我真的不知道下面的代碼有什麼問題。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
從問題中不清楚你想要動態調度,不。 –