: 中缀运算符在 Haskell 中有什么作用? [英] What does the : infix operator do in Haskell?
本文介绍了: 中缀运算符在 Haskell 中有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在阅读 Haskell 的温和介绍(不太温和)并且它重复使用 :
操作符而不直接解释它的作用.
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?
推荐答案
:
是前置"操作符:
x : xs
返回一个列表,其中 x
作为第一个元素,后跟 xs
中的所有元素.在其他函数式语言中,这通常称为 cons
,因为它通过从空列表中重复应用递归地构造"一个列表:
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 : []
是列表[1, 2, 3, 4]
.
这篇关于: 中缀运算符在 Haskell 中有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文