##1. Introduction ###About this tutorial 想定読者は手続き型言語(C, C++, Java, Python …)を経験しているが関数型言語(Haskell, ML, OCaml …)を経験していない人.
###So what's Haskell? Haskellは
- 純粋関数型言語
- 評価戦略は遅延評価
- 型推論のある静的型付け言語
##2. Starting Out ###Ready, set, go!
- 基本的な関数の紹介
- 四則演算
- 論理演算
- Eqのメソッド
- Enumのメソッド
- 負の数は注意
-3
,(-3)
- 関数の結合強度が最強
- 中置記法,
\
div`` - カッコの付け方が代表的な手続き型言語とは違うから注意
bar(3)
,bar 3
###Baby's first functions 関数を定義する
doubleMe x = x + x
- if文
'
も名前に使える- 一つも引数を取らない関数は定義や名前をつけているだけ
###An intro to lists
- lists are a homogenous data structure
++
,:
- [1,2,3] is actually just syntactic sugar for 1:2:3:[]
!!
head
,tail
,last
,init
head
は部分関数なので[]
には使えないlength
,null
,reverse
,take
,drop
,maximum
,minimum
,sum
,product
,elem
###Texas ranges
[1..20]
['a'..'z']
[2,4..20]
cycle
,repeat
###I'm a list comprehension
[x*2 | x <- [1..10]]
[x*2 | x <- [1..10], x*2 >= 12]
[x | x <- [10..20], x /= 13, x /= 15, x /= 19]
[x*y | x <- [2,5,10], y <- [8,10,11]]
###Tuples
(1, 2)
fst
,snd
,zip
##3. Types and Typeclasses
- 型
- Int
- Integer
- Float
- Double
- Bool
- Char
- 型クラス
- Eq
- Ord
- Show
- Read
- Enum
- Bounded
- Num
- Integral
- Floating
##4. Syntax in Functions
- パターンマッチ
- ガード
- let, where
- case文
##5. Recursion
- 再帰でmaximum関数の実装