LoginSignup
13
11

More than 5 years have passed since last update.

ズンドコキヨシ with Haskell

Last updated at Posted at 2016-03-11

ズンドコキヨシ with Perl6
をHaskellでやってみました。もうちょっと短くなるような気もします。

import           Control.Monad
import           System.Random

data Sound = Z | D | K deriving (Eq, Ord, Show)

main :: IO ()
main = genSound >>= go [] >> putStr "\n"
 where
   go (D:Z:Z:Z:Z:_) _ = putStr (showZDK K)
   go xs x            = putStr (showZDK x) >> genSound >>= go (x:xs)

genSound :: IO Sound
genSound = (!!) [Z,D] <$> getStdRandom (randomR (0,1))

showZDK :: Sound -> String
showZDK Z = "ズン"
showZDK D = "ドコ"
showZDK K = "キ・ヨ・シ!"

ところでズンドコキヨシって何?

13
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
11