Multiparamater class type-inference error

Hi all, Sorry if this is too GHC-specific. I'm getting this strange instantiation error when compiling the following code with GHC 6.6: No instance for (Synchronous s ((a, b) -> a) (a, b) a) arising from use of `mapSY' at SynchronousLib.lhs:342:8-16 Possible fix: add an instance declaration for (Synchronous s ((a, b) -> a) (a, b) a) In the expression: mapSY fst In the definition of `fstSY': fstSY = mapSY fst --- data Signal a = NullS | a :- Signal a deriving (Eq) class Synchronous s f1 a b | f1 -> a , f1 -> b where mapSY :: f1 -> s a -> s b delaySY :: a -> s a -> s a instance Synchronous Signal (a->b) a b where mapSY _ NullS = NullS mapSY f (x:-xs) = f x :- (mapSY f xs) delaySY e es = e:-es fstSY = mapSY fst {-- No instance for (Synchronous s ((a, b) -> a) (a, b) a) arising from use of `mapSY' at SynchronousLib.lhs:342:8-16 Possible fix: add an instance declaration for (Synchronous s ((a, b) -> a) (a, b) a) In the expression: mapSY fst In the definition of `fstSY': fstSY = mapSY fst Failed, modules loaded: AbsentExt, Vector, Queue, Signal. --} -- No error arises if fstSY is declared as fstSY a = mapSY fst a Is it GHC bug or am I supposed to declare it like that to assist type inference? Thanks in advance, Alfonso Acosta

Forgot to mention that no error arises if I explicitly give the type
signature of fstSY
fstSY :: Signal (a,b) -> Signal a
On 1/29/07, Alfonso Acosta
Hi all,
Sorry if this is too GHC-specific. I'm getting this strange instantiation error when compiling the following code with GHC 6.6:
No instance for (Synchronous s ((a, b) -> a) (a, b) a) arising from use of `mapSY' at SynchronousLib.lhs:342:8-16 Possible fix: add an instance declaration for (Synchronous s ((a, b) -> a) (a, b) a) In the expression: mapSY fst In the definition of `fstSY': fstSY = mapSY fst
--- data Signal a = NullS | a :- Signal a deriving (Eq)
class Synchronous s f1 a b | f1 -> a , f1 -> b where mapSY :: f1 -> s a -> s b delaySY :: a -> s a -> s a
instance Synchronous Signal (a->b) a b where mapSY _ NullS = NullS mapSY f (x:-xs) = f x :- (mapSY f xs) delaySY e es = e:-es
fstSY = mapSY fst
{-- No instance for (Synchronous s ((a, b) -> a) (a, b) a) arising from use of `mapSY' at SynchronousLib.lhs:342:8-16 Possible fix: add an instance declaration for (Synchronous s ((a, b) -> a) (a, b) a) In the expression: mapSY fst In the definition of `fstSY': fstSY = mapSY fst Failed, modules loaded: AbsentExt, Vector, Queue, Signal. --} --
No error arises if fstSY is declared as
fstSY a = mapSY fst a
Is it GHC bug or am I supposed to declare it like that to assist type inference?
Thanks in advance,
Alfonso Acosta

Alfonso Acosta wrote:
fstSY = mapSY fst No instance for (Synchronous s ((a, b) -> a) (a, b) a)... ...no error arises if I explicitly give the type signature of fstSY fstSY :: Signal (a,b) -> Signal a
This is the notorious Monomorphism Restriction. See http://www.haskell.org/haskellwiki/Monomorphism_restriction You can get around it either by specifying the type, as you discovered, or by using the -fno-monomorphism-restriction flag for ghc or ghci. In ghci you can also specify this as a :set command, hence also in your .ghci file if you'd like. Hope this helps, Yitz
participants (2)
-
Alfonso Acosta
-
Yitzchak Gale