[Haskell-cafe] ODP: Extensible states

Marcin Mrotek marcin.jan.mrotek at gmail.com
Wed May 6 12:14:18 UTC 2015

I think that the whole point of extensible records is to change the type on appending, to provide more safety at compile time than (hash) maps. If you don't want to use lenses (zoom) to combine different state monads, I guess a map is the best option.

Kind regards,
Marcin Mrotek

-----Wiadomość oryginalna-----
Od: "Alberto G. Corona " <agocorona at gmail.com>
Wysłano: ‎2015-‎05-‎05 23:03
Do: "Marcin Mrotek" <marcin.jan.mrotek at gmail.com>
DW: "adam vogt" <vogt.adam at gmail.com>; "haskell-cafe" <haskell-cafe at haskell.org>
Temat: Re: [Haskell-cafe] Extensible states

Thanks all of you.

So there is no trick that can make extensible records O(1) for field access, like the native haskell records?. I didn´t know that all the extensible records have  O(n) or O(log n) at most.

That is not better than my State monad with a Data.Map.  It is not possible to use HList-like records like the one that Adam mentioned since the type signature must not change when a new field is added.

2015-05-05 22:20 GMT+02:00 Marcin Mrotek <marcin.jan.mrotek at gmail.com>:


I'm not sure if this is what you're looking for, but vinyl + lens state monad combinators let you write something like this:

foo :: State (Rec Foo [B,C,F]) Bar
foo = ...

bar = State (Rec Foo [A,B,C,D,E,F]
bar = do
   x <- zoom rsubset foo
   rlens SA .= 3

Unfortunately Vinyl has O(n) lookup (unless it gets optimized away by sufficiently glorious haskell compiler, I guess, but I have no idea whether it actually can happen). But I'm not sure if the speed impact is noticeable, compared to using monad transformer stacks, for example.





Best regards,
Marcin Mrotek

Haskell-Cafe mailing list
Haskell-Cafe at haskell.org


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150506/bf52a2b0/attachment.html>

More information about the Haskell-Cafe mailing list