一个例子是:
fib: Stream Integer
fib@(1::tfib) = 1 :: 1 :: [ a+b | (a,b) <- zip fib tfib]
但这会产生错误:
50 | fib@(1::tfib) = 1 :: 1 :: [ a+b | (a,b) <- zip fib tfib]
| ^
unexpected "@(1::tfib)"
expecting "<==", "using", "with", ':', argument expression, constraint argument, expression, function right hand side, implementation
block, implicit function argument, or with pattern
鉴于它在可能的位置无法识别@
,这看起来并不乐观。
请注意,as-patterns的相关概念在Haskell和Idris中的作用相同:
growHead : List a -> List a
growHead nnl@(x::_) = x::nnl
growHead ([]) = []