[Haskell-cafe] YAHT: Ex 9.2

Magnus Therning magnus at therning.org
Sun Oct 29 13:43:59 EST 2006

I've been slowly making my way through Yet Another Haskell Tutorial.  As
a first introduction to the language it doesn't seem bad at all.
However, I'm wondering about the proposed solution to exercise 9.2.  The
text itself suggests using "instance Monad (Either String) where", so I
arrived at

  instance Monad (Either String) where
      return a = Right a
      fail a = Left a
      Right a >>= f = f a
      Left a >>= _ = Left a

However, when loading it in ghci 6.6 I get the following error message:

     Illegal instance declaration for `Monad (Either String)'
        (The instance type must be of form (T a b c)
         where T is not a synonym, and a,b,c are distinct type variables)
    In the instance declaration for `Monad (Either String)'

The solution, according to the author is

  instance Monad (Either String) where
      return x = Right x
      fail s = Left s
      Right x >>= f = f x
      Left s >>= _ = Left s

Which results in exactly the same error message.

I'm suspecting this is a result of my limited grasp of Haskell's syntax
(an area where YAHT is sorely lacking).  Any tips/pointers appreciated.


Magnus Therning                             (OpenPGP: 0xAB4DFBA4)
magnus at therning.org             Jabber: magnus.therning at gmail.com

Software is not manufactured, it is something you write and publish.
Keep Europe free from software patents, we do not want censorship
by patent law on written works.

As far as the laws of mathematics refer to reality, they are not
certain, and as far as they are certain, they do not refer to reality.
     -- Albert Einstein
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061029/e94b06f4/attachment.bin

More information about the Haskell-Cafe mailing list