Hello,
Consider the following program:
-------------------------------------------------------------------
-- bar.hs
{-# LANGUAGE NoMonomorphismRestriction #-}
data Status = Foo | Bar
data Rec m a = Rec {
get :: m a
, status :: Status
}
defRec :: (Monad m) => Rec m a
defRec = undefined
myRec :: (Monad m) => Rec m a
myRec = Rec x y
where
Rec x y = defRec
-------------------------------------------------------------------
It doesn't compile (under GHC 7.10.2), the error is:
bar.hs:16:7:
No instance for (Monad t0)
The type variable ‘t0’ is ambiguous
When checking that ‘y’ has the inferred type
y :: Status
Probable cause: the inferred type is ambiguous
In an equation for ‘myRec’:
myRec
= Rec x y
where
Rec x y = defRec
Failed, modules loaded: none.
If you remove the language extension, it does.
Keeping the NoMonomorphismRestriction, it can be forced to typecheck by putting in a "dummy" type that satifies the constraint when obtaining the field `status` (that doesn't depend on `m`.
-------------------------------------------------------------------
-- bar.hs
{-# LANGUAGE NoMonomorphismRestriction #-}
data Status = Foo | Bar
data Rec m a = Rec {
get :: m a
, status :: Status
}
defRec :: (Monad m) => Rec m a
defRec = undefined
myRec :: (Monad m) => Rec m a
myRec = Rec x y where
s :: Rec Maybe a -> Status
s = status
x = get defRec
--
y = s defRec
-------------------------------------------------------------------
So, what's going on here? Is this a feature of this extension? It seems like the ability to destructure and then recombine is pretty fundamental, and it shouldn't break in the way that it does. (I.e. it's kinda crazy to have to put in a dummy type satisfying the constraint; is there some way to pass down the error
--