How does | (pipe) in pattern matching work?
你可以写:
乍一看,
不起作用。(我也不知道这是怎么实现的。)
所以它是一个神奇的内置操作器?
(我相信我以前见过这个问题,但不可能找到…)
而
是的,管道(
A pattern alternative p1 | ... | pn
consists of a number of alternative
patterns pi . All alternative patterns
are type checked with the expected
type of the pattern. They may no bind
variables other than wildcards. The
alternative pattern matches a value v
if at least one its alternatives
matches v.
所以是的,管道是一个内置的,对模式匹配上下文敏感。