Document the nullary-variant period in alt patterns
This commit is contained in:
parent
ba1df0eda9
commit
6afecc37e3
1 changed files with 9 additions and 0 deletions
|
|
@ -3396,12 +3396,21 @@ alt x @{
|
|||
cons(10, _) @{
|
||||
process_ten();
|
||||
@}
|
||||
nil. @{
|
||||
ret;
|
||||
@}
|
||||
_ @{
|
||||
fail;
|
||||
@}
|
||||
@}
|
||||
@end example
|
||||
|
||||
Note in the above example that @code{nil} is followed by a period. This is
|
||||
required syntax for pattern matching a nullary tag variant, to distingush the
|
||||
variant @code{nil} from a binding to variable @code{nil}. Without the period
|
||||
the value of @code{x} would be bound to variable @code{nil} and the compiler
|
||||
would issue an error about the final wildcard case being unreachable.
|
||||
|
||||
Multiple alternative patterns may be joined with the @code{|} operator. A
|
||||
range of values may be specified with @code{to}. For example:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue