我试图了解 Data.Data 包的 Constr 类型。考虑下面的会话。dataTypeConstrs
返回Constr
Maybe 的零参数和单参数构造函数的列表。由于明显的类型错误,尝试重新创建列表失败。它是 GHC 关于 Consr 值的特殊行为吗?
$ ghci
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
Prelude> :set -XScopedTypeVariables
Prelude> :module +Data.Data
Prelude Data.Data> dataTypeConstrs (dataTypeOf (Nothing :: Maybe ()))
[Nothing,Just]
Prelude Data.Data> :i it
it :: [Constr] -- Defined at <interactive>:4:1
Prelude Data.Data> let i2 :: [Constr] = [Nothing,Just]
<interactive>:6:23:
Couldn't match expected type ‘Constr’ with actual type ‘Maybe a0’
In the expression: Nothing
In the expression: [Nothing, Just]