什么是“@”符号是指参考Haskell中的列表? [英] What does the "@" symbol mean in reference to lists in Haskell?

查看:93
本文介绍了什么是“@”符号是指参考Haskell中的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ps @(p:pt)

在这种情况下, @ 符号是什么意思?我似乎无法在Google上找到任何信息(很遗憾,很难在Google上搜索符号),并且我无法在Prelude文档中找到该功能,所以我认为它必须是某种语法糖。 / p>

解决方案

是的,它只是语法上的糖,用 @ 如。 ps @(p:pt)为您提供名称


  1. 清单: ps

  2. 清单头部: p

  3. 清单尾部: 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

  1. the list: ps
  2. the list's head : p
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆