[Haskell-cafe] Ambiguous type signature in class declaration
Bo Herlin
bo at gcab.net
Wed Apr 27 13:12:57 EDT 2005
Hi
I am trying to make a class like this:
> class CRank a b where
> rank :: a -> b -> Maybe Integer -- Nothing means b is out of range
or badly constructed
> unrank :: a -> Integer -> Maybe b -- Nothing means rank is out of range
> count :: a -> Maybe Integer -- Nothing means infinity
with possible instances like
> data DPrime = Prime deriving (Show)
>
> instance CRank DPrime Integer where
> rank Prime x = Nothing -- to be implemented: (rank Prime 11) should
give (Just 4)
> unrank Prime r = Nothing -- to be implemented: (unrank Prime 4)
should give (Just 11)
> count _ = Nothing -- Nothing means infinity
and
> data DFibonacci = Fibonacci deriving (Show)
>
> instance CRank DFibonacci Integer where
> rank Fibonacci x = Nothing -- to be implemented
> unrank Fibonacci r = Nothing -- to be implemented
> count _ = Nothing -- Nothing means infinity
but all i get is
ERROR "./Cafe.lhs":8 - Ambiguous type signature in class declaration
*** ambiguous type : CRank a b => a -> Maybe Integer
*** assigned to : count
Any suggestions anyone?
Thanks in advance
/Bo
More information about the Haskell-Cafe
mailing list