Last active
August 29, 2015 14:07
-
-
Save kmorcinek/46cab924afec59d9a19c to your computer and use it in GitHub Desktop.
F# command
This file contains hidden or 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
List.map | |
List.filter | |
type Position = | |
struct | |
val X : int | |
val Y : int | |
new(x, y) = { X = x; Y = y} | |
end | |
let sumRabbits list = | |
let rec loop list acc = | |
match list with | |
| (head:Rabbit) :: tail -> loop tail (acc + head.Food) | |
| [] -> acc | |
loop list 0.0 | |
let squared = | |
numbers | |
|> List.filter isOdd | |
|> List.map square | |
List.filter (fun n -> n%2 = 0) nums | |
// Sum a list | |
let accumulate acc x = acc + x | |
let sumList = List.fold_left accumulate 0 [1 .. 10] | |
// Notice our accumulator function is identical to the (+) operator, | |
// so we can rewrite our fold as: | |
let conciseSum = List.fold_left (+) 0 [1 .. 10] | |
let nextYears2 = { eclipse with Year = 2006 } | |
open System | |
// TIP: sets the current directory to be same as the script directory | |
System.IO.Directory.SetCurrentDirectory (__SOURCE_DIRECTORY__) | |
type MyClassBase2(x: int) = | |
let mutable z = x * x | |
do for i in 1..z do printf "%d " i | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment