Haskell State Accessors (second attempt: Composability)

Last week I introduced some constructs to make programming games with Haskell easier, mostly the idea of an accessor for dealing nicely with highly stateful functions. The (refined once) abstraction looked like this:

And then given the Accessor abstraction you could do stuff like define a := operator for readability and whatnot. I was proud that you could write accessors that accessed things other than the top level of the data structure.

But something still wasn’t right. I wanted to be able to do something like a.b.c in OO langauges, where a, b, and c were accessors. So here is my new Accessor abstraction:

The idea is that an Accessor is an object which accesses a value of type a as a function of a value of type s (I call it s for state, the typical value). But it no longer has anything to do with a monad, it’s an abstraction simply for extracting data from other data. The new signature is: