[Haskell-cafe] Missing a "Deriving"?

michael rice nowgate at yahoo.com
Mon Jun 1 17:30:00 EDT 2009


Got it.

Thanks!

Michael

--- On Mon, 6/1/09, Daniel Fischer <daniel.is.fischer at web.de> wrote:

From: Daniel Fischer <daniel.is.fischer at web.de>
Subject: Re: [Haskell-cafe] Missing a "Deriving"?
To: haskell-cafe at haskell.org
Date: Monday, June 1, 2009, 1:51 PM

Am Montag 01 Juni 2009 19:02:36 schrieb michael rice:

> All good so far, but then tried to convert Failable from Computation to
> Monad
>
>
> instance Monad Failable where
>     return = Success
>     fail = Fail
>     >>= (Success x) f = f x
>     >>= (Fail s) _ = Fail s
>     mplus (Fail _) y = y
>     mplus x _ = x
>  
>
> and got the following error.
>
>
> Prelude> :l graph5
> [1 of 1] Compiling Main             ( graph5.hs, interpreted )
>
> graph5.hs:34:4: parse error on input `>>='
> Failed, modules loaded: none.
> Prelude>
>

When you use an operator in prefix position, you must enclose it in parentheses, like you 
must enclose a function in backticks if you use it infix.

So the definition of (>>=) should read


    (>>=) (Success x) f = f x
    (>>=) (Fail s) _ = Fail s

or, defining it in infix position,
    (Success x) >>= f = f x
    (Fail s) >>= _ = Fail s

>
> Complete code follows.
>
> Michael
>

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090601/5da24d47/attachment.html


More information about the Haskell-Cafe mailing list