[英]Haskell: Are list comprehensions higher order functions?
我有一个我们不应该使用任何更高阶函数的赋值,列表理解是否可以归类为更高阶函数?
A list comprehension in Haskell is just syntactic sugar. Haskell中的列表理解只是语法糖。 It is defined in the Haskell 2010 Report here like so: 它在哈斯克尔报告2010定义在这里 ,像这样:
[ e | True ] = [e]
[ e | q ] = [ e | q, True ]
[ e | b, Q ] = if b then [ e | Q ] else []
[ e | p <- l, Q ] = let ok p = [ e | Q ]
ok _ = []
in concatMap ok l
[ e | let decls, Q ] = let decls in [ e | Q ]
Note the use of Q
, which ranges over qualifiers (which can include functions), in the patterns. 注意Q
的使用,它在模式中的限定符(可以包括函数)范围内。 So the answer is yes, a list comprehension is higher-order. 所以答案是肯定的,列表理解是高阶的。
”Higher order" has a specific meaning. If a function takes an argument which is a function (or returns a function), the former is said to be higher order. (For example: map.) “高阶”具有特定的含义。如果函数接受一个函数的参数(或返回一个函数),则前者被称为更高阶。(例如:map。)
List comprehensions are expressions representing list values, not functions. 列表推导是表示列表值而不是函数的表达式。 So the answer is: No. 所以答案是:不。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.