Create a gist now

Instantly share code, notes, and snippets.

@bpk-t /TFWH_2.8.md
Last active Mar 18, 2017

TFWH_2.8

練習問題A

Prelude> 2 + 2 / 2
3.0
Prelude> (2 + 2) / 2
2.0
Prelude> (/) ((+) 2 2) 2
2.0

練習問題B

構文として正しくないもの
[0,1)
double double 0
if 1 == 0 then 2 == 1

構文としては正しいが意味のある型を持たないもの
[(+), (-)]
concat ["tea", "for", '2']

正しい形式のもの
double -3
double (-3)
"++" == "+" ++ "+"
[[], [[]], [[[]]]]
concat ["tea", "for", "2"]

練習問題C

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"

練習問題D

  • 先行評価器 -> O(N)
  • 遅延評価器 -> O(1)

先行評価の代替案

f $ head xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment