swh:1:snp:aeaf3dbb58f5be84b565e73b5ade1503ee8cb6d6
Raw File
Tip revision: b6407e0f026cf5491ca5ed0a35ea5cf316ebe8ca authored by Anish Tondwalkar on 21 May 2021, 03:15:25 UTC
formatted for submission
Tip revision: b6407e0
incrState.hs
-- Monadic Interface
ret as rforall a. wr:Int ~> x:a -> ST <{ri:Int|ri==wr} >{ro:Int|ro==wr} >a
ret = 0

thenn as w1:Int ~> w2:Int ~> w3:Int ~>
  (ST <{v:Int|v==w1} >{v:Int|v==w2} >Unit)
  -> (ST <{v:Int|v==w2} >{v:Int|v==w3} >Int)
  -> ST <{v:Int|v==w1} >{v:Int|v==w3} >Int
thenn = 0

bind as rforall a, b. w1:Int ~> w2:Int ~> w3:Int ~>
  (ST <{v:Int|v==w1} >{v:Int|v==w2} >a)
  -> (unused:a -> ST <{v:Int|v==w2} >{v:Int|v==w3} >b)
  -> ST <{v:Int|v==w1} >{v:Int|v==w3} >b
bind = 0

get as wg:Int ~> Bool -> ST <{gi:Int|gi==wg} >{go:Int|go==wg} >{gr:Int|gr==wg}
get = True

put as wp:Int -> ST <Int >{p:Int|p==wp} >Unit
put = 0

-- incr
incr :: i:Int ~> ST <{v:Int|i==v} >{w:Int|w==i+1} >Unit
incr = bind (get True) (\x -> put (x+1))
back to top