[Haskell-cafe] Re: Newbie on instance of Monad

Mauricio briqueabraque at yahoo.com
Sun Nov 2 08:31:34 EST 2008


>> Hi,
>>
>> 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)
> 
> RandomGen g is considered the constraint for the application of 
> RandomMonad constructor, but GHC does not conclude that every value of 
> (RandomMonad g a) fulfills this constraint. Actually, 'undefined' is 
> available for any 'g'.
> 
> you need to make (RandomGen g) a constraint of the instance:
> 
> instance RandomGen g => Monad (RandomMonad g) where

Nice. I wasn't so wrong as I though :)

I didn't understand why can't the compiler deduce
that g is always going to be of type RandomGen. Even
if I use 'undefined', it has to be a RandomGen undefined.

> Btw. RandomMonad looks like Control.Monad.Reader.

You are right, I'll try that instead so I learn a little
bit more. But I can't understand this syntax:

class (Monad m) => MonadReader r m | m -> r where

What is the '|' doing there? I'll post that in a new thread
since it's a different question.

Thanks,
Maurício



More information about the Haskell-Cafe mailing list