<link href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css" type="text/css" rel="stylesheet" />and also modified the "body" tag like this:
<script type="text/javascript" src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"> </script>
<script type="text/javascript" src="http://google-code-prettify.googlecode.com/svn/trunk/src/lang-hs.js"> </script>
<body onload='prettyPrint()'>and voila, it's possible, to get syntax highlighting by using the "pre" tag with the attribute "prettyprint lang-html" or "prettyprint lang-hs" or ... !
Note: you may need to clean the HTML parenthesis with this tool: Simplecode.pl
{-# LANGUAGE GADTs, FlexibleInstances #-}
module StackMachineMonad where
-- Representation
type Program instr = [instr]
type StackProgram = Program StackInstruction
data StackInstruction = Push Int | Pop
-- Concatenation and interface
empty = []
pop :: StackProgram
push :: Int -> StackProgram
pop = Pop : []
push n = Push n : []
-- Interpreter
type Stack a = [a]
interpret :: StackProgram -> (Stack Int -> Stack Int)
interpret (Push a : is) stack = interpret is (a : stack)
interpret (Pop : is) stack = interpret is (tail stack)
interpret [] stack = stack
-- Examples, try for instance
-- > interpret example []
-- > interpret (replace 5) [3]
example = Push 5 : Push 42 : Pop : []
exampleTwice = example ++ example
replace a = pop ++ push a
No comments:
Post a Comment