Prelude> 2 + 2 / 2
3.0
Prelude> (2 + 2) / 2
2.0
Prelude> (/) ((+) 2 2) 2
2.0
構文として正しくないもの
[0,1)
double double 0
if 1 == 0 then 2 == 1
構文としては正しいが意味のある型を持たないもの
[(+), (-)]
concat ["tea", "for", '2']
正しい形式のもの
double -3
double (-3)
"++" == "+" ++ "+"
[[], [[]], [[[]]]]
concat ["tea", "for", "2"]
1. toUpper
2. 単語リストを文字列に変換
3. [x] ++ xs
Prelude> :m Data.Char
Prelude Data.Char> :{
Prelude Data.Char| capitalize :: String -> String
Prelude Data.Char| capitalize str = unwords $ map (\ x -> [toUpper $ head x] ++ tail x) $ words str
Prelude Data.Char| :}
Prelude Data.Char> capitalize "The morphology of prex -- an essay in meta-algorithmics"
"The Morphology Of Prex -- An Essay In Meta-algorithmics"
- 先行評価器 -> O(N)
- 遅延評価器 -> O(1)
先行評価の代替案
f $ head xs