Search Haskell Channel Logs

Sunday, March 5, 2017

#haskell channel featuring pacak, Axman6, lambdabot, buttons840, dmwit, Welkin, and 8 others.

turnage 2017-03-05 17:48:18
When a Reader monad is defined and the definition calls "ask", how does ask access the Reader's context?
Axman6 2017-03-05 17:50:48
that depends on the particular instance, but for the trivial Reader (r -> a), ask r = r (where ask has type r -> r)
Koterpillar 2017-03-05 17:50:48
turnage: the bind implementation for this monad passes the context to each action, and ask simply returns that passed parameter
Axman6 2017-03-05 17:51:28
for ReaderT, which is essentially r -> m a, it's just ask = ReaderT (\r -> return r)
turnage 2017-03-05 17:52:28
so ask, inside the definition of a reader, has access to the reader's context field?
turnage 2017-03-05 17:56:13
Oh, ask is defined for the Reader class as an action that yields the context? And ask implicitly received the reader as a parameter because it is called inside the Reader definition?
Welkin 2017-03-05 17:56:40
there is `ask` and `asks`
turnage 2017-03-05 17:57:38
I mean ask as in this sample: http://adit.io/posts/2013-06-10-three-useful-monads.html#the-reader-monad
ski 2017-03-05 17:58:54
Koterpillar : well, it's not the same, but it reminded me of that
turnage 2017-03-05 18:02:43
I think my question is basically, how is it that ask can yield different values when it doesn't appear to take any parameters?
turnage 2017-03-05 18:03:43
oh
turnage 2017-03-05 18:03:45
nvm I see
Koterpillar 2017-03-05 18:03:58
You'll see it if you expand the definitions of it and bind
turnage 2017-03-05 18:04:24
thanks for the help Koterpillar; just pulled up the source
buttons840 2017-03-05 18:06:25
can someone help me figure out this type error http://lpaste.net/353255
buttons840 2017-03-05 18:07:15
i thought the two versions of the code (with and without do notation) were equivalent?
geekosaur 2017-03-05 18:07:45
buttons840, suggest you take the do-based one and ask ghci its type
geekosaur 2017-03-05 18:08:09
just for starters
Koterpillar 2017-03-05 18:08:13
buttons840: $ ate your bind
buttons840 2017-03-05 18:08:37
actually, i messed up the error message, let me fix it
geekosaur 2017-03-05 18:08:52
however, the real problem is likely to be what Koterpillar said: ($) is not magical, it scopes as far as it can and this *includes* the (>>=) ... which changes the whole type
geekosaur 2017-03-05 18:09:28
wheras do notation stops it at the ends of the line (modulo indentation for continuation)
monochrom 2017-03-05 18:10:45
@quote monochrom point.free
lambdabot 2017-03-05 18:10:45
monochrom says: "point free" can be decomposed to: "point" refers to ".", "free" refers to using no "$". :)
lpaste_ 2017-03-05 18:16:15
Buttons840 pasted "Same error without $ " at http://lpaste.net/353257
buttons840 2017-03-05 18:16:29
geekosaur: I removed the $ and just used parens and have the same issue: http://lpaste.net/353257
geekosaur 2017-03-05 18:16:49
your parens are wrong
geekosaur 2017-03-05 18:17:11
the =<< goes *outside* the pure
Koterpillar 2017-03-05 18:17:20
you replaced pure . Card with pure applied to Card...
geekosaur 2017-03-05 18:17:43
the paramerter to pure, that is
buttons840 2017-03-05 18:20:32
i had `f = (code here, no type holes)` and got an error saying GHC found [Side] but expected IO Card (Card is a [Side] newtype) -- so I thought adding `pure . Card (same code as before)` here would turn it into the required type?
Koterpillar 2017-03-05 18:21:56
please go through the types of each expression again
roboguy` 2017-03-05 18:22:39
buttons840: note that that is parenthesized `pure . (Card (same code as before))`
hololeap 2017-03-05 18:27:32
is `sequence [Just 1, Just 2, Nothing]` essentially the same thing as to `Just 1 >>= (\_ -> Just 2) >>= (\_ -> Nothing)` ?
pacak 2017-03-05 18:28:11
> sequence [Just 1, Just 2, Nothing]
lambdabot 2017-03-05 18:28:14
Nothing
pacak 2017-03-05 18:28:27
> sequence [Just 1, Just 2]
lambdabot 2017-03-05 18:28:30
Just [1,2]
pacak 2017-03-05 18:28:57
hololeap: Not quite. It tries to collect results.
hololeap 2017-03-05 18:29:54
what is a method that essentially chains together monads like (Thing 1 >>= Thing >>= Thing >>= Thing) etc where you can specify the number in the chain or have it run infinitely
ski 2017-03-05 18:30:30
hololeap : use `sequence_' instead, and it's essentially the same
pacak 2017-03-05 18:30:37
:t forever
lambdabot 2017-03-05 18:30:39
Applicative f => f a -> f b
pacak 2017-03-05 18:30:40
:t sequence_
lambdabot 2017-03-05 18:30:43
(Foldable t, Monad m) => t (m a) -> m ()
ski 2017-03-05 18:30:51
@type replicateM_
pacak 2017-03-05 18:30:52
:t replicateM_
lambdabot 2017-03-05 18:30:54
Applicative m => Int -> m a -> m ()
lambdabot 2017-03-05 18:30:55
Applicative m => Int -> m a -> m ()
hololeap 2017-03-05 18:31:15
what if you want to keep the result at the end like a chain of state monads
ski 2017-03-05 18:31:31
"like a chain of state monads" ?
ski 2017-03-05 18:31:37
collect results in a list or what ?
ski 2017-03-05 18:31:49
or pass one intermediate result from one to the next ?
ski 2017-03-05 18:31:54
@type foldM
lambdabot 2017-03-05 18:31:56
(Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
dmwit 2017-03-05 18:32:07
:t foldr (>=>) return
lambdabot 2017-03-05 18:32:09
(Foldable t, Monad m) => t (c -> m c) -> c -> m c
dmwit 2017-03-05 18:32:36
:t replicateM
lambdabot 2017-03-05 18:32:38
Applicative m => Int -> m a -> m [a]
dmwit 2017-03-05 18:32:42
Really hard to tell what's wanted, to be honest.
pacak 2017-03-05 18:33:02
hololeap: Can you explain your task in a bit more details? An example maybe?
hololeap 2017-03-05 18:33:10
it's not a task
pacak 2017-03-05 18:33:22
Whatever you are trying to achieve
hololeap 2017-03-05 18:33:31
i'm just trying to get a better grasp of some details. should i start at the beginning?
pacak 2017-03-05 18:33:54
Go ahead
dmwit 2017-03-05 18:33:58
hololeap: http://stackoverflow.com/q/40983249/791604 possibly
buttons840 2017-03-05 18:43:15
do { a <- b; c $ d a } is that the same as (c $ d) =<< b ?
Koterpillar 2017-03-05 18:43:43
no
Koterpillar 2017-03-05 18:44:12
it's the same as (c . d) =<< b
hololeap 2017-03-05 18:44:30
essentially, i've been trying to learn how to code a simple interactive interface with state, thus the state monat transformer with IO. i found that you could essentially write an infinite loop with `execStateT (sequence $ repeat (StateT addLine)) 0`
hololeap 2017-03-05 18:44:55
where addLine is a function: Int -> IO (Int, Int)