[Haskell-cafe] State & nested structures

Stephen Tetley stephen.tetley at gmail.com
Fri Oct 29 11:35:09 EDT 2010


2010/10/29 Dupont Corentin <corentin.dupont at gmail.com>:

> Also, I can't manage to write the more generic function SB x ->  SA x.
>

Horribly enough this one seems to work...

mapOnBofA :: SB a -> SA a
mapOnBofA mf = get >>= \st@(A {b=temp}) ->
               let (ans,temp2) = runState mf temp
               in put (st { b=temp2}) >> return ans

However, I'd have to question why you want both SA and SB as state
functional types. Having inner runState's is sometimes good practice
(its an instance of the Local Effect pattern identified by Ralf
Laemmel and Joost Visser), but if you have it "commonly" I'd suspect
you design is somehow contrived and could be simplified.


More information about the Haskell-Cafe mailing list