Skip to content

Instantly share code, notes, and snippets.

@jfischoff
Created December 31, 2014 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfischoff/999abf4ac5e5dc516d3a to your computer and use it in GitHub Desktop.
Save jfischoff/999abf4ac5e5dc516d3a to your computer and use it in GitHub Desktop.
A mix of Vinyl style and SOP style
foldRRec :: forall f xs c a b p.
RecAll f xs c
=> p c
-> (forall x. c x => x -> a)
-> (a -> b -> b)
-> b
-> NP f xs
-> b
foldRRec p convert f z xs
= foldRRec' convert f z
$ reifyConstraint p xs
foldRRec' :: RecAll f xs c
=> (forall x. c x => x -> a)
-> (a -> b -> b)
-> b
-> NP (Dict c :. f) xs
-> b
foldRRec' _ _ z Nil = z
foldRRec' convert f z ((Compose (Dict x)) :* xs)
= f (convert x)
$ foldRRec' convert f z xs
reifyConstraint
:: RecAll f rs c
=> proxy c
-> NP f rs
-> NP (Dict c :. f) rs
reifyConstraint prx rec =
case rec of
Nil -> Nil
(x :* xs) -> Compose (Dict x) :* reifyConstraint prx xs
foldMapG :: forall f xs c m p.
(RecAll f xs c, Monoid m)
=> p c
-> (forall x. c x => x -> m)
-> NP f xs
-> m
foldMapG p f xs = foldRRec p f (<>) mempty xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment