:infix操作符在Haskell中做了什么? [英] What does the : infix operator do in Haskell?
本文介绍了:infix操作符在Haskell中做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在阅读 Haskell的简洁介绍(并不那么温和)它会重复使用:
运算符而不直接解释它的作用。
解决方案 c:是前置运算符:
x:xs
返回一个列表,其中包含 x
作为第一个元素,后面是 xs
中的所有元素。在其他函数式语言中,这通常称为 cons
,因为它通过从空列表重复应用递归地构造一个列表:
1:2:3:4:[]
是 [1,2,3,4]
列表。
I'm reading A Gentle Introduction to Haskell (which is not so gentle) and it repeatedly uses the :
operator without directly explaining what it does.
So, what exactly does it do?
解决方案
:
is the "prepend" operator:
x : xs
Returns a list which has x
as first element, followed by all elements in xs
. In other functional languages, this is usually called cons
, because it "cons"tructs a list recursively by repeated application from an empty list:
1 : 2 : 3 : 4 : []
is the list [1, 2, 3, 4]
.
这篇关于:infix操作符在Haskell中做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文