在( 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
我想知道以下内容,但在更改说明中找不到答案: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/