如何进行GHC.泛型表示有效



我真的被GHC中的"泛型表示类型"弄糊涂了。Generics。我不明白这种数据类型是如何工作的。例如,元信息,M1:

newtype M1 i c f p
M1
  unM1 :: f p

为什么类型M1有四个类型变量:i、c、f和p。我的意思是,为什么4。它有什么特别的意义吗?

此外,任何适合初学者学习GHC Generics的书籍或论文都将不胜感激。

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 Constructor

最新更新