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. Re: Parser composition (David Virebayre)
----------------------------------------------------------------------
Message: 1
Date: Fri, 3 Dec 2010 10:33:00 +0100
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Parser composition
To: Angelos Bimpoudis <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
2010/12/2 Angelos Bimpoudis <[email protected]>
So I would like to ask about whether or not this:
>
> P1>>=?u1 ->
>
> P2>>=?u2 ->
>
> P3>>=?u3 ->
>
> P4>>=?u4 ->
>
> return (f u1 u2 u3 u4)
>
>
>
> can be rewritten to:
>
> P1>>=(?u1 -> P2>>=(?u2 -> P3>>=(?u3 -> P4>>=(?u4 -> return (f u1 u2 u3
> u4)))))
>
Yes, but the extra parenthesis you added are not necessary.
I am trying to understand what is the f in p>>=f in each one of above
> sequencing applications?
>
Amy probably explained it better that I will, and I'm not sure I understood
the question but :
In
P1>>=(?u1 -> P2>>=(?u2 -> P3>>=(?u3 -> P4>>=(?u4 -> return (f u1 u2 u3
u4)))))
--
-------------------------------------------------------------------------
p f
In
P2>>=(?u2 -> P3>>=(?u3 -> P4>>=(?u4 -> return (f u1 u2 u3 u4)))))
-- ------------------------------------------------------------
p f
Etc.
>
> So >>= gets you in this structure (is this the monad?), and return is the
> gate out of it?
>
(Someone please correct me if I'm not using the right words;)
>>= binds two monadic computation together, getting a value out of the first
one, and feeding that value to the second one.
return is more a gate into it, as it takes a value and 'returns' its monadic
equivalent, for example :
-- In the list monad
Prelude> return 1 :: [Int]
[1]
As you see, return didn't "gate out" anything of the list monad, on the
contrary it took a value into the list monad. Same with the Maybe monad :
Prelude> return 1 :: Maybe Int
Just 1
And it works that way for every monad, returns take a value, and return its
monadic version.
Best regards
David.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101203/f4580c93/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 30, Issue 4
****************************************