I don't really get what is wrong with the following code.
data TypeA = TypeA
class MyClass a where
myClassFunction :: a -> String
instance MyClass TypeA where
myClassFunction TypeA = "TypeA"
bar :: (MyClass a) => String -> a
bar "TypeA" = TypeA
I get following error:
Couldn't match expected type ‘a’ with actual type ‘TypeA’
‘a’ is a rigid type variable bound by
the type signature for bar :: MyClass a => String -> a
at test.hs:9:8
Relevant bindings include
bar :: String -> a (bound at test.hs:10:1)
In the expression: TypeA
In an equation for ‘bar’: bar "TypeA" = TypeA
Failed, modules loaded: none.
I'm afraid that I'm missing something crucial about Haskell type system.