我真的对GHC.Generics中的“泛型表示类型”感到困惑。我不明白这种数据类型是如何工作的。例如,元信息,M1
newtype M1 i c f p
M1
unM1 :: f p为什么类型M1有四个类型的变量: i,c,f和p。我的意思是,为什么4。它有一些特殊的意义吗?
另外,对于初学者学习GHC泛型的任何书籍或论文都将不胜感激。
发布于 2018-05-10 18:00:27
GHC.Generics没有太多的资源。你最好的选择是在黑客,博客文章和阅读源代码的文档。
以下是我保留的类型同义词的简化引用列表,以便记住GHC.Generics中的所有类型意味着什么。
type TypeName = D1 ('MetaSelector name moduleName packageName isNewType) rest
-- Company from data Company = MkCompany { name :: String, address :: String }
type Constructor = C1 ('MetaCons constructor prefixOrInfix isRecord) rest
-- MkCompany from data Company = MkCompany { name :: String, address :: String }
type NamedSelector = S1 ('MetaSel ('Just selector) unpackednesss sourceStrictness decidedStrictness)
-- age from data Person = Person { age :: Int }
type UnnamedSelector = S1 ('MetaSel Nothing unpackednesss sourceStrictness decidedStrictness)
-- Int from data Wrapper = Wrapper Int
type ConcatSelectors = (:*:)
type ConcatConstructors = (:+:)
type TypeParameter a = Rec0 a
-- a from the right side of data Wrapper a = Wrapper {getA :: a}
type ConstructorEmptyValuePlaceholder = U1
-- data Empty = MkEmpty, MkEmpty is a Constructor but takes no values
-- ConstructorEmptyValuePlaceholder fills the type requirement of Constructorhttps://stackoverflow.com/questions/31109559
复制相似问题