Last active
August 29, 2015 14:24
-
-
Save mollyporph/7300ce778caf06af5d30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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