[Haskell-cafe] Ambiguous type signature in class declaration
Bo Herlin
bo at gcab.net
Thu Apr 28 07:00:13 EDT 2005
Hi again
Next approach:
> module Cafe where
>
> class CRankable a where
> rank :: a b -> b -> Maybe Integer -- Nothing means b is out of
range or badly constructed
> unrank :: a b -> Integer -> Maybe b -- Nothing means rank is out of
range
> count :: a b -> Maybe Integer -- Nothing means infinity
This works ok:
> data CPrime a = Prime deriving (Show)
>
> instance CRankable CPrime where
> rank Prime x = Nothing
> unrank Prime r = Nothing
> count Prime = Nothing
But once i start returning anything but Nothing like:
> data CPrime' a = Prime' deriving (Show)
>
> instance CRankable CPrime' where
> rank Prime' x = Just x
> unrank Prime' r = Just r
> count Prime' = Nothing
i get:
ERROR "./Cafe.lhs":26 - Inferred type is not general enough
*** Expression : rank
*** Expected type : CRankable CPrime' => CPrime' a -> a -> Maybe Integer
*** Inferred type : CRankable CPrime' => CPrime' Integer -> Integer ->
Maybe Integer
so where exactly do i say a is an Integer?
/Bo
More information about the Haskell-Cafe
mailing list