[Haskell-cafe] Fun with multi-parameter type classes
Jon Cast
jcast at ou.edu
Thu Aug 19 16:33:39 EDT 2004
> Hi,
>
> I've been getting into Haskell over the past few months and have just
> come up against a bit of a brick wall when trying to encapsulate
> some of the data structures in my code nicely. Basically what I
> want to have, is a type class where one of the intermediate values
> is opaque with respect to code using its implementations. This is
> a simplified version of what I'm trying to accomplish:
>
> class Foo t where
> encode :: String -> t
> decode :: t -> String
>
> instance Foo Int where
> encode = read
> decode = show
>
> test = decode . encode
>
> This currently fails, because the type checker insists on trying to
> figure out what its type should be - even though it shouldn't be
> needed.
The intermediate type /is/ needed---it's a (hidden) parameter to your
`encode' and `decode' functions. Why do you think it shouldn't be?
<snip>
Jon Cast
More information about the Haskell-Cafe
mailing list