Reto Kramer wrote:
> What I'm really looking for is not so much the chaining of StateT  
> compositions, but rather the isolation of StateA from StateB while  
> they both flow from the search loop into the respective library calls  
> (foo, bar) transparently to the application programmer.

How about this?

-- these two should be defined in two separate library modules, of course
trueFoo :: MonadState StateA m => m ()
trueBar :: MonadState StateB m => m ()

data AppStateRec = AppStateRec { a :: StateA, b :: StateB }

type Eval a = StateT AppStateRec Identity a

exec :: Eval ()
exec = do foo
          bar
          foo
          foo
          bar
  where
    -- you might want to define combinators for the following pattern,
    -- but for just two functions this is good enough
    foo = do AppStateRec a b <- get
             a' <- runStateT trueFoo a
             put $ AppStateRec a' b
    bar = do AppStateRec a b <- get
             b' <- runStateT trueBar b
             put $ AppStateRec a b'


-Udo
-- 
"In the software business there are many enterprises for which it is not
clear that science can help them; that science should try is not clear
either."
        -- E. W. Dijkstra

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to