Anonymous user
Execute HQ9+/Haskell: Difference between revisions
Added the case to deal with the increment instruction, and removed the notice
(does not work fine for '+') |
(Added the case to deal with the increment instruction, and removed the notice) |
||
Line 1:
{{implementation|HQ9+}}{{collection|RCHQ9+}}
This [[HQ9+]] interpreter is written in [[Haskell]].
We use [https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Traversable.html#v:mapAccumR mapAccumR] to maintain the accumulator.
However, the specification doesn't say what to do with said accumulator on completion.
<lang haskell>import Char (toLower, toUpper)▼
<lang haskell>module Main where
import Data.List -- for concat
import Data.Traversable -- for mapAccumR
main = do
hq9p source = concatMap run $ map toLower source▼
s <- getLine
where run 'h' = "Hello, world!\n"▼
putStrLn (snd (hq9p s))
run '9' = bottles▼
hq9p :: String -> (Int,String)
run _ = ""▼
where
fin (acc,log) = (acc,concat log)
run acc ch = case ch of
'q' -> (acc,src)
bottles :: String
bottles =
where
beers n = unlines [
bob n
bob
let nu
in nu
pass n = case
0 ->
_ ->
▲ s 1 = ""
|