20 Dec 17:03
Re: Class/Instance : what am I doing wrong in this example ?
Claude Heiland-Allen <claudiusmaximus <at> goto10.org>
2007-12-20 16:03:30 GMT
2007-12-20 16:03:30 GMT
david48 wrote:
| I'm really inexperienced at this :
> class Gadget g where
> fInit :: g -> a -> g
>
> data FString = FString !Int !String deriving Show
>
> instance Gadget FString where
> fInit (FString n _) s = FString n (take n s)
The types of:
> fInit :: g -> a -> g
and:
> take :: Int -> [a] -> [a]
cause the mismatched types error.
You're trying to apply 'take n' to a value of type 'a' ('take n'
requires [a]), moreover putting the value of 'take n s' into the FString
further constrains its type to be [Char] == String.
So either fix the Gadget g class, or fix the Gadget FString instance.
Claude
--
--
http://claudiusmaximus.goto10.org
RSS Feed