Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sc-475] Add documentation for new match options #212

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,53 @@ data List = (List.cons head tail) | (List.nil)
ListEx2 = (List.cons 1 (List.cons 2 (List.cons 3 List.nil)))
```

Match different kinds of terms, both matches are equivalent:
imaqtkatt marked this conversation as resolved.
Show resolved Hide resolved
```rs
match list {
(List.cons hd tl): (Some hd)
List.nil: None
}

match list {
developedby marked this conversation as resolved.
Show resolved Hide resolved
List.cons: (Some list.head)
List.nil: None
}

match bind = list {
List.cons: (Some bind.head)
List.nil: None
}
```

Match native numbers:
```rs
match 4 {
0: "zero"
5: "five"
4: "four"
_: "other"
}
```

Which is the equivalent of nesting match terms:
```rs
match 4 {
0: "zero"
1+a: match (- a 4) {
imaqtkatt marked this conversation as resolved.
Show resolved Hide resolved
0: "five"
_: ...
}
}
```

Match multiple terms:
```rs
match True, True {
imaqtkatt marked this conversation as resolved.
Show resolved Hide resolved
True True: True
_ _: False
}
```

### More features

Key:
Expand Down
Loading