Skip to content

Commit 0a9bb6d

Browse files
committed
Begin to fill the contents of ex18
1 parent aff32a7 commit 0a9bb6d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

assets/18.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55

66
## 必要な知識
77

8+
Haskellには、コードを極めて簡潔に書くテクニックが、たくさんあります。この課題では、そうしたテクニックのうち、特によく使われるものを紹介します。みなさんがHaskellを書くときに必ずしもここで学習したことを使う必要はないですが、既存のHaskell製コードの中でも高確率で使われているので、是非習得してください。
9+
810
### (カリー化された)関数の部分適用
911

12+
まずは、関数の部分適用という手法を知ることで、ありふれた関数の定義を書かずに済ませられるようになるほか、Haskellにおける関数`->`の秘密も知りましょう。
13+
1014
`map`関数
1115

12-
```
16+
```haskell
1317
ghci> :t map
1418
map :: (a -> b) -> [a] -> [b]
1519
```
1620

1721
関数`(a -> b)`とリスト`[a]`という引数を二つ受け取る
1822

19-
```
23+
```haskell
2024
ghci> map (\x -> x * 2) [3, 8, 9]
2125
[6,16,18]
2226
```
@@ -889,13 +893,15 @@ ghci> dangerous = \(Just x) -> x
889893

890894
## HLintで改善点をある程度自動で見つける
891895

892-
```
896+
```bash
897+
shell> cabal install hlint
898+
# あるいは...
893899
shell> stack install hlint
894900
```
895901

896902
ここで紹介していない`TupleSections`というGHCの拡張を使ったものも(GHCの拡張の話を後回しにしたいので敢えて紹介していません... あしからず)。
897903

898-
```
904+
```bash
899905
shell> hlint assets/16.hs
900906
assets/16.hs:18:14: Warning: Avoid lambda
901907
Found:

0 commit comments

Comments
 (0)