Commit bf8c9499 authored by Camil Staps's avatar Camil Staps 🚀

Merge branch 'DataSetFoldImplementations' into 'master'

provide specific fold instances for Data.Set to improve performance

See merge request !254
parents 254d9995 a4a4c21d
Pipeline #23470 passed with stage
in 3 minutes and 52 seconds
......@@ -40,9 +40,22 @@ gEq{|Set|} eEq x y = (size x == size y) && gEq{|* -> *|} eEq (toAscList x) (toAs
gLexOrd{|Set|} eLexOrd x y = gLexOrd{|* -> *|} eLexOrd (toAscList x) (toAscList y)
instance Foldable Set where
foldr :: (a .b -> .b) .b !(Set a) -> .b
foldr _ z Tip = z
foldr f z (Bin _ x l r) = foldr f (f x (foldr f z r)) l
foldr` :: (a .b -> .b) !.b !(Set a) -> .b
foldr` _ z Tip = z
foldr` f z (Bin _ x l r) = foldr` f (f x (foldr` f z r)) l
foldl :: (.b -> .(a -> .b)) .b !(Set a) -> .b
foldl _ z Tip = z
foldl f z (Bin _ x l r) = foldl f (f (foldl f z l) x) r
foldl` :: (.b -> .(a -> .b)) !.b !(Set a) -> .b
foldl` _ z Tip = z
foldl` f z (Bin _ x l r) = foldl` f (f (foldl` f z l) x) r
/*--------------------------------------------------------------------
* Query
*--------------------------------------------------------------------*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment