简体   繁体   English

haskell 中非记录数据构造函数的术语

[英]Term for non-record data constructors in haskell

data A b c = B | C b | H { b :: b, c :: c }

AFAIK, B is called nullary constructor C is called unary constructor, while H is called record. AFAIK, B称为空构造函数C称为一元构造函数,而H称为记录。

But what is the term for arbitrary-arity constructors including both B and C ?但是包括BC在内的任意元构造函数的术语是什么? Is there something better than non-record constructors?有比非记录构造函数更好的东西吗?

I'm not sure they deserve a special name.我不确定他们是否值得一个特殊的名字。 A record constructor is basically just a non-record constructor with some automatically defined accessor functions and convenient syntactic support.记录构造函数基本上只是一个非记录构造函数,带有一些自动定义的访问器函数和方便的语法支持。 In your example above, I would consider H a binary constructor or a constructor of arity 2, since I can construct and destruct it like any other binary constructor:在上面的示例中,我将H视为二进制构造函数或 arity 2 的构造函数,因为我可以像任何其他二进制构造函数一样构造和销毁它:

let H a b = H (1+1) (2+2) in (a,b)

For what it's worth, the Haskell98 report just calls them "constructors with field labels" and "constructors without field labels" and makes it pretty clear that even with field labels they are still "data constructors of arity k".就其价值而言,Haskell98 报告只是将它们称为“具有字段标签的构造函数”和“没有字段标签的构造函数”,并清楚地表明,即使有字段标签,它们仍然是“arity k 的数据构造函数”。

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

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