Ticket #506 (new enhancement)

Opened 11 years ago

Get and put

Reported by: Sgeo Owned by: toups
Priority: major Milestone:
Component: toups/functional.plt Keywords:
Cc: Version: (1 1)
Racket Version:


I think it would make sense to include get, put, and modify for the state monad, or perhaps call them state-get state-put state-modify. Could also make state-put and state-modify not return useful values, but not sure if there's a reason to do that.

(define state-get
  (lambda (state)
    (state-doublet state state)))

(define (state-put new-state)
  (lambda (old-state)
    (state-doublet new-state new-state)))

(define (state-modify modifier)
  (lambda (old-state)
    (define result (modifier old-state))
    (state-doublet result result)))
Note: See TracTickets for help on using tickets.