Difference between revisions of "Talk:Haskell Quiz/Bytecode Compiler/Solution Justin Bailey"

From HaskellWiki
Jump to: navigation, search
(comment)
 
m (typo)
 
Line 7: Line 7:
 
| op == Pow = eval left ^ eval right
 
| op == Pow = eval left ^ eval right
 
| op == Mod = eval left `mod` eval right
 
| op == Mod = eval left `mod` eval right
<haskell>
+
</haskell>
   
 
Maybe better written as:
 
Maybe better written as:
Line 19: Line 19:
 
f Pow = (^)
 
f Pow = (^)
 
f Mod = mod
 
f Mod = mod
<haskell></haskell>
+
</haskell>

Latest revision as of 10:53, 4 November 2006

eval (Statement op left right)
        | op == Mult = eval left * eval right
        | op == Minus = eval left - eval right
        | op == Plus = eval left + eval right
        | op == Div = eval left `div` eval right
        | op == Pow = eval left ^ eval right
        | op == Mod = eval left `mod` eval right

Maybe better written as:

eval (Statement op left right) = eval left `f` eval right
    where f Mult  = (*)
          f Minus = (-)
          f Plus  = (+)
          f Div   = div
          f Pow   = (^)
          f Mod   = mod