let eqDoge = doge = ("Chien", "Doge", 5)
//val doge : string * string * int = ("Chien", "Doge", 5)  

type Animal = { Espece : string ; Nom : string ; Age : int } 
let doge = { Espece = "Chien"; Nom = "Doge"; Age = 5}

type animalType = |Chien |Chat |Autre //discriminated union
type animal = {Espece : animalType; Nom : string; Age : int } //record
let doge = {Espece = Chien; Nom = "Doge"; Age = 5}

type Arbre =
        | Feuille of int
        | Noeud of int * Arbre * Arbre  
let monArbre = Noeud(1, 
                    Noeud(2,
                            Noeud(4,
                                Feuille(6),
                                Feuille(7)),
                            Feuille(4)),
                    Feuille(3))

let premiers = [3; 5; 7]
//val premiers : int list = [3; 5; 7]

let premiersEtUn = 1::premiers
//val premiersEtUn : int list = [1; 3; 5; 7]

let entiersPairs = 
            seq{
                for i in [1..2..10] do
                    yield i 
            }
//val entiersPairs : seq<int>

let auCarre x = x * x
//val auCarre : x:int -> int 

let estPair y = y % 2 = 0
//val estPair : y:int -> bool

let leCarreEstPair = auCarre >> estPair
//val leCarreEstPair : (int -> bool) 

let leCarreEstPair12 = estPair(auCarre(12))
let leCarreEstPair12' = 12 |> auCarre |> estPair

// le format "%+d" ajoute le signe + ou - 
printfn "%+d" -3
printfn "%+d" 9
// affiche : -3 +9

let afficheEntier = printf "%+d "
//val afficheEntier : (int -> unit)

afficheEntier -3
afficheEntier 9
// affiche : -3 +9

let (|%) valeur pourcentage = valeur * (1.0 - pourcentage/100.0)
//val ( |% ) : valeur:float -> pourcentage:float -> float

let prixArticle = 50.99
let remise = 80.0 // dernière démarque
let prixEnSolde = prixArticle |% remise
//val prixEnSolde : float = 10.198

let doge = {Espece = Chien; Nom = "Doge"; Age = 5}
let lol = {Espece = Chat; Nom = "Lol"; Age = 2}
let flipper = {Espece = Autre; Nom = "Flipper"; Age = 15}
let caractereAnimal animal =
    match animal with
    | {Espece = Chien} -> "Sympa"
    | {Espece = Chat} -> "Mignon"
    | {Espece = Autre} -> "Indéfini" 
//val caractereAnimal : animal:animal -> string 

let caractereDoge = caractereAnimal doge
let caractereGrumpy = caractereAnimal grumpy
let caractereFlipper = caractereAnimal flipper

//val caractereDoge : string = "Sympa"
//val caractereGrumpy : string = "Mignon"
//val caractereFlipper : string = "Indéfini"

let villeTuple = ("San Francisco", 800000, 600)
let (nomVille, habitants, superficie) = villeTuple
//val villeTuple : string * int * int = ("San Francisco", 800000, 600)
//val superficie : int = 600
//val nomVille : string = "San Francisco"
//val habitants : int = 800000

type LangagesType = XmlProvider<"""<langage nom="un langage" paradigme="un paradigme"/>""">
let langage = LangagesType.Parse("""<langage nom="F#" paradigme="Fonctionnel"/>""")    
printf "%s est un langage %s" langage.Nom langage.Paradigme

[<Measure>] type Habitant
[<Measure>] type Km

let villeTuple = ("San Francisco", 800000<Habitant>, 600<Km^2>)
let (nomVille, habitants, superficie) = villeTuple
let densite = habitants/superficie
//val densite : int<Habitant/Km ^ 2> = 1333

//ne compile pas
let mauvaisCalcul = habitants + superficie

let telecharger url = 
    async{
        do! Async.Sleep 1000 // asynchrone 
        let webClient = new WebClient() // synchrone
        let! html = webClient.AsyncDownloadString(new Uri(url)) // asynchrone
        return html
    } 
let sites = ["http://fsharp.org";
            "http://www.tryfsharp.org";
            "https://github.com/fsharp/"]

let superContenu = 
        sites
        |> List.map telecharger
        |> Async.Parallel
        |> Async.RunSynchronously

let unAcinq = seq { for i in 1..5 do yield i }
let sixAdix = seq{ for i in 6..10 do yield i }

let unAdix = 
        seq{ 
            yield! unAcinq
            yield! sixAdix
        } 

let pairs = [1..100]
            |> List.filter (fun i -> i%2 = 0 )
            |> List.map (fun i -> i.ToString() )
            |> List.reduce (fun i s -> i+","+s )
//val pairs : string = "2,4,6,8,10,12,14,16...

var pairsQ = from i in Enumerable.Range(1, 100)
             where i % 2 == 0
             select i.ToString();

var pairs = pairsQ.Aggregate((i, s) => i + "," + s);
Ou
var pairs = Enumerable.Range(1, 100)
                .Where(i => i % 2 == 0)
                .Select(i => i.ToString())
                .Aggregate((i, s) => i + "," + s);