<Query Kind="FSharpProgram" />

let h t = t+1
let g t = [t+1]
let f t = [t; t+1]

// ---

let unit t = [t]

// ---

let map h m = // List.map h m
    // [ for t in m do yield h t ]
    let mutable r = []
    for t in m do
        r <- r @ [h t]
    r

let xh = map h [3; 7]
printfn "xh: %A" xh

let xg = map g [3; 7]
printfn "xg: %A" xg

let xf = map f [3; 7]
printfn "xf: %A" xf

// ---
printfn ""

let bind f m = // List.collect f m
//    [for t in m do
//        for u in f t do yield u]
    let mutable r = []
    for t in m do
        for u in f t do
            r <- r @ [u]
    r

let yg = bind g [3; 7]
printfn "yg: %A" yg

let yf = bind f [3; 7]
printfn "yf: %A" yf

// ---
printfn ""

let flat m2 = // List.concat m2
//    [for m in m2 do
//        for u in m do yield u]
    let mutable r = []
    for m in m2 do
        for u in m do
            r <- r @ [u]
    r

let zg = flat [[4]; [8]]
printfn "zg: %A" zg

let zf = flat [[3; 4]; [7; 8]]
printfn "zf: %A" zf

// ---