什么是“@”符号是指参考Haskell中的列表? [英] What does the "@" symbol mean in reference to lists in Haskell?
问题描述
ps @(p:pt)
在这种情况下, @
符号是什么意思?我似乎无法在Google上找到任何信息(很遗憾,很难在Google上搜索符号),并且我无法在Prelude文档中找到该功能,所以我认为它必须是某种语法糖。 / p>
是的,它只是语法上的糖,用 @
如。 ps @(p:pt)
为您提供名称
- 清单:
ps
- 清单头部:
p
- 清单尾部:
pt
没有<$ c $ (1)或(2):( 3)。
这个语法实际上适用于任何构造函数;如果你有数据树a =树a [树a]
,那么 t @(Tree _ kids)
会给你访问树及其子项。
I've come across a piece of Haskell code that looks like this:
ps@(p:pt)
What does the @
symbol mean in this context? I can't seem to find any info on Google (it's unfortunately hard to search for symbols on Google), and I can't find the function in the Prelude documentation, so I imagine it must be some sort of syntactic sugar instead.
Yes, it's just syntactic sugar, with @
read aloud as "as". ps@(p:pt)
gives you names for
- the list:
ps
- the list's head :
p
- the list's tail:
pt
Without the @
, you'd have to choose between (1) or (2):(3).
This syntax actually works for any constructor; if you have data Tree a = Tree a [Tree a]
, then t@(Tree _ kids)
gives you access to both the tree and its children.
这篇关于什么是“@”符号是指参考Haskell中的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!