[英]What does the type mean?
This is the newtype: 这是新类型:
newtype Combine a b = Combine { unCombine :: (a -> b) }
I'm having problems understanding many things about this line, but the first is the braces. 我在理解有关这条线的许多事情时遇到了问题,但首先是大括号。 What are they and what do they do here - create a function from two input datatypes?
它们是什么,它们在做什么?-从两个输入数据类型创建一个函数?
The braces allow for record syntax. 花括号允许记录语法。 It can be considered short-hand for the following:
它可以被视为以下方面的简写:
newtype Combine a b = Combine (a -> b)
unCombine :: Combine a b -> (a -> b)
unCombine (Combine a) = a
Record syntax creates the unCombine
function for you automatically so you don't have to define it for yourself. 记录语法会自动为您创建
unCombine
函数,因此您不必自己定义它。 It comes in handy when your types have a lot of type parameters. 当您的类型具有很多类型参数时,它会派上用场。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.