[Haskell-cafe] Extensible states

Roman Cheplyaka roma at ro-che.info
Tue May 5 09:50:26 UTC 2015


On 05/05/15 12:40, Alberto G. Corona  wrote:
> Hi,
> 
> Anyone used some of the extensible record packages to create a kind of
> extensible state monad?
> 
> I mean something that besides having "get", "gets" and "put"  would have
> some kind of "add" and "gets":
> 
> add :: a -> State ()
> gets  :: State (Maybe a)
> 
> or 
> 
> add :: LabelName -> a -> State ()
> gets :: LabelName -> State (Maybe a)
> 
> 
> So that I can extend the state without using additional monad
> transformers. Monad transformers are very hard for beginners and
> scramble error messages
> 
> I did the first option for MFlow, hplayground and Transient packages
> (setSData and getSData). But my solution uses a map indexed by type and
> this requires a lookup for each access.
> 
> I would like to know if there is an alternative with no lookups. I´m not
> obsessed with speed but In some applications the speed may be important....
> 
> Anyone?


If you care about the error message quality, you'd rather stay away from
extensible records.

And if you care about speed, most (all?) extensible records give you
O(n) access, so you'd be actually better off with a simple (Hash)Map.

Roman

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150505/49ea34f9/attachment.sig>


More information about the Haskell-Cafe mailing list