Re: get and set

Krasimir Angelov <[email protected]>
Newsgroups gmane.comp.lang.haskell.gui
Message-ID <[email protected]>
    The getter and setter abstractions are really more
universal concept than Attr in GIO and StateVariable
in HOpenGL. The get and set functions are not limited
to IO monad and can be implemented for many others
monad types. Unfortunately proper implementation
requires functional dependencies. The attached module
contains definitions for get and set functions for IO,
ST, Reader, ReaderT, State, StateT, RWS and RWST
monads. The idea is that each monad can maintains some
kind of state and the corresponding Attr type gives
access to some part of the state. The good example is
the StateAttr with State monad. 

Example:


data Point = Point {x :: Int, y :: Int}

attrX :: StateAttr Point Int
attrX = StateAttr x (\v p -> p{x=v})

attrY :: StateAttr Point Int
attrY = StateAttr y (\v p -> p{y=v})

move :: Int -> Int -> State Point Int
move vx vy = do
   x <- get attrX
   attrX =: x+vx
   y <- get attrY
   attrY =: y+vy

I propose to standardize this concept and add Attr
module to the GHC base package.

Cheers,
Krasimir

__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com
Attr.hs (application/octet-stream, 4.2 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.