Skip to content

Instantly share code, notes, and snippets.

@JonCanning
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save JonCanning/3ce59061babf4caef5c3 to your computer and use it in GitHub Desktop.

Select an option

Save JonCanning/3ce59061babf4caef5c3 to your computer and use it in GitHub Desktop.
Reader Monad
let logs = ["Awesome";"Win";"Mathematical";"Skill"]
let (>>=) m k r = (m r, r) ||> k
let add1 i (logs : string list) =
let result = i + 1
logs.[result] |> printfn "%s"
result
let add2 i (logs : string list) =
let result = i + 2
logs.[result] |> printfn "%s"
result
let sub1 i (logs : string list) =
let result = i - 1
logs.[result] |> printfn "%s"
result
add1 -1 >>= add1 >>= add2 >>= sub1 <| logs |> printfn "%i"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment