Skip to content

Instantly share code, notes, and snippets.

@nushio3
Last active December 15, 2015 11:29
Show Gist options
  • Save nushio3/5253230 to your computer and use it in GitHub Desktop.
Save nushio3/5253230 to your computer and use it in GitHub Desktop.

小問1

(選択肢文字列,値)のリストをとって、ユーザーに選択肢を提示し、番号を入力して選んでもらった値を返す関数

choice :: [(String, a)] -> IO a

を作ってください。

小問2

choiceを使って次のような一連の処理をするプログラムを作ってください。

  1. 苗字を聞く。
  2. 名前を聞く。
  3. ミドルネームを持っているかどうかの選択肢を提示し、ある場合は入力してもらった上で、フルネームを組み立てて表示する。

小問3

次のような愉快なゲーム記述言語っぽいものが作れるよう、choice を書き換えてみてください。

main = do
  putStrLn "どこへ行く?"
  choice [ ("宿屋" , inn)
         , ("野外" , outdoor) ]

inn = do
  putStrLn "あなたはぐっすり眠った。"
  main

outdoor = do
  putStrLn "マネジメント上の問題が現れた!!どうする?"
  choice [ ("殴る" , fight)
         , ("メラ" , magic) ]

ゲームスクリプトの全実装はこちら> https://gist.github.com/nushio3/5253576

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