💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
模式匹配是根据一个匹配的指定值进行分支处理,尽可能深的模式。在Haxe中,所有的模式匹配通过 switch表达式(第5.17节)处理,在其中通过个体的case语句表示模式。这里我们将探索不同的模式的语法,使用这个数据结构作为运行例子: > Pattern matching is the process of branching depending on a value matching given, possibly deep patterns. In Haxe, all pattern matching is done within a switch expression (5.17) where the individual case expressions represent the patterns. Here we will explore the syntax for different patterns using this data structure as running example: ~~~ enum Tree<T> { Leaf(v:T); Node(l:Tree<T>, r:Tree<T>); } ~~~ 一些模式匹配器基础包括: > Some pattern matcher basics include: * 模式总是从头至尾匹配 * 最上面的匹配了输入的值的模式,它的表达式将被执行 * 一个 \_ 匹配任何,所以 case _: 是等同于 default: 的 > * Patterns will always be matched from top to bottom. > * The topmost pattern that matches the input value has its expression executed. > * A _ pattern matches anything, so case _: is equal to default: