Create a gist now

Instantly share code, notes, and snippets.

練習問題E

Prelude> 1 + (2 + 3)
6
Prelude> (1 + 2) + 3
6
Prelude> [1] ++ ([2] ++ [3])
[1,2,3]
Prelude> ([1] ++ [2]) ++ [3]
[1,2,3]
Prelude> 1 - (2 - 3)
2
Prelude> (1 - 2) -3
-4
  • 加法の単位元→0
  • 連接の単位元→[]
  • 関数合成の単位元→id

練習問題G

Prelude> :m Data.Char
Prelude Data.Char> let nums = ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
Prelude Data.Char> :{
Prelude Data.Char| count 0 = ""
Prelude Data.Char| count n = map toLower (nums !! (n - 1)) ++ " men, " ++ count (n - 1)
Prelude Data.Char| :}
Prelude Data.Char> line2 = "Went to mow a meadow\n"
Prelude Data.Char> line4 = line2 ++ "\n"
Prelude Data.Char> :{
Prelude Data.Char| line3 1 = "One man add his dog\n"
Prelude Data.Char| line3 n = nums !! (n - 2) ++ " men " ++ count (n - 2) ++ "One man and his dog\n"
Prelude Data.Char| :}
Prelude Data.Char> :{
Prelude Data.Char| line1 1 = "One man went to mow\n"
Prelude Data.Char| line1 n = nums !! (n - 2) ++ " men went to mow\n"
Prelude Data.Char| :}
Prelude Data.Char> verse n = line1 n ++ line2 ++ line3 n ++ line4
Prelude Data.Char> :{
Prelude Data.Char| song 0 = ""
Prelude Data.Char| song n = song (n - 1) ++ "\n" ++ verse n
Prelude Data.Char| :}

Prelude Data.Char> putStr (song 3)

One man went to mow
Went to mow a meadow
One man add his dog
Went to mow a meadow


Two men went to mow
Went to mow a meadow
Two men One man and his dog
Went to mow a meadow


Three men went to mow
Went to mow a meadow
Three men two men, One man and his dog
Went to mow a meadow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment