[Haskell-cafe] Newbie on instance of Monad

Mauricio briqueabraque at yahoo.com
Fri Oct 31 16:43:48 EDT 2008


After a lot of thinking, I can't get what I
am doing wrong in this code:

data ( RandomGen g ) => RandomMonad g a = RandomMonad (g -> a)

instance Monad (RandomMonad g) where
   return = RandomMonad . const
   RandomMonad f1 >>= f2 = RandomMonad f3 where
     f3 a = f2f1 a (next a)
     RandomMonad f2f1 = f2 . f1

I get this error message:

Could not deduce (RandomGen g)
  from the context (Monad (RandomMonad g))
  arising from a use of `RandomMonad' at src/encherDB.hs:10:11-21
   Possible fix:
    add (RandomGen g) to the context of the type signature for `return'
     In the first argument of `(.)', namely `RandomMonad'
     In the expression: RandomMonad . const
     In the definition of `return': return = RandomMonad . const

but I'm not smart enough to understand what
it means.

Thanks a lot,

More information about the Haskell-Cafe mailing list