Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/tests/nofib/real/infer/State.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module State (State, returnS, eachS, thenS, putS, getS, useS) where

data  State s x       =   Abs (s -> (x, s))
rep                   ::  State s x -> (s -> (x,s))
rep (Abs f)           =   f
returnS               ::  x -> State s x
returnS x             =   Abs (\s -> (x, s))
eachS                 ::  State s x -> (x -> y) -> State s y
xS `eachS` f          =   Abs (\s -> let (x,s') = rep xS s in (f x, s'))
thenS                 ::  State s x -> (x -> State s y) -> State s y
xS `thenS` kS         =   Abs (\s -> let (x,s') = rep xS s in rep (kS x) s')
putS                  ::  s -> State s ()
putS s'               =   Abs (\s -> ((), s'))
getS                  ::  State s s
getS                  =   Abs (\s -> (s,s))
useS                  ::  State s x -> s -> x
useS xS s             =   let (x,s') = rep xS s in  x

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].