Execute HQ9+/Haskell
Execute HQ9+/Haskell is an implementation of HQ9+.
Other implementations of HQ9+.
Execute HQ9+/Haskell is part of RCHQ9+. You may find other members of RCHQ9+ at Category:RCHQ9+.
This HQ9+ interpreter is written in Haskell. <lang haskell>import Char (toLower, toUpper)
main = interact hq9p
hq9p :: String -> String hq9p source = concatMap run $ map toLower source
where run 'h' = "Hello, world!\n" run 'q' = source run '9' = bottles run _ = "" -- Obviously, the final case works just fine for '+'.
bottles :: String bottles = concat
[up (bob n) ++ wall ++ ", " ++ bob n ++ ".\n" ++ pass n ++ bob (n - 1) ++ wall ++ ".\n\n" | n <- [99, 98 .. 0]] where bob n = num n ++ " bottle" ++ s n ++ " of beer" wall = " on the wall" pass 0 = "Go to the store and buy some more, " pass _ = "Take one down and pass it around, " up (x : xs) = toUpper x : xs num (-1) = "99" num 0 = "no more" num n = show n s 1 = "" s _ = "s"</lang>