[Haskell-cafe] Existential Types (I guess)
Ozgur Akgun
ozgurakgun at gmail.com
Fri Jan 22 06:31:33 EST 2010
Dear Cafe,
I can write and use the following,
data IntHolder = IntHolder Integer
instance Show IntHolder where
show (IntHolder n) = show n
liftInt :: (Integer -> Integer) -> IntHolder -> IntHolder
liftInt f (IntHolder c) = IntHolder (f c)
But I cannot generalise it to *Num:*
data NumHolder = forall a. Num a => NumHolder a
instance Show NumHolder where
show (NumHolder n) = show n
liftNum :: (Num a) => (a -> a) -> NumHolder -> NumHolder
liftNum f (NumHolder c) = NumHolder (f c)
The error message I get is the following:
Couldn't match expected type `a' against inferred type `a1'
`a' is a rigid type variable bound by
the type signature for `liftNum' at Lifts.hs:54:16
`a1' is a rigid type variable bound by
the constructor `NumHolder' at Lifts.hs:55:11
In the first argument of `f', namely `c'
In the first argument of `NumHolder', namely `(f c)'
In the expression: NumHolder (f c)
Regards,
--
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100122/030d6693/attachment.html
More information about the Haskell-Cafe
mailing list