Skip to content

Instantly share code, notes, and snippets.

@zakky-dev
Created May 3, 2014 15:36
Show Gist options
  • Save zakky-dev/baa1f5809c6e9f95dea9 to your computer and use it in GitHub Desktop.
Save zakky-dev/baa1f5809c6e9f95dea9 to your computer and use it in GitHub Desktop.
「すごいHaskell楽しく学ぼう!」第8章165ページのサンプルコードを弄くり回した結果。書籍の「let式を使う」という目的を完全無視し、ひたすら分割する方向へ進めてしまった末路。そして文字列のフォーマットについてごねごね考えた原因。
import qualified Data.Char as C
type FirstName = String
type LastName = String
flatten :: [[a]] -> [a]
flatten [] = []
flatten (x:xs) = x ++ flatten xs
toUpper :: String -> String
toUpper = map C.toUpper
doQuestion :: String -> IO String
doQuestion s = do
putStrLn s
getLine
-- できれば文字列のフォーマット関数を使って綺麗にしたいところ......
makeGreetMessage :: FirstName -> LastName -> String
makeGreetMessage fn ln = flatten ["hey ", toUpper fn, " ", toUpper ln, ", how are you?"]
main = do
firstName <- doQuestion "What's your first name?"
lastName <- doQuestion "What's your last name?"
putStrLn $ makeGreetMessage firstName lastName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment