Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Problem combining monads <sigh!> (John M. Dlugosz)
   2. Re:  Problem combining monads <sigh!> (Karol Samborski)
   3. Re:  Problem combining monads <sigh!> (Daniel Trstenjak)
   4. Re:  What is a "Monad Comprehension" ? (akash g)


----------------------------------------------------------------------

Message: 1
Date: Mon, 07 Apr 2014 04:06:44 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Problem combining monads <sigh!>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

I think I was looking at the page 
<http://learnyouahaskell.com/for-a-few-monads-more#state> a few paragraphs 
under the H3 
?The join function?.  It mentions ??we wanted to combine several of them into 
one, be it 
with <*> or >>=,??

Now I'm actually quite comfortable with Applicative syntax, and am preferring 
it in places 
where older texts and examples use monads or fmap etc.  (I look forward to an 
updated 
standard where Monads are derived from Applicatives.)

        (Aside:  is there a "history" function in GHCi to show the last few 
commands I typed?)

So, I tried a GHCi example starting with:

?>(+7) <$> [1,2,3]

?>[(+7), (*2)] <*> [1,2,3]

no sweat.  Now use >>= to do the same thing:

?>[(+7), (*2)] >>= [1,2,3]
-- nope
(I'll spare the error messages, which inspired some of the other things to try, 
some of 
which were just to explore the errors themselves)

?>[(+7), (*2)] <<= [1,2,3]
-- nope

?>[(+7), (*2)] =<< [1,2,3]
-- nope

?>[return (+7), return(*2)] =<< [1,2,3]
-- nope

(Use a single function as a simpler starting point)

?>(+7) =<< [1,2,3]
-- nope

?>return (+7) =<< [1,2,3]
-- nope

?>return (+7) >>= [1,2,3]
-- nope

?>return [1,2,3]
[1,2,3]
it :: [Integer]
-- just checking

?>[1,2,3] >>= (+7)
-- nope
?>[1,2,3] >>= do (+7)
-- nope.  Error messages are talking about
     No instance for (Num [b0]) arising from the literal `1'
so why is it looking inside the monad at one of the values and thinking that 
itself should 
be a list?

?>[1,2,3] >>= [(+7)]
-- nope

?>[1,2,3] >>=  (+7).return
-- nope, but got *two* errors out of that one

?>[1,2,3] >>=  liftM(+7)
-- nope

?>[1,2,3] >>=  liftM(+7) ::[Integer]
-- nope

?>[1,2,3] >>=  liftM(+7) ::Integer
-- nope

?>[1,2,3] >>=  liftM((+7) :: Integer -> Integer)
-- nope

?>[[1,2,3]] >>=  liftM((+7) :: Integer -> Integer)
[8,9,10]
it :: [Integer]

Ah, I'm getting somewhere.  But back to the question of why is the element of 
the list 
(nondeterminism monad) want its own element to be a list too?

?>return [1,2,3] >>=  liftM((+7) :: Integer -> Integer)
[8,9,10]
it :: [Integer]

Same thing.  But the list is already a monad, not a bare (scalar) value, so 
what's going on?

?>[1,2,3] >>= (+7)
-- nope

?>[1,2,3] >>= map(+7)
-- nope

?>[1,2,3] >>= liftM(+7)
-- nope  Am I starting to repeat myself?

?>[1,2,3] >>= liftM(+7) ::[Integer]
-- nope
Give up for the evening.


I wonder if that is a record for how many ways it can be incorrect?  I'm 
frustrated, 
especially since the Applicative syntax worked so easily.  But the referenced 
page and 
other texts casually say how they are interchangable.  Urrrgh!

Please enlighten?

?John



------------------------------

Message: 2
Date: Mon, 7 Apr 2014 11:13:59 +0200
From: Karol Samborski <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Problem combining monads <sigh!>
Message-ID:
        <cace2dtu0v4imcev9njumpaz0sh_oduqhhb_jyblafj-xosf...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi John!

2014-04-07 11:06 GMT+02:00 John M. Dlugosz <[email protected]>:
> I think I was looking at the page
> <http://learnyouahaskell.com/for-a-few-monads-more#state> a few paragraphs
> under the H3 ?The join function?.  It mentions ??we wanted to combine
> several of them into one, be it with <*> or >>=,??
>
> Now I'm actually quite comfortable with Applicative syntax, and am
> preferring it in places where older texts and examples use monads or fmap
> etc.  (I look forward to an updated standard where Monads are derived from
> Applicatives.)
>
>         (Aside:  is there a "history" function in GHCi to show the last few
> commands I typed?)
>
> So, I tried a GHCi example starting with:
>
> ?>(+7) <$> [1,2,3]
>
> ?>[(+7), (*2)] <*> [1,2,3]
>
> no sweat.  Now use >>= to do the same thing:
>
> ?>[(+7), (*2)] >>= [1,2,3]
> -- nope
> (I'll spare the error messages, which inspired some of the other things to
> try, some of which were just to explore the errors themselves)
>
> ?>[(+7), (*2)] <<= [1,2,3]
> -- nope
>
> ?>[(+7), (*2)] =<< [1,2,3]
> -- nope
>
> ?>[return (+7), return(*2)] =<< [1,2,3]
> -- nope
>
> (Use a single function as a simpler starting point)
>
> ?>(+7) =<< [1,2,3]
> -- nope
>
> ?>return (+7) =<< [1,2,3]
> -- nope
>
> ?>return (+7) >>= [1,2,3]
> -- nope
>
> ?>return [1,2,3]
> [1,2,3]
> it :: [Integer]
> -- just checking
>
> ?>[1,2,3] >>= (+7)
> -- nope
> ?>[1,2,3] >>= do (+7)
> -- nope.  Error messages are talking about
>     No instance for (Num [b0]) arising from the literal `1'
> so why is it looking inside the monad at one of the values and thinking that
> itself should be a list?
>
> ?>[1,2,3] >>= [(+7)]
> -- nope
>
> ?>[1,2,3] >>=  (+7).return
> -- nope, but got *two* errors out of that one

You're close. It should be:
[1,2,3] >>= return . (+7)

Best,
Karol


------------------------------

Message: 3
Date: Mon, 7 Apr 2014 11:20:22 +0200
From: Daniel Trstenjak <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Problem combining monads <sigh!>
Message-ID: <20140407092022.GA4540@machine>
Content-Type: text/plain; charset=utf-8


Hi John,

for some versions you almost did it ;).

> ?>return (+7) =<< [1,2,3]

   return . (+7) =<< [1,2,3]

> ?>[1,2,3] >>=  (+7).return

   [1,2,3] >>= return . (+7)


It's really helpful to look at the types:

   > :t return (+7)
   return (+7) :: (Monad m, Num a) => m (a -> a)
   > :t return . (+7)
   return . (+7) :: (Monad m, Num b) => b -> m b


Greetings,
Daniel


------------------------------

Message: 4
Date: Mon, 7 Apr 2014 15:08:46 +0530
From: akash g <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] What is a "Monad Comprehension" ?
Message-ID:
        <caliga_dfi8x7uxwskbanlodey5s-uh2cer1nvuecj+9oa35...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

At one point of time, comprehensions were available for all monads.  Then
it was removed, and has now been added back as a language extension (from
the cursory glance that I gave)

Basically, monad comprehensions are about using the samesyntactic sugar for
different monads (like the do notation)

Perhaps, this'll help (if you haven't seen this already)

https://ghc.haskell.org/trac/ghc/wiki/MonadComprehensions


On Mon, Apr 7, 2014 at 2:15 PM, Kim-Ee Yeoh <[email protected]> wrote:

>
> On Mon, Apr 7, 2014 at 3:33 PM, John M. Dlugosz 
> <[email protected]>wrote:
>
>> I know about List Comprehensions, but what is a general Monad
>> Comprehension?  List Comprehensions are the use of set-builder notation to
>> define a list, so I don't understand how that would generalize.
>
>
> Assuming that you have done a search and that you're still stumped, how
> can you make the question more specific?
>
> Do you think that quoting specific bits of what you have read might help
> us help you more?
>
> -- Kim-Ee
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140407/80a81c62/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 70, Issue 15
*****************************************

Reply via email to