Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.12 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.net
  2. // See the 'F# Tutorial' project for more help.
  3.  
  4. type Price =
  5.     | Empty
  6.     | Value of double
  7.     | ValueChildren of double * Price list
  8.     with
  9.     static member private apply applyAction (lhs, rhs) =
  10.         match lhs, rhs with
  11.         | Empty, Empty -> Empty
  12.         | Empty, Value x
  13.         | Value x, Empty -> Value x
  14.         | Empty, ValueChildren (x, c)
  15.         | ValueChildren (x, c), Empty -> ValueChildren (x, c)
  16.  
  17.         | Value x, Value y
  18.         | Value x, ValueChildren (y, _)
  19.         | ValueChildren (x, _), Value y
  20.         | ValueChildren (x, _), ValueChildren (y, _) -> ValueChildren (applyAction x y, [lhs; rhs])
  21.  
  22.     static member (+) (lhs, rhs) =
  23.         Price.apply (+) (lhs, rhs)
  24.     static member (-) (lhs, rhs) =
  25.         Price.apply (-) (lhs, rhs)
  26.     static member (*) (lhs, rhs) =
  27.         Price.apply (*) (lhs, rhs)
  28.     static member (/) (lhs, rhs) =
  29.         Price.apply (/) (lhs, rhs)
  30.  
  31.  
  32. [<EntryPoint>]
  33. let main argv =
  34.     let a = Price.Value 1.3
  35.     let b = Price.Value 23.3
  36.     let c = a * b
  37.  
  38.     printfn "%A" argv
  39.     0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement