Commit 2d48998b authored by Steffen Michels's avatar Steffen Michels

remove superfluous fold function from Data.Set and use more efficient foldl...

remove superfluous fold function from Data.Set and use more efficient foldl marcro from StdList instead of foldl from Foldable
parent 84f142fb
Pipeline #16539 passed with stage
in 2 minutes and 48 seconds
......@@ -63,12 +63,12 @@ definition module Data.Set
from StdOverloaded import class ==, class < (..)
from StdClass import class Ord (..), <=, >
from Data.Maybe import :: Maybe
from Data.List import foldl, map
from StdList import foldl, map
from Data.Maybe import :: Maybe
from StdBool import not, &&
from Data.GenEq import generic gEq
from Data.GenLexOrd import generic gLexOrd, :: LexOrd
from Data.Foldable import class Foldable
from Data.Foldable import class Foldable (foldr`)
/**
* A `Set a` is an unordered, uncounted collection of values of type `a`.
......@@ -423,12 +423,6 @@ split :: !a !(Set a) -> (!Set a, !Set a) | < a
*/
splitMember :: !a !(Set a) -> (!Set a, !Bool, !Set a) | < a
/**
* Post-order fold.
* @complexity O(n)
*/
fold :: !(a -> .b -> .b) !.b !.(Set a) -> .b
/**
* Convert the set to an ascending list of elements.
* @type (Set a) -> [a]
......@@ -443,7 +437,7 @@ toList s :== toAscList s
* @complexity O(n)
* @type (Set a) -> [a]
*/
toAscList t :== fold (\a as -> [a:as]) [] t
toAscList t :== foldr` (\a as -> [a:as]) [] t
/**
* Create a set from a list of elements.
......
......@@ -227,14 +227,6 @@ partition p (Bin _ x l r)
| p x = (link x l1 r1,merge l2 r2)
| otherwise = (merge l1 r1,link x l2 r2)
/*--------------------------------------------------------------------
* Fold
*--------------------------------------------------------------------*/
fold :: !(a -> .b -> .b) !.b !.(Set a) -> .b
fold _ z Tip = z
fold f z (Bin _ x l r) = fold f (f x (fold f z r)) l
/*--------------------------------------------------------------------
* Lists
*--------------------------------------------------------------------*/
......
......@@ -9,12 +9,12 @@ import StdString
from StdTuple import fst, snd
import Data.List
import Data.GenEq
from Data.Set import :: Set, instance == (Set a), instance < (Set a), fold, fromList, toList, toAscList
from Data.Set import :: Set, instance == (Set a), instance < (Set a), instance Foldable Set, fromList, toList, toAscList
from Data.Map import :: Map, findKeyWith
from Data.Maybe import :: Maybe (..), fromJust, maybeToList, instance Functor Maybe, instance == (Maybe a)
import Data.Error
from Data.Functor import class Functor (..)
from Data.Foldable import class Foldable (foldl1)
from Data.Foldable import class Foldable (foldl1, foldr`)
from Control.Applicative import class Applicative
import Control.Monad
import Data.MapCollection
......@@ -952,7 +952,7 @@ where
resolveImgAttrs :: !ImgTags !FontSpans !TextSpans !(Set BasicImgAttr) !*(!ImgPaths,!ImgSpans,!GridSpans) -> (!MaybeError SpanResolveError (Set BasicImgAttr),!*(!ImgPaths,!ImgSpans,!GridSpans))
resolveImgAttrs user_tags font_spans text_spans attrs spans
#! (m_attrs`,spans) = strictTRMapSt (resolveImgAttr user_tags font_spans text_spans) (fold (\a as -> [a:as]) [] attrs) spans // USING (toList attrs) INSTEAD OF (fold (\a as -> [a:as]) [] attrs) CRASHES THE COMPILER: Run Time Error: index out of range
#! (m_attrs`,spans) = strictTRMapSt (resolveImgAttr user_tags font_spans text_spans) (foldr` (\a as -> [a:as]) [] attrs) spans // USING (toList attrs) INSTEAD OF (fold (\a as -> [a:as]) [] attrs) CRASHES THE COMPILER: Run Time Error: index out of range
= case [e \\ Error e <- m_attrs`] of
[e : _] = (Error e,spans)
_ = (Ok (fromList (map fromOk m_attrs`)),spans)
......
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