Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/Constrained/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Constrained.Core (
NonEmpty ((:|)),
Evidence (..),
unionWithMaybe,
nubOrd,
) where

import Constrained.List (
Expand Down Expand Up @@ -130,3 +131,13 @@ instance Typeable c => Show (Evidence c) where
unionWithMaybe :: (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
unionWithMaybe f ma ma' = (f <$> ma <*> ma') <|> ma <|> ma'

-- | Strip out duplicates (in n-log(n) time, by building an intermediate Set)
nubOrd :: Ord a => [a] -> [a]
nubOrd =
loop mempty
where
loop _ [] = []
loop s (a : as)
| a `Set.member` s = loop s as
| otherwise =
let s' = Set.insert a s in s' `seq` a : loop s' as
15 changes: 2 additions & 13 deletions src/Constrained/NumOrd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import Constrained.AbstractSyntax
import Constrained.Base
import Constrained.Conformance
import Constrained.Core (Value (..), unionWithMaybe)
import Constrained.Core (Value (..), unionWithMaybe, nubOrd)
import Constrained.FunctionSymbol
import Constrained.GenT
import Constrained.Generic
Expand All @@ -70,7 +70,7 @@
import Data.List.NonEmpty (NonEmpty ((:|)))
import qualified Data.List.NonEmpty as NE
import Data.Maybe
import qualified Data.Set as Set

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.8

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.8

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.8

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Stack

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.6

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.6

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.6

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.10

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.10

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.10

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - latest

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - latest

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - latest

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.12

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.12

The qualified import of ‘Data.Set’ is redundant

Check warning on line 73 in src/Constrained/NumOrd.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - Linux - 9.12

The qualified import of ‘Data.Set’ is redundant
import Data.Typeable (typeOf)
import Data.Word
import GHC.Int
Expand Down Expand Up @@ -362,17 +362,6 @@
-- implementations are found here
-- =====================================================================

-- | Strip out duplicates (in n-log(n) time, by building an intermediate Set)
nubOrd :: Ord a => [a] -> [a]
nubOrd =
loop mempty
where
loop _ [] = []
loop s (a : as)
| a `Set.member` s = loop s as
| otherwise =
let s' = Set.insert a s in s' `seq` a : loop s' as

-- | Builds a MemberSpec, but returns an Error spec if the list is empty
nubOrdMemberSpec :: Ord a => String -> [a] -> Specification a
nubOrdMemberSpec message xs =
Expand Down Expand Up @@ -936,7 +925,7 @@

propagateMemberSpec AddW (HOLE :<: i) es =
memberSpec
(nub $ mapMaybe (safeSubtract i) (NE.toList es))
(nubOrd $ mapMaybe (safeSubtract i) (NE.toList es))
( NE.fromList
[ "propagateSpecFn on (" ++ show i ++ " +. HOLE)"
, "The Spec is a MemberSpec = " ++ show es -- show (MemberSpec @HasSpec @TS es)
Expand Down
Loading