Advertisement
Guest User

3.8

a guest
Mar 3rd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.71 KB | None | 0 0
  1. type Instruction = | ADD | SUB | MULT | DIV | SIN | COS | LOG | EXP | PUSH of float;;
  2.  
  3. type stack = List<float>
  4.    
  5. exception EmptyStack
  6.  
  7. let intpInstr (s:stack) (i:Instruction)  : stack =
  8.     match (i, s) with
  9.         | ADD, x :: y :: s'     ->  (x + y) :: s'
  10.         | SUB, x :: y :: s'     ->  (x - y) :: s'
  11.         | MULT, x :: y :: s'    ->  (x * y) :: s'
  12.         | DIV, x :: y :: s'     ->  (x / y) :: s'
  13.         | SIN, x :: s'          ->  sin (x) :: s'
  14.         | COS, x :: s'          ->  cos (x) :: s'
  15.         | LOG, x :: s'          ->  log (x) :: s'
  16.         | EXP, x :: s'          ->  exp (x) :: s'
  17.         | PUSH x, _             ->  x :: s
  18.         | _                     ->  raise EmptyStack;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement