Created
December 26, 2017 19:41
-
-
Save lucansky/12e33a71edf6eeea8be365aff9fea869 to your computer and use it in GitHub Desktop.
Generic interpreter in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Data.Gerber.Interpreter where | |
import Data.Gerber.Types | |
data InterpreterState = InterpreterState | |
{ commandsParsed :: Integer } | |
deriving (Show, Eq) | |
initState = InterpreterState | |
{ commandsParsed = 0 } | |
eval :: Command -> InterpreterState -> InterpreterState | |
eval command state = | |
InterpreterState { commandsParsed = commandsParsed state + 1 } | |
evalBulk :: [Command] -> InterpreterState | |
evalBulk cmds = go cmds initState | |
where | |
go :: [Command] -> InterpreterState -> InterpreterState | |
go [] imm = imm | |
go (x) imm = eval x imm | |
go (x:xs) imm = go xs $ eval x imm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment