以下是我到目前为止的尝试:
module Main where
data FooT = One | Two deriving (Show, Read)
{-
That is what I want
foo :: (Show a, Read a) => a
foo = One
-}
--class Footable (Show a, Read a) => a where
class Footable a where
--foo2 :: (Show a, Read a) => a
foo2 :: a
instance Footable FooT where
foo2 = One
-- test = print foo2
Run Code Online (Sandbox Code Playgroud)
我想测试编译.我认为问题不在于普遍量化.ghc说a是一个'严格的类型变量' 编辑(刚性类型变量),但我真的不理解这是什么.这个问题似乎与此有关
编辑
正如我在@ sepp2k的评论中写的那样,它可能与存在主义类型有关,但我偶然发现了一个奇怪的行为:
这确实编译: …