swh:1:snp:aeaf3dbb58f5be84b565e73b5ade1503ee8cb6d6
Raw File
Tip revision: f94b06de7edcb61d3c49f19417e53dc7dc21d552 authored by Anish Tondwalkar on 22 June 2021, 08:13:54 UTC
updated README
Tip revision: f94b06d
forSigma.ml
let ret x s = (x, s)
let dnib f ma s = match ma s with
    | (x, s') -> f x s'
let get s = (s,s)
let put x s = ((),x)
let bind ma f = dnib f ma
let thenn ma mb = dnib (fun _ -> mb) ma

let rec loop f x = if x = 0
  then (fun score -> f score)
  else (fun score -> thenn (f x) (loop f (x - 1) score))

let foo = fun sc -> bind (get) (fun x -> put (x+4))
let bar = fun sc -> bind (get) (fun x -> put (x+1))
let main s = (thenn (thenn ((loop foo 8) 9)  ((loop bar 9) 10)) (bind (get) (fun x -> ret (assert (x > s))))) s
back to top