我真的不知道下面的代码有什么问题。Haskell中的刚性类型变量
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
我收到以下错误:
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.
我怕我失去了一些东西约Haskell的类型系统是至关重要的。
该代码的目标是什么? –
@BartekBanachewicz主要尝试使用Haskell类型系统和动态调度(我不确定这是这里的情况) – Saczew
从问题中不清楚你想要动态调度,不。 –