haskell - 使用 `as` 语法的惰性模式匹配的语法

标签 haskell ghci

在( Vanilla )GHCi 8.6.5 中,以下功能完全有效:

f xs@ ~(x:xt) = xs
如果我现在在 9.0.1 中做同样的事情,我会得到一个错误
Suffix occurrence of @. For an as-pattern, remove the leading whitespace.
只需删除 @ 之间的空格即可和 ~似乎还不够,因为那时@~将被解释为运算符,因此我发现的唯一有效变体是
f xs@(~(x:xt)) = xs
我想知道以下内容,但在更改说明中找不到答案:
  • 从 8.6.5 到 9.0.1 究竟发生了什么变化导致了这种不兼容性?
  • xs@(~(x:xt))真的是编写这种模式的最佳方式,还是有比这更好的方式?
  • 最佳答案

    GHC 9.0 中对 ~ 和 @ 处理的更改描述为 here .引用迁移指南:

    GHC 9.0 implements Proposal 229, which means that the !, ~, and @ characters are more sensitive to preceding and trailing whitespace than they were before. As a result, some things which used to parse one way will now parse differently (or throw a parse error).

    关于haskell - 使用 `as` 语法的惰性模式匹配的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67972231/

    相关文章:

    haskell - 这样的功能是否已经存在? (或者,这个函数有什么更好的名字?)

    list - Haskell:编译函数与解释函数之间的奇怪差异,这些函数打印连接的无限列表

    haskell - 如何使用堆栈和 GHCI 获取堆栈跟踪?

    haskell - GHC : partially compile Haskell code?

    javascript - 功能珍珠 : Implementing trace in JavaScript

    haskell - 您对辅助函数的命名约定是什么?

    haskell - GADT - 应用和用处?

    haskell - 将类型级别列表转换为值

    haskell - 如何在ghci的多行模式下编辑前一行?

    list - Haskell 多行 `let` in `ghci`