[Haskell-cafe] Newbie on instance of Monad

2008-10-31 Thread Mauricio

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)

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,
MaurĂ­cio

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2008-10-31 Thread Henning Thielemann


On Fri, 31 Oct 2008, Mauricio wrote:


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'.



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


you need to make (RandomGen g) a constraint of the instance:

instance RandomGen g = Monad (RandomMonad g) where


Btw. RandomMonad looks like Control.Monad.Reader.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2008-10-31 Thread Henning Thielemann


On Fri, 31 Oct 2008, Jonathan Cast wrote:


On Fri, 2008-10-31 at 18:43 -0200, Mauricio wrote:

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)

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


Yikes.  Just search the archives for `Set not a Monad'; you have the
same issue.


I think that this would be the answer if he is after a constraint for 'a', 
but he wants to constraint 'g'.



Hint: data RandomGen g = RandomMonad g a means nothing at all like what
you think it means.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2008-10-31 Thread Jonathan Cast
On Fri, 2008-10-31 at 18:43 -0200, Mauricio wrote:
 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)
 
 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.

Yikes.  Just search the archives for `Set not a Monad'; you have the
same issue.

Hint: data RandomGen g = RandomMonad g a means nothing at all like what
you think it means.

jcc


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe