[Haskell-cafe] IO (Either a Error) question

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sat May 8 01:16:54 EDT 2010


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.
>
> do { p <- e; stmts } =
>     let ok p = do { stmts }
>         ok _ = fail "..."
>     in e >>= ok
>
> However, it's also true that the fails introduced by the translation
> of maybeAdd will never be invoked, since the two patterns are
> irrefutable.

Huh?  What about "maybeAdd (Just 2) Nothing" ?

> That is, maybeAdd would work exactly the same if the do syntax
> translation were changed to read:
>
> do { p <- e; stmts } = e >>= \p -> do { stmts }

Wait, are you using "irrefutable" as "it will still work if we make do
blocks work the way I want"?

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list