Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions containers-tests/tests/seq-properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Control.Arrow ((***))
import Control.Monad.Trans.State.Strict
import Data.Array (listArray)
import Data.Coerce (coerce)
import Data.Foldable (Foldable(foldl, foldl1, foldr, foldr1, foldMap, fold), toList, all, sum, foldl', foldr')
import Data.Foldable (Foldable(foldl, foldl1, foldr, foldr1, foldMap, fold), all, sum, foldl', foldr')
import Data.Functor ((<$>), (<$))
import Data.Maybe (listToMaybe)
import qualified Data.Maybe as Maybe
Expand Down Expand Up @@ -194,8 +194,8 @@ instance (Arbitrary a, Sized a) => Arbitrary (FingerTree a) where
arb n = do
pr <- arbitrary
sf <- arbitrary
let n_pr = Prelude.length (toList pr)
let n_sf = Prelude.length (toList sf)
let n_pr = Prelude.length pr
n_sf = Prelude.length sf
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa... Any idea why we had such a uselessly inefficient length calculation here before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are Digits so it's up to 4 elements and I don't think it is noticeable. It might even end up the same after inlining and optimizations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I got mixed up. Still better to get it right.

-- adding n `div` 7 ensures that n_m >= 0, and makes more Singles
let n_m = max (n `div` 7) ((n - n_pr - n_sf) `div` 3)
m <- arb n_m
Expand Down
2 changes: 2 additions & 0 deletions containers/src/Data/Sequence.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ module Data.Sequence (
viewl, -- :: Seq a -> ViewL a
ViewR(..),
viewr, -- :: Seq a -> ViewR a
-- ** List
toList,
-- * Scans
scanl, -- :: (a -> b -> a) -> a -> Seq b -> Seq a
scanl1, -- :: (a -> a -> a) -> Seq a -> Seq a
Expand Down
16 changes: 13 additions & 3 deletions containers/src/Data/Sequence/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ module Data.Sequence.Internal (
viewl, -- :: Seq a -> ViewL a
ViewR(..),
viewr, -- :: Seq a -> ViewR a
-- ** List
toList,
-- * Scans
scanl, -- :: (a -> b -> a) -> a -> Seq b -> Seq a
scanl1, -- :: (a -> a -> a) -> Seq a -> Seq a
Expand Down Expand Up @@ -197,7 +199,7 @@ import Control.Monad (MonadPlus(..))
import Data.Monoid (Monoid(..))
import Data.Functor (Functor(..))
import Utils.Containers.Internal.State (State(..), execState)
import Data.Foldable (foldr', toList)
import Data.Foldable (foldr')
import qualified Data.Foldable as F

import qualified Data.Semigroup as Semigroup
Expand Down Expand Up @@ -2375,6 +2377,12 @@ viewRTree (Deep s pr m (Three x y z)) =
viewRTree (Deep s pr m (Four w x y z)) =
SnocRTree (Deep (s - size z) pr m (Three w x y)) z

-- | \(O(n)\). Convert to a list of elements.
--
-- @since FIXME
toList :: Seq a -> [a]
toList = F.toList

------------------------------------------------------------------------
-- Scans
--
Expand Down Expand Up @@ -4316,8 +4324,10 @@ findIndicesR p xs = foldlWithIndex g [] xs
-- eventually find a less mind-bending way to accomplish this.

-- | \( O(n) \). Create a sequence from a finite list of elements.
-- There is a function 'toList' in the opposite direction for all
-- instances of the 'Foldable' class, including 'Seq'.
Comment thread
meooow25 marked this conversation as resolved.
--
-- @'fromList' . 'toList' = id@
--
-- For any finite list @xs@, @'toList' ('fromList' xs) = xs@.
fromList :: [a] -> Seq a
-- Note: we can avoid map_elem if we wish by scattering
-- Elem applications throughout mkTreeE and getNodesE, but
Expand Down
Loading