
On Tue, 22 Apr 2003, Derek Elkins wrote:
I had a similar problem, but that was because I needed to use the constructors. MonadState has the methods you are using just write your code requiring MonadState as both State and StateT are instances.
next_random_probability :: ( ..., MonadState g m) => m a (snip)
Works perfectly, thanks very much! That must be the only combination I didn't try. (-:
When you have two identical methods like this, you can try removing the type from one and seeing what hugs or ghci thinks the type is. Then, you can specialize that if you want.
No doubt it'll all be clearer when I better understand what's going on!
Jon Cast

On Tue, 22 Apr 2003, Jon Cast wrote:
When you have two identical methods like this, you can try removing the type from one and seeing what hugs or ghci thinks the type is. Then, you can specialize that if you want.
Unfortunately, in this case, with that function in isolation I get, Ambiguous type variable(s) `s', `m' in the constraint `MonadState s m' arising from use of `get' .... and with it being used in other functions I get things like, Inferred type is less polymorphic than expected Quantified type variable `m' escapes or similar. That is, I haven't yet managed to make the function compile without a type signature! I have found your technique useful in other contexts, though. (-: -- Mark

Unfortunately, in this case, with that function in isolation I get,
Ambiguous type variable(s) `s', `m' in the constraint `MonadState s m' arising from use of `get' ....
An easy way to get round this is to give a completely bogus type signature like: foo :: a The compiler will report a mismatch and the error message will tell you what it thinks the type is. -- Alastair Reid alastair@reid-consulting-uk.ltd.uk Reid Consulting (UK) Limited http://www.reid-consulting-uk.ltd.uk/alastair/

On Tue, 22 Apr 2003 23:05:09 +0100
Alastair Reid
Unfortunately, in this case, with that function in isolation I get,
Ambiguous type variable(s) `s', `m' in the constraint `MonadState s m' arising from use of `get' ....
An easy way to get round this is to give a completely bogus type signature like:
foo :: a
The compiler will report a mismatch and the error message will tell you what it thinks the type is.
Or the straightforward and simple answer: in GHCi or Hugs, just do :t f. E.g. :t get ==> (MonadState s m) => m s. GHCi (and I imagine Hugs too) doesn't try to validate the constraints.
participants (4)
-
Alastair Reid
-
Derek Elkins
-
Jon Cast
-
Mark Carroll