agrafix / superrecord

Haskell: Supercharged anonymous records
BSD 3-Clause "New" or "Revised" License
83 stars 16 forks source link

Generalize RecApply + associated refactors #30

Closed sheaf closed 3 years ago

sheaf commented 3 years ago
sheaf commented 3 years ago

Thanks; I'm still in the process of figuring out how to use the library.

I just added a constrained traversal as I found that very useful with the generic-lens library. In this case it gives a way of traversing the fields of a record with a type-changing update:

traverseC
  :: ( TraversalC c as bs, Applicative f )
  => ( forall (l :: Symbol) a b. (KnownSymbol l, c l a b) => FldProxy l -> a -> f b )
  -> Rec as -> f ( Rec bs )

i.e. at field label l, use the typeclass instance c l a b to perform a type-changing update of type a -> f b.

This is quite general and can be used to write zipWith-style functions for instance.

I still need to test some of this a bit more though.