Created
December 31, 2014 22:40
-
-
Save jfischoff/999abf4ac5e5dc516d3a to your computer and use it in GitHub Desktop.
A mix of Vinyl style and SOP style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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