CodePlexProject Hosting for Open Source Software
Basic Discriminated Unions
type wheel = Wheel of float // radius of wheel, inchestype cycle = | Unicycle of wheel | Bicycle of wheel * wheel let veryBigWheel = Wheel(26.0)let bigWheel = Wheel(13.0)let smallWheel = Wheel(6.0)let pennyFarthing = Bicycle(veryBigWheel, smallWheel)let racer = Bicycle(bigWheel, bigWheel)let kidsBike = Bicycle(smallWheel, smallWheel)let UnionSample1() = let show bike = match bike with | Unicycle (Wheel r) -> printfn "Unicycle, one wheel, radius = %f" r | Bicycle (Wheel r1,Wheel r2) -> printfn "Bicycle, two wheels, front = %f, back = %f" r1 r2 show pennyFarthing; show racer; show kidsBike
Bicycle, two wheels, front = 26.000000, back = 6.000000Bicycle, two wheels, front = 13.000000, back = 13.000000Bicycle, two wheels, front = 6.000000, back = 6.000000
Last edited Sep 14, 2011 at 2:57 AM by ttliu2000, version 1
There is no recommended release for this project.