Skip to content

Commit 315308a

Browse files
committed
Begin to explain pattern-matching in a lambda abstraction
1 parent 51ef49b commit 315308a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

assets/18.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1013,18 +1013,18 @@ ghci> entry = Entry { category = cat, price = pri }
10131013

10141014
#### ラムダ抽象の引数でのパターンマッチ
10151015

1016-
引数でのパターンマッチは、ラムダ抽象でも使える
1016+
前節で説明したとおり、パターンマッチは変数へ代入する箇所であればどこでも利用できます。課題hoge(15?)で紹介したラムダ抽象における引数も、もちろん例外ではありません
10171017

1018-
つまり、
1018+
例えば次のように、タプルを受け取る関数`tupleToEntry`があったとしましょう:
10191019

1020-
```
1020+
```haskell
10211021
tupleToEntry :: (String, Integer) -> Entry
10221022
tupleToEntry (cat, pri) = Entry cat pri
10231023
```
10241024

1025-
↑と↓は同じ!
1025+
この`tupleToEntry`関数は、(あまり役に立つ書き換えではないですが)ラムダ抽象を使って次のように書き換えることができます:
10261026

1027-
```
1027+
```haskell
10281028
tupleToEntry :: (String, Integer) -> Entry
10291029
tupleToEntry = \(cat, pri) -> Entry cat pri
10301030
```

0 commit comments

Comments
 (0)