The problem seems equivalent to the following: http://pobox.com/~oleg/ftp/Haskell/typecast.html#local-fd That is, the inferred type is too general to chose the appropriate instance. The solution is also the same: either add type annotations to restrict the inferred type (and so make it _match_ the desired instance) -- or use local type inference. Here's the working code of your Haskell embedding of the Forth-like stack language:
> {-# OPTIONS -fglasgow-exts #-} > {-# OPTIONS -fallow-undecidable-instances #-} > > main = print $ test () > > test = square . 4 > > dup (a, b) = (a, (a, b)) > mult (a, (b, c)) = (b*a, c) > square = mult . dup > > instance Num c => Eq (a -> (c, b)) > instance Num c => Show (a -> (c, b)) > instance (Num c, TypeCast a b) => Num (a -> (c, b)) where > fromInteger val stack = (fromInteger val,typeCast stack) [TypeCast elided] _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe