Skip to content

Instantly share code, notes, and snippets.

@Glorp
Created October 23, 2018 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glorp/3af96a5c81ee7d436c371dfa2f938e83 to your computer and use it in GitHub Desktop.
Save Glorp/3af96a5c81ee7d436c371dfa2f938e83 to your computer and use it in GitHub Desktop.
type KuEgenskaper =
{ navn : string
hoyde : int
}
type Animal =
| Coo of KuEgenskaper
| Hest of int
| Bamse
let coo = Coo { navn = "Dagros"; hoyde = 4 }
let dyrFunksjon v =
match v with
| Coo { navn = "Dagros"; hoyde = g } -> g + 1
| Coo { hoyde = g } -> g
| Hest z -> z
| Bamse -> 7
let t = (1, 2)
match t with
| (x, _) -> x
let bla q =
let (r, s) = q
r + s
bla t
snd t
coo
dyrFunksjon (Coo {navn = "Benny"; hoyde = 4})
let antallBen x =
match x with
| Coo _ -> 4
| Hest y -> y
| Bamse -> 3
antallBen Bamse
let egenskaper = [{ navn = "Dagros"; hoyde = 4 }; { navn = "Solros"; hoyde = 5 }]
List.map Coo egenskaper
Hest 4 = Hest 4
Bamse
type Foo = A | B | C
type X = int
let y : X = 3
let foo (d : int) = d + 1
type Y = Y of int
type Bar = { x : Foo; y : Foo }
type Quux = Enten of Foo | Eller of Foo
Enten A
Enten B
Enten C
Eller A
Eller B
Eller C
let x = { navn = "Dagros"; hoyde = 5}
match x with
| { navn = y; hoyde = z } -> y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment