[Haskell-cafe] A Very Simple Type Class Question
Tom Ellis
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Tue Nov 11 22:19:55 UTC 2014
On Tue, Nov 11, 2014 at 03:59:50PM -0500, Larry Lee wrote:
> I have a very simple problem.
> I have a class and want to define a function in that class that
> returns a different instance of the same class.
>
> I tried accomplishing this as follows:
>
> class A a where
> f :: A b => a -> b
>
>
> This fails however when I try to instantiate it. For example:
>
> instance A String where
> f x = x
The `f` that you defined has type `String -> String`. However, given the
definition of the class `A` it should have been of type `A b => String ->
b`.
What exactly are you trying to do here? This is probably not the way to go
about it.
Tom
More information about the Haskell-Cafe
mailing list