Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.net
- // See the 'F# Tutorial' project for more help.
- type Price =
- | Empty
- | Value of double
- | ValueChildren of double * Price list
- with
- static member private apply applyAction (lhs, rhs) =
- match lhs, rhs with
- | Empty, Empty -> Empty
- | Empty, Value x
- | Value x, Empty -> Value x
- | Empty, ValueChildren (x, c)
- | ValueChildren (x, c), Empty -> ValueChildren (x, c)
- | Value x, Value y
- | Value x, ValueChildren (y, _)
- | ValueChildren (x, _), Value y
- | ValueChildren (x, _), ValueChildren (y, _) -> ValueChildren (applyAction x y, [lhs; rhs])
- static member (+) (lhs, rhs) =
- Price.apply (+) (lhs, rhs)
- static member (-) (lhs, rhs) =
- Price.apply (-) (lhs, rhs)
- static member (*) (lhs, rhs) =
- Price.apply (*) (lhs, rhs)
- static member (/) (lhs, rhs) =
- Price.apply (/) (lhs, rhs)
- [<EntryPoint>]
- let main argv =
- let a = Price.Value 1.3
- let b = Price.Value 23.3
- let c = a * b
- printfn "%A" argv
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement