【问题标题】:What does the expression `first @ (x:xs) ` and `second @(y:ys)` mean? [duplicate]表达式`first @ (x:xs)`和`second @(y:ys)`是什么意思? [复制]
【发布时间】:2020-03-27 00:06:16
【问题描述】:

我看到了 Haskell 代码的 sn-p,它递归地将两个列表连接在一起,同时按升序对其进行排序:

merge :: Ord a => [a] -> [a] -> [a]
merge [] xs = xs
merge ys[] = ys

merge first @ (x:xs) second @(y:ys)
   | x <y = x :merge xs (y:ys)
   | otherwise = y : merge ys (x:xs)

我不明白merge first @ (x:xs) second @(y:ys) 这行是做什么的。

【问题讨论】:

标签: haskell


【解决方案1】:

找出答案的简单方法是在 GHCi(GHC 解释器)中尝试。如果你运行:

$ ghci
Prelude> functionName bind@(first:rest) = print(bind ++ ", " ++ [first] ++ ", " ++ rest)
Prelude> functionName "test"
"test, t, est"

我们看到,如果我们调用functionName,我们得到的是:

bind  => test
first => t
rest  => est

所以我们可以说:

  1. bind 接收发送的整个参数,
  2. first 成为争论的焦点;参数的第一个元素,
  3. rest 接受除参数的第一个元素之外的所有内容。

【讨论】:

    猜你喜欢
    • 2013-10-13
    • 1970-01-01
    • 2015-06-21
    • 2013-03-05
    • 2013-11-22
    • 1970-01-01
    • 2014-09-02
    • 2016-06-10
    • 2014-12-06
    相关资源
    最近更新 更多