create a record with all record accessors

16 Feb
2014
16 Feb
'14
3:05 p.m.
I have records of type (f a) where all fields are of type "a". I want to create records that contain all field getters as elements. I can do this generically: getters :: (Traversable f, Applicative f) => f (f a -> a) getters = fmap (\n x -> Fold.toList x !! n) $ MS.evalState (Trav.sequenceA (pure (MS.state $ \n -> (n, succ n)))) 0 Applicative is only needed for "pure". That is, "Pointed f" would be enough. However, (!!) is not total and not very efficient. Is there already a type class in a package with "getters" as method or something I can build an efficient "getters" from? I suspect the answer lies in one of the "lens" modules. :-)
4113
Age (days ago)
4113
Last active (days ago)
0 comments
1 participants
participants (1)
-
Henning Thielemann