[Haskell-cafe] IO (Either a Error) question
Brandon S. Allbery KF8NH
allbery at ece.cmu.edu
Sat May 8 01:23:07 EDT 2010
On May 8, 2010, at 01:16 , Ivan Lazar Miljenovic wrote:
> David Menendez <dave at zednenem.com> writes:
>> On Sat, May 8, 2010 at 12:15 AM, Ivan Lazar Miljenovic
>>> Well, any time you have a do-block like this you're using failable
>>> patterns:
>>>
>>> maybeAdd :: Maybe Int -> Maybe Int -> Maybe Int
>>> maybeAdd mx my = do x <- mx
>>> y <- my
>>> return $ x + y
>>
>> This is true in the sense that the translation for the do syntax in
>> the Haskell report uses fail.
>
> Huh? What about "maybeAdd (Just 2) Nothing" ?
Isn't that handled by the definition of (>>=) in Maybe, as opposed to
by invoking fail?
> instance Monad Maybe where
> -- ...
> Nothing >>= _ = Nothing
> (Just x) >>= f = f x
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100508/91a69807/PGP.bin
More information about the Haskell-Cafe
mailing list