Skip to content

Commit

Permalink
records: pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentpayot committed Oct 19, 2023
1 parent fbf34c0 commit 36cc494
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ foo = 1 + ?what_could_this_be

## Arrays

<!-- TODO make this just like the Lists section -->

```purs
myArray = [2,4,3]
Expand Down Expand Up @@ -198,6 +196,17 @@ bumpAge :: Person -> Person
bumpAge p@{ age } =
p { age = age + 1 }
```
### Pattern matching

```purs
ecoTitle {author: "Umberto Eco", title: t} = Just t
ecoTitle _ = Nothing
ecoTitle {title: "Foucault's pendulum", author: "Umberto Eco"} -- (Just "Foucault's pendulum")
ecoTitle {title: "The Quantum Thief", author: "Hannu Rajaniemi"} -- Nothing
-- ecoTitle requires both field to type check
ecoTitle {title: "The Quantum Thief"} -- Object lacks required property "author"
```

### Row Polymorphism

Expand Down

0 comments on commit 36cc494

Please sign in to comment.