Skip to content

Instantly share code, notes, and snippets.

@carljparker
Last active September 27, 2015 18:38
Show Gist options
  • Save carljparker/1314135 to your computer and use it in GitHub Desktop.
Save carljparker/1314135 to your computer and use it in GitHub Desktop.
F# Sample Code
//
// Learn more about F# at http://fsharp.net
//
open System;
open System.IO;
printfn "\n";
let cjpL = [1; 2; 3; 4; 5; 6; 7; 8];
// Console.WriteLine "{0}" cjpL;
printfn "%A" cjpL;
//
// 1
//
printfn "%d" ( List.head cjpL )
//
// [2; 3; 4; 5; 6; 7; 8]
//
printfn "%A" ( List.tail cjpL )
let fstl l =
List.head l
let sndl l =
List.head <| List.tail l
let trdl l =
List.head <| ( List.tail <| List.tail l )
//
// 1
//
printfn "%d" ( fstl cjpL )
//
// 2
//
printfn "%d" ( sndl cjpL )
//
// 3
//
printfn "%d" ( trdl cjpL )
printfn "\n+++++++++++++++ reverse ++++++++++++++++++\n"
cjpL |> List.rev |> printfn "%A"
printfn "\n"
let cjpL_2 = 9 :: List.rev cjpL |> List.rev;
printfn "%A" cjpL_2;
printfn "\n+++++++++++++++ filter ++++++++++++++++++\n"
List.filter ( fun x -> ( x % 2 = 1 ) ) cjpL |> printfn "%A";
printfn "\n+++++++++++++++ map ++++++++++++++++++++\n"
let cjpL_3 = List.map (fun x -> x * x ) cjpL_2;
printfn "%A" cjpL_3;
printfn "\n+++++++++++ reduce ( x + y ) ++++++++++++++++\n"
List.reduce ( fun x y -> x + y ) cjpL |> printfn "%d";
printfn "\n+++++++++++ reduce ( x ** y ) ++++++++++++++++\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment