Search Haskell Channel Logs

Sunday, March 5, 2017

#haskell channel featuring Rembane, xubunto, bollu, lambdabot, Tuplanolla, cocreature,

bollu 2017-03-05 04:46:31
isn't the non-commutativity of monad transformers a huge pain?
johnw 2017-03-05 04:46:50
bollu: you mean, in general?
bollu 2017-03-05 04:46:53
yes
johnw 2017-03-05 04:47:03
bollu: some are commutative (like ReaderT, with any monad)
johnw 2017-03-05 04:47:07
no, no particular pain
bollu 2017-03-05 04:47:19
I see
Rembane 2017-03-05 04:47:27
It's less than you might think. :)
bollu 2017-03-05 04:48:00
johnw: I've been using State + Error, which don't commute. I was wondering what would happen if I start adding things like Cont
bollu 2017-03-05 04:48:09
johnw: reasoning seems hard
johnw 2017-03-05 04:48:32
State + Error just has outright different semantics than Error + State. It's a feature that you can chose the meaning that is most appropriate.
bollu 2017-03-05 04:49:01
johnw: isn't that what "don't commute" means? :) semantics don't match if you flip them?
johnw 2017-03-05 04:49:03
ContT is a bit of a special beast; it introduces a couple restrictions that most other transformers don't have
bollu 2017-03-05 04:49:18
johnw: hm, I see. I have been told that ListT is also hard to "get right?
Tuplanolla 2017-03-05 04:49:20
How pleasant are noncommutative monads to use in mtl style?
bollu 2017-03-05 04:49:20
"*
johnw 2017-03-05 04:49:21
bollu: well, in that case, commutativity would mean eliminating information
bollu 2017-03-05 04:49:26
johnw: yeah
Tuplanolla 2017-03-05 04:49:38
I've never tried that.
johnw 2017-03-05 04:49:40
ListT isn't all that hard to get right, it's just that the naive version isn't right at all
bollu 2017-03-05 04:49:42
johnw: is there some way to systematically derive like, the, "commutator" of two monads?
johnw 2017-03-05 04:50:09
bollu: no
bollu 2017-03-05 04:50:12
johnw: like, in the group theory sense of the word, I can abelianise a group by finding the commutator subgroup, right?
bollu 2017-03-05 04:50:14
oh, that's sad
cocreature 2017-03-05 04:51:08
Tuplanolla: it's a bit weird since your semantics now change depending on how you instantiate the type class constraints
bollu 2017-03-05 04:51:22
if I have a StateT s Either e a, and I have a "Left e", how do I raise it into the StateT? "lift" doesn't seem to be doing the trick
johnw 2017-03-05 04:51:56
make a combinator called "left"
bollu 2017-03-05 04:52:12
do I get it by default with mtl?
Tuplanolla 2017-03-05 04:52:13
I can imagine, cocreature. It feels like pushing an unnecessary choice to the user.
johnw 2017-03-05 04:52:29
left e = StateT $ \_ -> Left e
johnw 2017-03-05 04:52:39
bollu: I don't think so
johnw 2017-03-05 04:52:48
mtl doesn't really give you combinators specific to certain combinations
bollu 2017-03-05 04:52:50
hm, OK, thanks :)
cocreature 2017-03-05 04:53:33
wait why does lift not work?
johnw 2017-03-05 04:53:40
yeah, I'm wondering that now too
cocreature 2017-03-05 04:53:45
:t lift :: Either e a -> StateT s (Either e) a
lambdabot 2017-03-05 04:53:48
Either e a -> StateT s (Either e) a
cocreature 2017-03-05 04:53:53
works just fine
Tuplanolla 2017-03-05 04:54:29
One other thing that bugs me is using `bracket` and friends with mtl style.
xubunto 2017-03-05 04:54:36
how would I get a file with <$> and <*> to compile?
Tuplanolla 2017-03-05 04:54:41
You have to choose an order for that.
cocreature 2017-03-05 04:55:05
xubunto: I don't understand that question. do you have some specific error?
xubunto 2017-03-05 04:55:17
cocreature: not in scope
cocreature 2017-03-05 04:55:26
xubunto: import Control.Applicative
cocreature 2017-03-05 04:55:42
or use a newer ghc, 8.0 should have them in the Prelude iirc
Tuplanolla 2017-03-05 04:55:52
Even 7.10 does, cocreature.
bollu 2017-03-05 04:56:02
johnw: well fuck, turns out I wanted ExceptT e State s a
johnw 2017-03-05 04:56:08
bollu: haha
cocreature 2017-03-05 04:56:08
Tuplanolla: ah nice, I wasn't sure when that was introduced
bollu 2017-03-05 04:56:09
johnw: I misinterpreted the way they compose :P
johnw 2017-03-05 04:56:15
bollu: don't worry, that happens to all of us
Tuplanolla 2017-03-05 04:56:22
I'm still stuck in 7-land here.
johnw 2017-03-05 04:56:27
the composition is somewhat the inverse of the execution
bollu 2017-03-05 04:56:31
yeah
bollu 2017-03-05 04:56:33
just noticed xD
johnw 2017-03-05 04:56:37
ExceptT on the "outside" means that it's the most immediate effect
cocreature 2017-03-05 04:56:41
bollu: in that case the function you're looking for is called "hoistEither"
bollu 2017-03-05 04:57:00
cocreature: I see, thank you
cocreature 2017-03-05 04:57:06
it's in the errors package iirc
bollu 2017-03-05 04:57:30
cocreature: interestingly enough, this is the first time I have decided to use lens in a full blown fashing
bollu 2017-03-05 04:57:43
cocreature: it's fun, seeing how a "throw everything together" sort of codebase works out
bollu 2017-03-05 04:57:50
everything = mtl + lens + other stuff
johnw 2017-03-05 04:57:51
bollu: are you in the SF bay area by any chance?
bollu 2017-03-05 04:58:02
johnw: naw, India :) undergrad
xubunto 2017-03-05 04:58:05
cocreature: tyvm
johnw 2017-03-05 04:58:07
I'm going to be giving a talk on "pratical lensing" at BayHac
bollu 2017-03-05 04:58:07
johnw: why?
bollu 2017-03-05 04:58:12
ooh, that is quite cool
johnw 2017-03-05 04:58:24
like, a totally non-theory, "this is how we use lenses to get stuff done at my job" type of presentation
johnw 2017-03-05 04:58:37
since we use lenses in everything we do
cocreature 2017-03-05 04:58:49
bollu: oh btw you mentioned that you're coming to zurich right? will you be at zurihac?
bollu 2017-03-05 04:58:52
johnw: I have actually been trying to understand the theory. I dislike treating haskell libraries as libraries, they usually have some super pretty theory
Tuplanolla 2017-03-05 04:58:56
Does it involve `RankNTypes`, johnw?
bollu 2017-03-05 04:59:02
cocreature: I am considering it. I will have to ask my professor!
bollu 2017-03-05 04:59:15
cocreature: I'll be at ETH, so I'm not sure how far away it is
johnw 2017-03-05 04:59:16
Tuplanolla: at most I'm going to mention ALens as a way to avoid that requirement
bollu 2017-03-05 04:59:33
johnw: will there be a video recording? I would love to watch it
bollu 2017-03-05 04:59:36
johnw: of the talk that is
johnw 2017-03-05 04:59:42
Tuplanolla: however, my upcoming talk on in the south bay on quantification will cover RankNTypes in detail
johnw 2017-03-05 04:59:46
bollu: I think so
Tuplanolla 2017-03-05 05:00:20
To me that extension is a sign that I'm lensing too hard and need to stop, johnw.
johnw 2017-03-05 05:00:26
haha
bollu 2017-03-05 05:00:42
cocreature: I am registering, what the hell, might as well :)
bollu 2017-03-05 05:00:47
cocreature: will you be there?
johnw 2017-03-05 05:00:49
I don't often treat lenses as values in my work use of lens
cocreature 2017-03-05 05:00:52
bollu: looking forward to meeting you there!
johnw 2017-03-05 05:00:55
sometimes, but not often
bollu 2017-03-05 05:01:02
cocreature: you too :D
ertes 2017-03-05 05:03:12
Tuplanolla: uhh… why?
ertes 2017-03-05 05:03:41
RankNTypes is mostly a convenience feature with lenses
Tuplanolla 2017-03-05 05:04:10
It means I'm spending more times making functions from lenses to lenses than doing useful things, ertes.
ertes 2017-03-05 05:04:32
ah =)
ertes 2017-03-05 05:04:50
you don't need RankNTypes for that though
johnw 2017-03-05 05:05:27
wouldn't he if the function were Lens' s a -> Lens' t b?
ertes 2017-03-05 05:05:35
if you change the type signature of your function, it may become more efficient, and you may get rid of that indicator, so you can keep lensing happily =)
ertes 2017-03-05 05:06:21
johnw: i think most of the time you can work with LensLike and not use RankNTypes
ertes 2017-03-05 05:06:57
at least for the use cases that come to my mind
cocreature 2017-03-05 05:07:11
johnw: I don't think you can avoid enabling RankNTypes by the use of a type synonym or can you?
johnw 2017-03-05 05:07:46
cocreature: well, you could use LensLike, or unfold the type aliases and share the constraint
Tuplanolla 2017-03-05 05:08:46
What if you want to use an argument lens over more than one functor?
johnw 2017-03-05 05:08:47
i.e.,: foo :: forall f. Functor f => ((a -> f a) -> s -> f s) -> (b -> f b) -> t -> f t
johnw 2017-03-05 05:09:15
in fact, if you get used to writing lenses as plain functions, you can create them without even importing lens
Tuplanolla 2017-03-05 05:10:24
The lens equivalent of `\ p fs xs -> (p fs) (p xs)`.