Skip to content

Instantly share code, notes, and snippets.

@darkf
Created December 29, 2012 03:01
Show Gist options
  • Select an option

  • Save darkf/4404293 to your computer and use it in GitHub Desktop.

Select an option

Save darkf/4404293 to your computer and use it in GitHub Desktop.
My Haskell is horrible
data Tok = Op Char | NumTok Int
op '+' = (+)
op '*' = (*)
op _ = \_ _ -> 666
eval toks =
eval' toks []
where
eval' [] s = head s
eval' (NumTok x:xs) s = eval' xs (x:s)
eval' (Op x:xs) (rhs:lhs:s) =
eval' xs $ ((op x) lhs rhs):s
main = print $ eval $ [NumTok 3, NumTok 2, Op '+', NumTok 2, Op '*', NumTok 2, Op '*']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment