[Haskell-cafe] Missing a "Deriving"?
Daniel Fischer
daniel.is.fischer at web.de
Mon Jun 1 13:51:35 EDT 2009
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
>
More information about the Haskell-Cafe
mailing list