我有一个类型类MyClass,并且它中有一个函数可以生成一个String.我想用这个暗示的实例Show,让我可以通过实施类型MyClass来show.到目前为止,我有,
class MyClass a where
someFunc :: a -> a
myShow :: a -> String
instance MyClass a => Show a where
show a = myShow a
Run Code Online (Sandbox Code Playgroud)
这给出了Constraint is no smaller than the instance head. 我也尝试过的错误,
class MyClass a where
someFunc :: a -> a
myShow :: a -> String
instance Show (MyClass a) where
show a = myShow a
Run Code Online (Sandbox Code Playgroud)
它给出了错误,ClassMyClass'用作类型`.
我怎样才能在Haskell中正确表达这种关系?谢谢.
我应该补充一点,我希望MyClass根据其类型发出特定字符串的特定实例来跟进这一点.例如,
data Foo …Run Code Online (Sandbox Code Playgroud) haskell ×1