僕の備忘録(PC、UN*X、ネットワーク関連が中心)なんです。
自分の書いたところは適当(な時とか)に書き換えますので御了承を。
引数二つを取る関数は、だいたい中置できるらしい。
Prelude> 30 `max` 20 30 Prelude> 30 `min` 10 10
リストは同じものしか列挙できない。
Prelude> ["foo", "bar", 3] <interactive>:25:16: No instance for (Num [Char]) arising from the literal `3' Possible fix: add an instance declaration for (Num [Char]) In the expression: 3 In the expression: ["foo", "bar", 3] In an equation for `it': it = ["foo", "bar", 3]
"文字列" は、文字の配列である。
Prelude> "foobar" !! 4 'a' Prelude> ["grape", "watermelon", "pineapple"] !! 2 !! 7 'l'
リストの連続。文字列ではダメみたい。
Prelude> [1..5] [1,2,3,4,5] Prelude> [1.1..5] [1.1,2.1,3.1,4.1,5.1]
そしてリスト内包表記。
Prelude> [x `div` 3 | x <- [10..20]] [3,3,4,4,4,5,5,5,6,6,6]
某所にて聞いた
URLから、
githubのソースを
mathematica にコピペ実行。
どのくらい時間が経ったかよく分からないが、
処理が終わるまで、20-30分程度掛かったと思う。
Prelude> head [1,2,3,4] 1 Prelude> tail [1,2,3,4] [2,3,4] Prelude> init [1,2,3,4] [1,2,3] Prelude> last [1,2,3,4] 4
tail とかinitとかlastとかを「無限リスト」に
書くと、いつまでも演算が完了しなくなる模様。
ちゃんと終われるような関数を使う。
Prelude> take 3 [1,2,3,4,5] [1,2,3] Prelude> take 8 [1..] [1,2,3,4,5,6,7,8]
リンクはご自由にどうぞ。でもURLや内容が変った場合はあしからず。