简体   繁体   English

GHC不接受GADT类型签名

[英]GHC does not accept GADT type signature

This declaration doesn't work: 该声明不起作用:

data Identity a where {Identity :: (->) a (Identity a)}

How to fix this? 如何解决这个问题?

At least as of GHC 7.8, if you turn on GADT support, then your code typechecks and does what you'd expect : 至少从GHC 7.8开始, 如果你打开GADT支持,那么你的代码可以检查并做你期望的事情

{-# LANGUAGE GADTs #-}
data Identity a where {Identity :: (->) a (Identity a)}

resulting in: 导致:

GHCi, version 7.8.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( foo.hs, interpreted )
Ok, modules loaded: Main.
λ» :i Identity
data Identity a = Identity a    -- Defined at foo.hs:2:1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM