Created
March 27, 2017 05:00
-
-
Save rmunn/6e949b29543b9a7a45f9057e173b195b to your computer and use it in GitHub Desktop.
F# snippets from the http://insights.dice.com/2017/03/20/examining-f-programming-language post, with indentation restored
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
First snippet: | |
let rec fib = seq { | |
yield! [0; 1] | |
yield! fib | |
|> Seq.pairwise | |
|> Seq.map (fun (prev, next) -> prev + next) | |
} | |
Second snippet: | |
let num = 12 | |
let squareIt n = n * n | |
let mixedTuple = ( num, "two", 3.3, squareIt ) | |
Third snippet: | |
let rec quicksort = function | |
| [] -> [] | |
| first::rest -> | |
let smaller,larger = List.partition ((>=) first) rest | |
List.concat [quicksort smaller; [first]; quicksort larger] | |
Fourth snippet: | |
[<Measure>] type inch | |
[<Measure>] type foot | |
let convertInchtoFeet ( length : float<inch> ) = length / 12.0<inch> * 1.0<foot> . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment