Taneb 2017-02-03 02:45:53
reactormonk, is fooL a lens there
reactormonk 2017-02-03 02:46:04
Taneb, Foo (Maybe Bar)
ph88 2017-02-03 02:46:07
hey guys, i know that ghc can get stuck when you do something like instance Class a => Class b instance Class b => Class a anyone know how this is called and if there is documentation about this ?
Taneb 2017-02-03 02:46:22
reactormonk, what is the type of "fooL"
mroman 2017-02-03 02:47:20
How can I teach ghc that I'm not in a list monad :(
reactormonk 2017-02-03 02:47:25
Taneb, the whole thing is (authorityL .> _Just .> authorityPortL .> _Just .> portNumberL) via https://hackage.haskell.org/package/uri-bytestring-0.2.2.1/docs/URI-ByteString.html - authorityL :: Lens' (URIRef a) (Maybe Authority) Source
reactormonk 2017-02-03 02:47:46
authorityPortL :: Lens' Authority (Maybe Port) - portNumberL :: Lens' Port Int
srhb 2017-02-03 02:48:05
mroman: By not using the wrong type.
mroman 2017-02-03 02:48:09
if i have a function foo :: Mondad m -> Foo m -> m ()
Taneb 2017-02-03 02:48:16
reactormonk, that should in fact be a Traversal
Taneb 2017-02-03 02:48:43
Because you can use a Prism to construct things, and you can't turn authorityPortL around to get a constructor like you can with _Just
reactormonk 2017-02-03 02:48:44
Taneb, ... which I can't really call view on.
reactormonk 2017-02-03 02:49:16
Yeah, I'm not too solid on the things above the basic Lens.
Gurkenglas 2017-02-03 02:49:29
:t [(undefined :: Prism' String Int) . (undefined :: Prism' Int Char), undefined :: Prism' String Char] -- Composing two prisms will give you a prism, reactormonk
lambdabot 2017-02-03 02:49:31
(Choice p, Applicative f) => [p Char (f Char) -> p String (f String)]
Taneb 2017-02-03 02:49:33
> Just (2, Just 3) ^? _Just . _2 . _Just
srhb 2017-02-03 02:49:35
mroman: What's your actual problem?
lambdabot 2017-02-03 02:49:36
Just 3
geekosaur 2017-02-03 02:50:28
mroman, not enough information. but my guess is you tried to do something like produce a String, without using pure/return so it inferred the list monad because String = [Char]. Show code.
geekosaur 2017-02-03 02:50:29
@paste
lambdabot 2017-02-03 02:50:30
Haskell pastebin: http://lpaste.net/
Gurkenglas 2017-02-03 02:50:33
reactormonk, can you construct an Authority from a Maybe Port? If yes, you can write a prism there, and compose that with the _Just parts
mroman 2017-02-03 02:50:38
I have xs <- f; mapM_ g xs
reactormonk 2017-02-03 02:50:44
Gurkenglas, nope, I can't.
mroman 2017-02-03 02:50:46
and it keeps telling me xs is a instead of [a]
mroman 2017-02-03 02:50:57
but the return type of f is [a]
reactormonk 2017-02-03 02:51:12
Gurkenglas, know some good documentation about advanced lensing? I feel like I'm in for some RTFM
geekosaur 2017-02-03 02:51:32
mroman, you probably wanted let, then
mroman 2017-02-03 02:51:52
no it's m [a]
geekosaur 2017-02-03 02:51:55
if f :: [a] then using <- does in fact mean [] is the monad
mroman 2017-02-03 02:52:06
or not
mroman 2017-02-03 02:52:07
hmb
mroman 2017-02-03 02:52:09
Right.
mroman 2017-02-03 02:52:14
Maybe it assumes that
geekosaur 2017-02-03 02:52:23
er
reactormonk 2017-02-03 02:52:43
Gurkenglas, I think I'm looking for something akin to an Optional in the haskell lens lib - https://julien-truffaut.github.io/Monocle/optics.html
Gurkenglas 2017-02-03 02:52:53
Hmm the literal documentation https://hackage.haskell.org/package/lens-4.15.1/docs/Control-Lens-Prism.html talks a little about what a Prism is, but it doesn't explain the composition rules
mroman 2017-02-03 02:53:13
Thx.
mroman 2017-02-03 02:53:16
fixed it :)
Gurkenglas 2017-02-03 02:53:29
Maybe he thought that's not his department because "its just function composition and anybody knows how that works with typeclasses"
Gurkenglas 2017-02-03 02:54:40
reactormonk, an optional is a traversal that has up to one target? How do you use that there's only up to one target?
Tuplanolla 2017-02-03 02:54:47
The lack of a node between Prism and Setter in that image is unsettling, reactormonk.
reactormonk 2017-02-03 02:55:33
Tuplanolla, what are you missing there?
Tuplanolla 2017-02-03 02:55:48
I don't know, but something ought to be there for symmetry.
reactormonk 2017-02-03 02:56:07
Gurkenglas, hmm, I'd say it's a specialization of Traversable to Maybe
reactormonk 2017-02-03 02:56:29
That doesn't need a Monoid.
Gurkenglas 2017-02-03 02:56:40
Tuplanolla, but https://hackage.haskell.org/package/lens also has nothing in between there
Gurkenglas 2017-02-03 02:57:00
reactormonk, but that would allow you to replace Nothing with Just or vice versa, which breaks the traversal laws
reactormonk 2017-02-03 02:58:01
Gurkenglas, pretty sure I don't follow
mroman 2017-02-03 02:58:41
geekosaur: yeah it was a missing m there.
Gurkenglas 2017-02-03 02:58:53
If you treat the Optional as a Traversal, you can only update at each place (and read something out meanwhile), i.e. you "traverse". This does not modify the number of elements traversed over
reactormonk 2017-02-03 03:00:26
There's only one element anyway.
reactormonk 2017-02-03 03:00:46
... and no, the set on there is a regular set. It just either happens or doesn't.
Gurkenglas 2017-02-03 03:00:54
Up to one. Even Traversals traversing over up to one element maybe not remove it or add one if there isnt one
Gurkenglas 2017-02-03 03:01:15
-maybe+may
reactormonk 2017-02-03 03:02:12
Where do you conclude that the Optional modifies the number of elements?
Gurkenglas 2017-02-03 03:02:53
If you implement it as Lens' s (Maybe a), you can set Nothing or Just-values in there at will
reactormonk 2017-02-03 03:04:40
So what should it be?
reactormonk 2017-02-03 03:05:34
Or a bit more practical, how do I construct my lens that I pass to view in such a way that I get a Maybe Int out?
Gurkenglas 2017-02-03 03:06:00
(Well, if you want to be able to set Nothing or Just-valus, you can still do it as Lens' s (Maybe a), but it wouldn't be Optional? :P)
Gurkenglas 2017-02-03 03:06:16
reactormonk, you can just preview the traversal you already have gotten out of the composition
reactormonk 2017-02-03 03:06:44
Gurkenglas, nice, thanks.
Gurkenglas 2017-02-03 03:06:53
:t preview :: Traversal' String Int -> String -> Maybe Int
lambdabot 2017-02-03 03:06:55
Traversal' String Int -> String -> Maybe Int
reactormonk 2017-02-03 03:07:16
darn, should have been looking for that.
reactormonk 2017-02-03 03:07:26
Thanks, problem solved.
reactormonk 2017-02-03 03:07:36
Now is there a way to maybe make an update to a record?
reactormonk 2017-02-03 03:07:47
... or should I construct a lens for said record first?
Gurkenglas 2017-02-03 03:08:06
Well, might an update a value where there wasnt one before?
Gurkenglas 2017-02-03 03:08:19
*insert
Gurkenglas 2017-02-03 03:09:04
:t over :: Traversal' String Int -> (Int -> Int) -> (String -> String)
lambdabot 2017-02-03 03:09:05
Traversal' String Int -> (Int -> Int) -> String -> String
reactormonk 2017-02-03 03:09:59
defaultRequest via https://www.stackage.org/haddock/lts-7.18/http-conduit-2.1.11/Network-HTTP-Conduit.html#t:Request
Gurkenglas 2017-02-03 03:10:01
:t set :: Traversal' String Int -> Int -> (String -> String) -- replaces each existing int with the one given
lambdabot 2017-02-03 03:10:04
Traversal' String Int -> Int -> String -> String
reactormonk 2017-02-03 03:10:09
No lenses provided.
Gurkenglas 2017-02-03 03:10:45
https://hackage.haskell.org/package/http-client-lens-0.1.0/docs/Network-HTTP-Client-Lens.html ?
Gurkenglas 2017-02-03 03:12:11
And now consider how many more hours you're working because you're not asking the right questions :D
roxxik 2017-02-03 03:13:33
if you just experimenetd with some code for a few days and then some random comment on irc points you to an 8 years old gist from ekmett, solving your problem
reactormonk 2017-02-03 03:13:39
Gurkenglas, I'm asking here so I know which questions to ask. And yes, I've done that before with uri and bytestring
reactormonk 2017-02-03 03:14:07
Gurkenglas, is there a nice way to wire the Maybe port from the preview into the setter for Request?
Gurkenglas 2017-02-03 03:14:38
Umm, more exact names or types pls
reactormonk 2017-02-03 03:15:19
Take the above lens, preview it, https://hackage.haskell.org/package/http-client-lens-0.1.0/docs/Network-HTTP-Client-Lens.html port
Gurkenglas 2017-02-03 03:15:59
I keep wanting to be an established question format where you just say into irc ":manual-exf Lens' s a -> s -> a" and people answer "view"
reactormonk 2017-02-03 03:16:09
So I'd have Lens' URIRef a b -> Lens' Request b -> Request -> Request
reactormonk 2017-02-03 03:16:28
or rather, that's what I'd like.
mroman 2017-02-03 03:16:35
https://wiki.haskell.org/Type_witness <- does that example code actually cast anything?
Gurkenglas 2017-02-03 03:16:35
Lens' URIRef a b <- too many type parameters
reactormonk 2017-02-03 03:16:51
So And Lens' (URIRef a) Maybe b -> Lens' Request b -> Request -> Request
reactormonk 2017-02-03 03:17:01
So Lens' (URIRef a) (Maybe b) -> Lens' Request b -> Request -> Request
mroman 2017-02-03 03:17:15
I don't really follow what it's supposed to do :(
merijn 2017-02-03 03:17:42
ok, so any persistent users here? I have a bunch of ugly repetitive code that I'm unsure how to clean up :\
Gurkenglas 2017-02-03 03:17:55
reactormonk, cannot instantiate. Did you mean to provide more parameters to the function im supposed to write?
merijn 2017-02-03 03:17:59
But I'm not really sure how
reactormonk 2017-02-03 03:19:02
Gurkenglas, I have lenses to get the information out of URIRef, and lenses how to put them into Request. How do I combine them? And how do I deal with Maybe in between?
Gurkenglas 2017-02-03 03:19:04
reactormonk, "Lens' Request b -> Request -> Request" reduces to "b -> b" - is there a parameter of that form?
Gurkenglas 2017-02-03 03:20:22
:t maybe id const :: Maybe b -> b -> b -- is this the intended behavior?
lambdabot 2017-02-03 03:20:24
Maybe b -> b -> b
geekosaur 2017-02-03 03:20:29
mroman, it's not a cast like in C
geekosaur 2017-02-03 03:20:38
because you can;t do that in Haskell
reactormonk 2017-02-03 03:20:53
Gurkenglas, in case of a Maybe, yes, I think so. Don't modify in that case.
reactormonk 2017-02-03 03:21:12
... in case of Nothing, to be exact.
geekosaur 2017-02-03 03:21:35
what it does is let you extract a value that could be one of several types, by providing a witness for the stored value's type and a witness for the type you want; it will only produce a Just if they match
Gurkenglas 2017-02-03 03:21:36
reactormonk, where do I get the URIRef to call the first lens on? Is there some Lens' Request (URIRef a)?
reactormonk 2017-02-03 03:21:41
But I don't see the reduction right now, so maybe I'm talking on another track.
reactormonk 2017-02-03 03:21:48
Gurkenglas, fuck, forgot about that.
Gurkenglas 2017-02-03 03:22:29
Okay so more generally we're at "Lens' s (Maybe a) -> Lens' s a -> s -> s"?
reactormonk 2017-02-03 03:22:40
Yeah.
reactormonk 2017-02-03 03:22:57
Ehh, wait. No.
noan 2017-02-03 03:23:08
where would be the best place to learn my way through haskell syntax? lyahfgg?
reactormonk 2017-02-03 03:23:20
Lens' s (Maybe a) -> Lens' r a -> s -> r -> r
roxxik 2017-02-03 03:24:32
reactorMonk: `Getter s (Maybe a) -> Setter r a -> s -> r -> r` ?
reactormonk 2017-02-03 03:24:44
roxxik, yeah.
roxxik 2017-02-03 03:24:48
having a Lens where you don't need one might restrict you later
roxxik 2017-02-03 03:24:59
and it shows better what you want to do
geekosaur 2017-02-03 03:25:00
mroman, so if you pattern match a GADT constructor, you bring its type into scope. this means pattern matching IntWitness "proves" that pa is a p Int (since otherwise the pattern match fails to typecheck and falls through)
Gurkenglas 2017-02-03 03:25:00
\sa ra s -> ra %~ views sa (maybe const id) s
roxxik 2017-02-03 03:25:34
:t views
lambdabot 2017-02-03 03:25:35
MonadReader s m => LensLike' (Const r) s a -> (a -> r) -> m r
reactormonk 2017-02-03 03:26:14
roxxik, might be nice to have Lens' s (Maybe a) -> Lens' r a -> Lens' s r and then just stack them all up (not sure how yet)
reactormonk 2017-02-03 03:26:37
Also because it's not an Iso from what I understand, just a partial transferal of informations.
roxxik 2017-02-03 03:26:53
reactorMonk: Lens' s r is not very useful, i think
Gurkenglas 2017-02-03 03:26:54
Or with less advanced lens words and more pointfree, \sa ra -> over ra . maybe const id . view sa
mroman 2017-02-03 03:27:15
geekosaur: so the dynamicCast function just proves that both are p Int?
roxxik 2017-02-03 03:27:23
:t \sa ra -> over ra . maybe const id . view sa
lambdabot 2017-02-03 03:27:25
Getting (Maybe (a -> b -> a)) s1 (Maybe (a -> b -> a)) -> ASetter s t a (b -> a) -> s1 -> s -> t
reactormonk 2017-02-03 03:27:53
:t \sa ra s -> ra %~ views sa (maybe const id) s
lambdabot 2017-02-03 03:27:55
LensLike' (Const (a -> b -> a)) s1 (Maybe (a -> b -> a)) -> ASetter s t a (b -> a) -> s1 -> s -> t
geekosaur 2017-02-03 03:27:57
yes, and refuses you the value otherwise. this is the best you can do in Haskell because you must have a definite type
roxxik 2017-02-03 03:28:07
:t \sa ra -> over ra . maybe const id . view sa :: Getter s a -> Setter' r a -> s -> r -> r
lambdabot 2017-02-03 03:28:09
error:
lambdabot 2017-02-03 03:28:09
• Couldn't match expected type 'ASetter
lambdabot 2017-02-03 03:28:09
((a1 -> f0 a1) -> r1 -> f0 r1) (s1 -> r1 -> r1) a0 (b0 -> a0)'
roxxik 2017-02-03 03:28:15
:t \sa ra -> over ra . maybe const id . view sa :: Getter s (Maybe a) -> Setter' r a -> s -> r -> r
lambdabot 2017-02-03 03:28:17
error:
lambdabot 2017-02-03 03:28:17
• Couldn't match expected type 'ASetter
lambdabot 2017-02-03 03:28:17
((a1 -> f0 a1) -> r1 -> f0 r1) (s1 -> r1 -> r1) a0 (b0 -> a0)'
mroman 2017-02-03 03:28:21
so it doesn't actually do type casting?
Gurkenglas 2017-02-03 03:28:27
Experiment in queries.
roxxik 2017-02-03 03:28:38
jusst opened one
geekosaur 2017-02-03 03:28:56
mroman, as I said earlier, it does not do C style type casting, because that is not possible in Haskell
mroman 2017-02-03 03:29:17
You can do dynamic type casting by using type classes.
geekosaur 2017-02-03 03:29:20
(barring unsafeCoerce which will happily break your program if (ab)used)
geekosaur 2017-02-03 03:29:30
only to a point
reactormonk 2017-02-03 03:29:57
:t :t (\sa ra -> over ra . maybe const id . view sa) (preview (authorityL .> _Just .> authorityPortL .> _Just .> portNumberL))
lambdabot 2017-02-03 03:29:59
error: parse error on input ':'
reactormonk 2017-02-03 03:30:01
:t (\sa ra -> over ra . maybe const id . view sa) (preview (authorityL .> _Just .> authorityPortL .> _Just .> portNumberL))
lambdabot 2017-02-03 03:30:06
error:
lambdabot 2017-02-03 03:30:06
• Couldn't match type 'Maybe a0'
lambdabot 2017-02-03 03:30:06
with 's1 -> Const (Maybe (a -> b -> a)) s1'
mroman 2017-02-03 03:31:09
http://codepad.org/0nUm18yb <- something like that.
mroman 2017-02-03 03:31:31
but then this has nothing to do with the casting as in that type witnesses article
Gurkenglas 2017-02-03 03:31:44
:t \sa ra -> over ra . maybe const id . view sa :: Lens' String (Maybe Int) -> Lens' Char Int -> String -> Char -> Char -- reactormonk
lambdabot 2017-02-03 03:31:46
(Functor f1, Functor f) => Getting (Maybe (a -> b -> a)) ((Maybe Int -> f1 (Maybe Int)) -> String -> f1 String) (Maybe (a -> b -> a)) -> ASetter ((Int -> f Int) -> Char -> f Char) (String -> Char ->
lambdabot 2017-02-03 03:31:46
Char) a (b -> a) -> Lens' String (Maybe Int) -> Lens' Char Int -> String -> Char -> Char
mniip 2017-02-03 03:32:17
that looks
mniip 2017-02-03 03:32:24
fairly horrifying
roxxik 2017-02-03 03:32:36
:t maybe const id -- this is weird
lambdabot 2017-02-03 03:32:38
Maybe (a -> b -> a) -> a -> b -> a
roxxik 2017-02-03 03:32:44
:t maybe id const -- this is better
lambdabot 2017-02-03 03:32:45
Maybe b -> b -> b
mroman 2017-02-03 03:32:52
(gotta catch train. be back later)
Gurkenglas 2017-02-03 03:33:08
argh you're right
Gurkenglas 2017-02-03 03:33:17
(gotta catch brain. be back later)
roxxik 2017-02-03 03:33:59
:t \sa ra -> over ra . maybe id const . view sa -- this makes sense now
lambdabot 2017-02-03 03:34:01
Getting (Maybe b) s1 (Maybe b) -> ASetter s t b b -> s1 -> s -> t
int-index 2017-02-03 03:35:35
Ok, so I wrote an UTLC interpreter... (with de Bruijn indices). What do I put in a test suite? It seems to handle Church numerals fine, but I want to test corner cases
reactormonk 2017-02-03 03:35:44
:t let lens = undefined :: Applicative f => (Int -> f Int) -> URIRef a -> f (URIRef a); (\sa ra -> over ra . maybe id const . view sa) lens
lambdabot 2017-02-03 03:35:46
error:
lambdabot 2017-02-03 03:35:46
parse error (possibly incorrect indentation or mismatched brackets)
roxxik 2017-02-03 03:36:26
try `in` instead of `;`
mniip 2017-02-03 03:36:35
int-index, implement division
reactormonk 2017-02-03 03:36:38
:t lens = undefined :: Applicative f => (Int -> f Int) -> URIRef a -> f (URIRef a) in (\sa ra -> over ra . maybe id const . view sa) lens
lambdabot 2017-02-03 03:36:40
error:
lambdabot 2017-02-03 03:36:40
parse error on input '='
mniip 2017-02-03 03:36:40
that ought to be a good enough test
lambdabot 2017-02-03 03:36:40
Perhaps you need a 'let' in a 'do' block?
roxxik 2017-02-03 03:36:54
reactormonk: you still need let
reactormonk 2017-02-03 03:36:56
:t let lens = undefined :: Applicative f => (Int -> f Int) -> URIRef a -> f (URIRef a) in (\sa ra -> over ra . maybe id const . view sa) lens
lambdabot 2017-02-03 03:36:58
error:
lambdabot 2017-02-03 03:36:58
Not in scope: type constructor or class 'URIRef'
lambdabot 2017-02-03 03:36:58
error:
reactormonk 2017-02-03 03:37:05
Got me a cood alternative?
reactormonk 2017-02-03 03:37:17
:t let lens = undefined :: Applicative f => (Int -> f Int) -> [a] -> f ([a]) in (\sa ra -> over ra . maybe id const . view sa) lens
lambdabot 2017-02-03 03:37:19
error:
lambdabot 2017-02-03 03:37:19
• Couldn't match type 'Int' with 'Maybe b'
lambdabot 2017-02-03 03:37:19
Expected type: [a] -> Maybe b
reactormonk 2017-02-03 03:37:25
^ there we go.
merijn 2017-02-03 03:41:39
I have like 10 or 12 entities + relationships like this http://lpaste.net/1552983955743965184 in persistent and some code that generally needs to be able to 1) construct an entity, 2) extract it's content and 3) construct the relation. Which results in the bottom boilerplate code. Any suggestions on how I can make this less noisy/boilerplatey?
merijn 2017-02-03 03:42:19
It seems like things should be possible in a simpler way...