Skip to content

Instantly share code, notes, and snippets.

@mollyporph
Last active August 29, 2015 14:24
Show Gist options
  • Save mollyporph/7300ce778caf06af5d30 to your computer and use it in GitHub Desktop.
Save mollyporph/7300ce778caf06af5d30 to your computer and use it in GitHub Desktop.
type Vechicle =
| Animal of LegCount :int * BaseSpeed : int
| Car of Automatic : bool * BaseSpeed : int
let Speed vechicle =
let GetCarSpeed automatic baseSpeed =
if automatic then
baseSpeed*2
else
baseSpeed
match vechicle with
| Animal(legCount,baseSpeed) -> legCount*baseSpeed
| Car(automatic,baseSpeed) -> GetCarSpeed automatic baseSpeed
let ConsoleEnd() =
System.Console.ReadKey() |> ignore
0
[<EntryPoint>]
let main argv =
let nissan = Car(true, 40)
let vw = Car(false,71)
let pug = Animal(4,4);
let kangaroo = Animal(2,20)
let vehicleList = [nissan;vw;pug;kangaroo];
let speeds = vehicleList |> List.map(fun x -> Speed x)
printfn "%A" speeds
ConsoleEnd()
/*
Outputs [80; 71; 16; 40]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment