Skip to content

Instantly share code, notes, and snippets.

@L8D
Last active January 3, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L8D/8468416 to your computer and use it in GitHub Desktop.
Save L8D/8468416 to your computer and use it in GitHub Desktop.
BFA Assembler in Haskell
import Data.Char (isSpace)
import Data.Maybe (listToMaybe, fromMaybe)
maybeRead :: Read a => String -> Maybe a
maybeRead = fmap fst . listToMaybe . reads
parseLine :: String -> (Int, String)
parseLine = uncurry ((,) . fromMaybe 1 . maybeRead) . break isSpace
makeLine :: (Int, String) -> String
makeLine = concat . uncurry replicate
main = interact $ (++ "\n")
. filter (`elem` "+-><.,[]")
. unlines
. map (makeLine . parseLine . dropWhile isSpace)
. lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment