Execute Brain****/Haskell: Difference between revisions
Content added Content deleted
No edit summary |
(This version compiles with GHC and will run if loaded into ghci using :load BF) |
||
Line 8: | Line 8: | ||
A more efficient implementation could for example only admit well-bracketed brainfuck programs, and parse bracket blocks first, to replace the ''matchLeft'' and ''matchRight'' which need linear time. |
A more efficient implementation could for example only admit well-bracketed brainfuck programs, and parse bracket blocks first, to replace the ''matchLeft'' and ''matchRight'' which need linear time. |
||
<lang haskell> |
<lang haskell>module BF where |
||
moveLeft (x:l,r) = (l,x:r) |
|||
moveRight (l,x:r) = (x:l,r) |
moveRight (l,x:r) = (x:l,r) |
||
Line 44: | Line 46: | ||
dialog :: String -> IO () |
dialog :: String -> IO () |
||
dialog s = mapM_ print . run s . map read . lines =<< getContents |
dialog s = mapM_ print . run s . map read . lines =<< getContents |
||
</lang>(This version compiles with GHC and will run if loaded into ghci using ':load BF') |
|||
</lang> |
|||
Example session: |
Example session: |