Created
July 22, 2016 19:48
-
-
Save davenportw15/130983a9616f20076cb3c1708c005431 to your computer and use it in GitHub Desktop.
An F# FP example
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
open System | |
type Point = { x : double; y : double } | |
let distance (start : Point) (finish : Point) : double = | |
let x = finish.x - start.x | |
let y = finish.y - start.y | |
sqrt (x * x + y * y) | |
[<EntryPoint>] | |
let main argv = | |
let p1 = { x = 0.0; y = 0.0 } | |
let p2 = { x = 3.0; y = 4.0 } | |
distance p1 p2 |> printfn "%f" | |
printfn "" | |
let points = [ | |
{ x = 0.0; y = 4.0 }; | |
{ x = 3.0; y = 4.0 }; | |
{ x = 5.0; y = 12.0 } | |
] | |
let origin = { x = 0.0; y = 0.0 } | |
let distancesFromOrigin = points |> Seq.map (distance origin) | |
for d in distancesFromOrigin do | |
printfn "%f" d | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment