-
Notifications
You must be signed in to change notification settings - Fork 5
/
examples.fsx
64 lines (47 loc) · 2.08 KB
/
examples.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#load "src\FsPad\FsPad.fsx"
open FsPad
open System
///////////////////////////////////////
// Examples
///////////////////////////////////////
// Single value
dump 13
// Text is Html Encoded
dump "<b>Hello World</b>"
// A list of values
dump [ 1 .. 30 ]
// A tuple
dump ( ("By Plane", 2, 250.99) )
// A list of tuples (notice how it changes the layout, to tabular)
dump [ ("By Plane", 2, 250.99); ("By Car", 10, 210.5); ("By Train", 15, 483.53) ]
// A record
type Person = { firstName : string ; lastName : string; age : int; address : string }
dump { firstName = "Gustavo"; lastName = "Leon"; age = 43 ; address = "Dole" }
// A list of records (again changes to tabular)
dump
[
{firstName = "Gustavo"; lastName = "Leon" ; age = 43 ; address = "Dole" }
{firstName = "Steve" ; lastName = "Goguen"; age = 20 ; address = "?" }
]
// Nested stuff
type Dev = { firstName : string ; lastName : string ; age : int; address : string ; projects : string list }
dump {firstName = "Gustavo"; lastName = "Leon"; age = 43 ; address = "Dole" ; projects = ["F#+"; "ScrapeM" ]}
dump
[
{firstName = "Gustavo"; lastName = "Leon" ; age = 43 ; address = "Dole" ; projects = ["F#+"; "ScrapeM" ; "FsPad" ]}
{firstName = "Steve" ; lastName = "Goguen"; age = 20 ; address = "?" ; projects = ["Steego.NET"; "FsPad" ]}
]
//// Recursively Defined Object
//type Tree<'a>(value:'a, getEdges:'a -> seq<'a>) =
// let list = lazy [ for e in getEdges(value) -> Tree(e, getEdges) ]
// member this.Value = value
// member this.Children = list.Value
//let tree1 = Tree(Some 1, fun (Some x) -> seq { for x in x..2 -> Some x })
//dump (tree1, 9)
// List of option
[Some 1; None; Some 4] |> dump
// List of tuples, some of them are options
[1..30] |> List.map (fun x -> ( (if x % 2 = 0 then Some x else None), x, if x % 3 = 0 then Some x else None) ) |> dump
// List of record, some fields are options
type Tab<'a,'b,'c> = { a : 'a ; b : 'b ; c : 'c }
[1..30] |> List.map (fun x -> {a = (if x % 2 = 0 then Some x else None); b = x; c = if x % 3 = 0 then Some x else None} ) |> dump