Skip to content

Instantly share code, notes, and snippets.

@rommsen
Created May 30, 2018 07:12
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 rommsen/6bb735d292deefa00bf02fab5748708e to your computer and use it in GitHub Desktop.
Save rommsen/6bb735d292deefa00bf02fab5748708e to your computer and use it in GitHub Desktop.
Meetup1
// Syntax (keine Klammern, Funktionsaufrufe)
// value binding
let firstname : string = "Roman"
open System.Reflection
open System.Windows.Forms
open System.Security.Cryptography
let age : int = 37
// type inference
// reassign not working
age = 38
// mutable
let mutable alter = 27
alter <- 27
// aber das wollen wir ja nicht :D
// funktionen
let add2 x =
x + 2
// Aufruf
add2 40
let modulo3 x =
x % 3
modulo3 (add2 42)
// piping
42
|> add2
|> modulo3
|> (fun x -> x * 5)
// function composition
let add2Modulo3 =
add2 >> modulo3
42 |> add2Modulo3
// expressions
let modulo2Is0 x =
if x % 2 = 0 then
"ja"
else
"nein"
let add x y =
x + y
// currying
let add2Curry =
add 2
// Listen
let liste = [1..10]
liste
|> List.map (fun x -> x + 1)
let greater5 x =
x > 5
liste
|> List.map (fun x -> x + 1)
|> List.filter greater5
liste
|> List.map (fun x -> x + 1)
|> List.filter (not << greater5)
// Record
type Account =
{
Owner : string
Balance : decimal
}
let account =
{
Owner = "Roman"
Balance = 10M
}
let account2 =
{ account with Owner = "Lena" }
account
let withOwner owner account =
{ account with Owner = owner }
let withBalance balance account =
{ account with Balance = balance }
account
|> withBalance 20M
|> withOwner "Lena"
// DU
type Wert =
| Bube
| Dame
| König
| Ass
type Karte =
| Karo of Wert
| Herz of Wert
| Kreuz of Wert
| Pik of Wert
let welcheKarte karte =
match karte with
| Herz wert -> sprintf "Herz %A" wert
| Karo wert -> sprintf "Karo %A" wert
| Kreuz wert -> sprintf "Kreuz %A" wert
| Pik wert -> sprintf "Pik %A" wert
welcheKarte (Bube |> Karo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment