Commit e0f2da8d authored by Steffen Michels's avatar Steffen Michels

Merge branch 'reduce-warnings' into 'master'

Reduce strictness annotation warnings

See merge request !261
parents 9fe0136c 09dd3c82
Pipeline #27572 passed with stage
in 3 minutes and 11 seconds
......@@ -98,7 +98,7 @@ instance docDescription ParamDoc
* the arguments (the second argument). The first argument is the name.
*/
:: Property
= ForAll !String ![(!String,!Type)] !String
= ForAll !String ![(String,Type)] !String
/**
* When a property type contains type variables, a `PropertyVarInstantiation`
......@@ -251,7 +251,7 @@ parseDoc :: !String -> Either ParseError (!d, ![ParseWarning]) | docBlockToDoc{|
* @representation An order list of key-value pairs. A key can occur multiple
* times. The description has key `description`.
*/
:: DocBlock :== [(!String, !String)]
:: DocBlock :== [(String, String)]
/**
* The magic for {{`parseDoc`}}. Usually, a record type like {{`FunctionDoc`}}
......
......@@ -186,7 +186,7 @@ where
Left es -> Left (UnknownError "failed to parse property signature")
Right (name,args) -> Right (ForAll name args, [])
where
parser :: Parser Char (!String, ![(!String, !Type)])
parser :: Parser Char (!String, ![(String, Type)])
parser = skipSpaces *>
pMany (pSatisfy ((<>) ':')) >>= \name ->
skipSpaces *> pToken ':' *>
......
......@@ -109,7 +109,7 @@ where
:: UnificationState =
{ assignments :: ![TVAssignment]
, goals :: ![(!Type, !Type)]
, goals :: ![(Type, Type)]
, used_universal_vars :: ![TypeVar]
}
assignments s :== s.UnificationState.assignments
......
......@@ -6,7 +6,7 @@ from Data.Functor import class Functor
from Control.Applicative import class pure, class <*>, class Applicative
from Control.Monad import class Monad
mapArrSt :: !(.a -> .(*st -> *(!.a, !*st))) !*(arr .a) !*st -> *(!*(arr .a), !*st) | Array arr a
mapArrSt :: !(.a -> .(*st -> *(.a, *st))) !*(arr .a) !*st -> *(!*(arr .a), !*st) | Array arr a
foldrArr :: !(a .b -> .b) !.b !.(arr a) -> .b | Array arr a
......
......@@ -3,12 +3,12 @@ implementation module Data.Array
import StdArray, StdInt, StdOverloaded, StdClass, StdFunctions
import Data.Functor, Control.Applicative, Control.Monad
mapArrSt :: !(.a -> .(*st -> *(!.a, !*st))) !*(arr .a) !*st -> *(!*(arr .a), !*st) | Array arr a
mapArrSt :: !(.a -> .(*st -> *(.a, *st))) !*(arr .a) !*st -> *(!*(arr .a), !*st) | Array arr a
mapArrSt f arr st
#! (sz, arr) = usize arr
= mapArrSt` sz 0 f arr st
where
mapArrSt` :: !Int !Int !(.a -> .(*st -> *(!.a, !*st))) !*(arr .a) !*st -> *(!*(arr .a), !*st) | Array arr a
mapArrSt` :: !Int !Int !(.a -> .(*st -> *(.a, *st))) !*(arr .a) !*st -> *(!*(arr .a), !*st) | Array arr a
mapArrSt` sz idx f arr st
| idx == sz = (arr, st)
| otherwise
......
......@@ -50,13 +50,13 @@ instance asinh (Complex a) | Ord a & Eq a & AllGeo a & Arith a & pi a & sqrt a &
instance acosh (Complex a) | Ord a & Eq a & AllGeo a & Arith a & pi a & sqrt a & ln a
instance atanh (Complex a) | Ord a & Eq a & AllGeo a & Arith a & pi a & sqrt a & ln a
realPart :: (Complex a) -> a
imagPart :: (Complex a) -> a
realPart :: !(Complex a) -> a
imagPart :: !(Complex a) -> a
mkPolar :: a a -> Complex a | cos a & sin a & * a
cis :: a -> Complex a | cos a & sin a
polar :: (Complex a) -> (a, a) | Ord a & Eq a & atan a & sqrt a & MultDiv a & PlusMin a & pi a
magnitude :: (Complex a) -> a | sqrt a & * a & + a
phase :: (Complex a) -> a | Ord a & Eq a & atan a & MultDiv a & PlusMin a & pi a
magnitude :: !(Complex a) -> a | sqrt a & * a & + a
phase :: !(Complex a) -> a | Ord a & Eq a & atan a & MultDiv a & PlusMin a & pi a
conjugate :: (Complex a) -> Complex a | ~ a
conjugate :: !(Complex a) -> Complex a | ~ a
......@@ -129,10 +129,10 @@ instance acosh (Complex a) | Ord a & Eq a & AllGeo a & Arith a & pi a & sqrt a &
instance atanh (Complex a) | Ord a & Eq a & AllGeo a & Arith a & pi a & sqrt a & ln a where
atanh z = (one/two) * ln ((one+z) / (one-z))
realPart :: (Complex a) -> a
realPart :: !(Complex a) -> a
realPart (x :+ _) = x
imagPart :: (Complex a) -> a
imagPart :: !(Complex a) -> a
imagPart (_ :+ x) = x
mkPolar :: a a -> Complex a | cos a & sin a & * a
......@@ -144,10 +144,10 @@ cis theta = cos theta :+ sin theta
polar :: (Complex a) -> (a, a) | Ord a & Eq a & atan a & sqrt a & MultDiv a & PlusMin a & pi a
polar z = (magnitude z, phase z)
magnitude :: (Complex a) -> a | sqrt a & * a & + a
magnitude :: !(Complex a) -> a | sqrt a & * a & + a
magnitude (x :+ y) = sqrt (x*x + y*y)
phase :: (Complex a) -> a | Ord a & Eq a & atan a & MultDiv a & PlusMin a & pi a
phase :: !(Complex a) -> a | Ord a & Eq a & atan a & MultDiv a & PlusMin a & pi a
phase (x :+ y)
| x > zero = atan (y/x)
| x < zero && y >= zero = atan (y/x) + pi
......@@ -156,7 +156,7 @@ phase (x :+ y)
| x == zero && y < zero = pi / two
= undef
conjugate :: (Complex a) -> Complex a | ~ a
conjugate :: !(Complex a) -> Complex a | ~ a
conjugate (x :+ y) = x :+ (~y)
//Ugly
......
......@@ -5,4 +5,4 @@ definition module Data.Data
//
// Left True =+?= Left False == True
//
(=+?=) infix 6 :: a a -> Bool
(=+?=) infix 6 :: !a !a -> Bool
......@@ -7,6 +7,6 @@ import StdOverloaded, StdCleanTypes, StdString
//
// Left True =+?= Left False == True
//
(=+?=) infix 6 :: a a -> Bool
// TODO: this can probably be: pushD_a 0; pushD_a 1; pop_a 2; eqI
(=+?=) infix 6 :: !a !a -> Bool
(=+?=) l r = toString (CTToCons l) == toString (CTToCons r)
......@@ -5,4 +5,4 @@ from StdOverloaded import class ==
encodeInt :: ![Int] -> [Int]
decodeInt :: ![Int] -> [Int]
encode :: ![a] -> [(Int, a)] | == a
decode :: ![(!Int, !a)] -> [a] | == a
decode :: ![(Int, a)] -> [a] | == a
......@@ -27,17 +27,17 @@ decodeInt xs = reverse (rldInt` xs [])
encode :: ![a] -> [(Int, a)] | == a
encode xs = reverse (rle` xs [])
where
rle` :: ![a] ![(!Int, !a)] -> [(Int, a)] | == a
rle` :: ![a] ![(Int, a)] -> [(Int, a)] | == a
rle` [] acc = acc
rle` [x:xs] [] = rle` xs [(1, x)]
rle` [x:xs] [t=:(n, y) : ys]
| x == y = rle` xs [(n + 1, y) : ys]
| otherwise = rle` xs [(1, x) : t : ys]
decode :: ![(!Int, !a)] -> [a] | == a
decode :: ![(Int, a)] -> [a] | == a
decode xs = reverse (rld` xs [])
where
rld` :: ![(!Int, !a)] ![a] -> [a] | == a
rld` :: ![(Int, a)] ![a] -> [a] | == a
rld` [] acc = acc
rld` [(0, x) : xs] acc = rld` xs acc
rld` [(n, x) : xs] acc = rld` [(n - 1, x) : xs] [x : acc]
......
......@@ -102,7 +102,7 @@ combineErrors :: !(MaybeError e a) (MaybeError e b) (a b -> MaybeError e c) -> M
* @param The second operation, getting the result of the first as input
* @return The Error of the first or the second operation
*/
seqErrorsSt :: !(.st -> (MaybeError e a,!.st)) (a .st -> u:(!MaybeError e b, !.st)) !.st -> v:(MaybeError e b, !.st), [u <= v]
seqErrorsSt :: !(.st -> (MaybeError e a,.st)) (a .st -> u:(MaybeError e b, .st)) !.st -> v:(MaybeError e b, !.st), [u <= v]
/**
* Combines two MaybeError values, resulting from two operations on a state.
......@@ -113,4 +113,4 @@ seqErrorsSt :: !(.st -> (MaybeError e a,!.st)) (a .st -> u:(!MaybeError e b, !.s
* @param A combination function for the inputs if they are Ok
* @return The error of one of the operations or the result of the combination
*/
combineErrorsSt :: !(.st -> (!MaybeError e a, !.st)) (.st -> (!MaybeError e b, !.st)) (a b -> MaybeError e c) !.st -> (!MaybeError e c, !.st)
combineErrorsSt :: !(.st -> (MaybeError e a, .st)) (.st -> (MaybeError e b, .st)) (a b -> MaybeError e c) !.st -> (!MaybeError e c, !.st)
......@@ -68,7 +68,7 @@ combineErrors a b combf = case a of
Error e = Error e
Ok b = combf a b
seqErrorsSt :: !(.st -> (MaybeError e a,!.st)) (a .st -> u:(!MaybeError e b, !.st)) !.st -> v:(MaybeError e b, !.st), [u <= v]
seqErrorsSt :: !(.st -> (MaybeError e a,.st)) (a .st -> u:(MaybeError e b, .st)) !.st -> v:(MaybeError e b, !.st), [u <= v]
seqErrorsSt aop bop st
# (a,st) = aop st
= case a of
......@@ -76,7 +76,7 @@ seqErrorsSt aop bop st
Ok a = bop a st
combineErrorsSt :: !(.st -> (!MaybeError e a, !.st)) (.st -> (!MaybeError e b, !.st)) (a b -> MaybeError e c) !.st -> (!MaybeError e c, !.st)
combineErrorsSt :: !(.st -> (MaybeError e a, .st)) (.st -> (MaybeError e b, .st)) (a b -> MaybeError e c) !.st -> (!MaybeError e c, !.st)
combineErrorsSt aop bop combf st
# (a,st) = aop st
= case a of
......
......@@ -52,7 +52,7 @@ seqSt :: !(a .st -> .st) ![a] !.st -> .st
* @param The initial state.
* @result The value results and the final state.
*/
mapSt :: !(a .st -> (!b,!.st)) ![a] !.st -> (![b],.st)
mapSt :: !(a .st -> (b,.st)) ![a] !.st -> (![b],.st)
/**
* The fixed point combinator, reducing `fix f` to `f (fix f)`.
*/
......
......@@ -35,7 +35,7 @@ seqSt :: !(a .st -> .st) ![a] !.st -> .st
seqSt f [] st = st
seqSt f [x:xs] st = seqSt f xs (f x st)
mapSt :: !(a .st -> (!b,!.st)) ![a] !.st -> (![b],.st)
mapSt :: !(a .st -> (b,.st)) ![a] !.st -> (![b],.st)
mapSt f [] st = ([], st)
mapSt f [x:xs] st
# (y, st) = f x st
......
......@@ -62,7 +62,7 @@ setNodeData :: NodeIndex a u:(Graph a b) -> v:(Graph a b), [u <= v]
//Mapping
mapNodes :: !(a -> b) !.(Graph a e) -> .(Graph b e)
mapEdges :: !(a -> b) !.(Graph n a) -> .(Graph n b)
mapIndices :: ![(!NodeIndex,!NodeIndex)] !.(Graph n e) -> .(Graph n e)
mapIndices :: ![(NodeIndex,NodeIndex)] !.(Graph n e) -> .(Graph n e)
//Folding
foldrNodes :: (NodeIndex (Node n) .a -> .a) .a .(Graph n e) -> .a
......
......@@ -224,7 +224,7 @@ where
mapMap :: (a -> b) (Map k a) -> (Map k b) | Eq k & Ord k
mapMap f m = (fromList o map (app2 (id,f)) o toList) m
mapIndices :: ![(!NodeIndex,!NodeIndex)] !.(Graph n e) -> .(Graph n e)
mapIndices :: ![(NodeIndex,NodeIndex)] !.(Graph n e) -> .(Graph n e)
mapIndices updates { nodes, edges }
# updMap = fromList updates
= { Graph
......
......@@ -25,15 +25,15 @@ instance == (Heap a)
instance < (Heap a)
instance Semigroup (Heap a)
instance Semigroup (Heap a) where mappend :: !(Heap a) !(Heap a) -> Heap a
instance Monoid (Heap a)
:: Entry p a = Entry p a
null :: (Heap a) -> Bool
null :: !(Heap a) -> Bool
size :: (Heap a) -> Int
size :: !(Heap a) -> Int
//* @type Heap a
empty :== Empty
......@@ -47,32 +47,32 @@ singletonWith f a :== Heap 1 f (Node 0 a Nil)
//* @type a (Heap a) -> (Heap a) | Ord a
insert :== insertWith (<=)
insertWith :: (a a -> Bool) a (Heap a) -> Heap a
insertWith :: (a a -> Bool) a !(Heap a) -> Heap a
union :: (Heap a) (Heap a) -> Heap a
union :: !(Heap a) !(Heap a) -> Heap a
replicate :: a Int -> Heap a | Ord a
replicate :: a !Int -> Heap a | Ord a
uncons :: (Heap a) -> Maybe (a, Heap a) | Ord a
uncons :: !(Heap a) -> Maybe (a, Heap a) | Ord a
//* @type (Heap a) -> Maybe (a, Heap a) | Ord a
viewMin :== uncons
minimum :: (Heap a) -> a
minimum :: !(Heap a) -> a
trees :: (Forest a) -> [Tree a]
trees :: !(Forest a) -> [Tree a]
deleteMin :: (Heap a) -> Heap a
deleteMin :: !(Heap a) -> Heap a
map :: (a -> b) (Heap a) -> Heap b | Ord b
map :: (a -> b) !(Heap a) -> Heap b | Ord b
mapMonotonic :: (a -> b) (Heap a) -> Heap b | Ord b
mapMonotonic :: (a -> b) !(Heap a) -> Heap b | Ord b
filter :: (a -> Bool) (Heap a) -> Heap a
filter :: (a -> Bool) !(Heap a) -> Heap a
partition :: (a -> Bool) (Heap a) -> (Heap a, Heap a)
partition :: (a -> Bool) !(Heap a) -> (Heap a, Heap a)
split :: a (Heap a) -> (Heap a, Heap a, Heap a)
split :: a !(Heap a) -> (Heap a, Heap a, Heap a)
//* @type Int (Heap a) -> Heap a
take :== withList o 'Data.List'.take
......@@ -95,18 +95,18 @@ takeWhile :== withList o 'Data.List'.takeWhile
//* @type (a -> Bool) (Heap a) -> Heap a
dropWhile :== withList o 'Data.List'.dropWhile
nub :: (Heap a) -> Heap a
nub :: !(Heap a) -> Heap a
concatMap :: (a -> Heap b) (Heap a) -> Heap b | Ord b
concatMap :: (a -> Heap b) !(Heap a) -> Heap b | Ord b
group :: (Heap a) -> Heap (Heap a)
group :: !(Heap a) -> Heap (Heap a)
groupBy :: (a a -> Bool) (Heap a) -> Heap (Heap a)
groupBy :: (a a -> Bool) !(Heap a) -> Heap (Heap a)
intersect :: (Heap a) (Heap a) -> Heap a
intersect :: !(Heap a) (Heap a) -> Heap a
intersectWith :: (a a -> b) (Heap a) (Heap a) -> Heap b | Ord b
intersectWith :: (a a -> b) !(Heap a) (Heap a) -> Heap b | Ord b
withList :: ([a] -> [a]) (Heap a) -> Heap a
withList :: ([a] -> [a]) !(Heap a) -> Heap a
splitWithList :: ([a] -> ([a], [a])) (Heap a) -> (Heap a, Heap a)
splitWithList :: ([a] -> ([a], [a])) !(Heap a) -> (Heap a, Heap a)
......@@ -72,7 +72,7 @@ instance < (Heap a) where
//
// >>> null (singleton "hello")
// False
null :: (Heap a) -> Bool
null :: !(Heap a) -> Bool
null Empty = True
null _ = False
......@@ -84,7 +84,7 @@ null _ = False
// 1
// >>> size (fromList [4,1,2])
// 3
size :: (Heap a) -> Int
size :: !(Heap a) -> Int
size Empty = 0
size (Heap s _ _) = s
......@@ -124,7 +124,7 @@ singletonWith f a :== Heap 1 f (Node 0 a Nil)
//insert :: a (Heap a) -> (Heap a) | Ord a
insert :== insertWith (<=)
insertWith :: (a a -> Bool) a (Heap a) -> Heap a
insertWith :: (a a -> Bool) a !(Heap a) -> Heap a
insertWith leq x Empty = singletonWith leq x
insertWith leq x (Heap s _ t=:(Node _ y f))
| leq x y = Heap (s + 1) leq (Node 0 x (Cons t Nil))
......@@ -136,7 +136,7 @@ insertWith leq x (Heap s _ t=:(Node _ y f))
// fromList [1,2,6,4,3,5]
// >>> union (fromList [1,1,1]) (fromList [1,2,1])
// fromList [1,1,1,2,1,1]
union :: (Heap a) (Heap a) -> Heap a
union :: !(Heap a) !(Heap a) -> Heap a
union Empty q = q
union q Empty = q
union (Heap s1 leq t1=:(Node _ x1 f1)) (Heap s2 _ t2=:(Node _ x2 f2))
......@@ -148,7 +148,7 @@ union _ _ = abort "error in union\n"
//
// >>> replicate 'a' 10
// fromList "aaaaaaaaaa"
replicate :: a Int -> Heap a | Ord a
replicate :: a !Int -> Heap a | Ord a
replicate x0 y0 = fromList (repeatn y0 x0)
//| y0 < 0 = abort "Heap.replicate: negative length"
//| y0 == 0 = mempty
......@@ -168,7 +168,7 @@ replicate x0 y0 = fromList (repeatn y0 x0)
//
// >>> uncons (fromList [2,1,3])
// Just (1,fromList [2,3])
uncons :: (Heap a) -> Maybe (a, Heap a) | Ord a
uncons :: !(Heap a) -> Maybe (a, Heap a) | Ord a
uncons l=:(Heap _ _ t) = Just (root t, deleteMin l)
uncons _ = Nothing
......@@ -180,11 +180,11 @@ viewMin :== uncons
//
// >>> minimum (fromList [3,1,2])
// 1
minimum :: (Heap a) -> a
minimum :: !(Heap a) -> a
minimum (Heap _ _ t) = root t
minimum _ = abort "Heap.minimum: empty heap"
trees :: (Forest a) -> [Tree a]
trees :: !(Forest a) -> [Tree a]
trees (Cons a as) = [a : trees as]
trees _ = []
......@@ -192,7 +192,7 @@ trees _ = []
//
// >>> deleteMin (fromList [3,1,2])
// fromList [2,3]
deleteMin :: (Heap a) -> Heap a
deleteMin :: !(Heap a) -> Heap a
deleteMin Empty = Empty
deleteMin (Heap _ _ (Node _ _ Nil)) = Empty
deleteMin (Heap s leq (Node _ _ f0)) = Heap (s - 1) leq (Node 0 x f3)
......@@ -206,7 +206,7 @@ deleteMin (Heap s leq (Node _ _ f0)) = Heap (s - 1) leq (Node 0 x f3)
//
// >>> adjustMin (+1) (fromList [1,2,3])
// fromList [2,2,3]
adjustMin :: (a -> a) (Heap a) -> Heap a
adjustMin :: (a -> a) !(Heap a) -> Heap a
adjustMin _ Empty = Empty
adjustMin f (Heap s leq (Node r x xs)) = Heap s leq (heapify leq (Node r (f x) xs))
......@@ -274,7 +274,8 @@ fromListWith f xs :== 'StdList'.foldr (insertWith f) mempty xs
sort xs = 'Data.Foldable'.toList (fromList xs)
instance Semigroup (Heap a) where
mappend l r = union l r
mappend :: !(Heap a) !(Heap a) -> Heap a
mappend l r = union l r
instance Monoid (Heap a) where
mempty = empty
......@@ -314,7 +315,7 @@ instance Foldable Heap where
//
// >>> map negate (fromList [3,1,2])
// fromList [-3,-1,-2]
map :: (a -> b) (Heap a) -> Heap b | Ord b
map :: (a -> b) !(Heap a) -> Heap b | Ord b
map _ Empty = Empty
map f (Heap _ _ t) = foldMap (singleton o f) t
......@@ -325,7 +326,7 @@ map f (Heap _ _ t) = foldMap (singleton o f) t
// fromList [2,3,4]
// >>> map (*2) (fromList [1,2,3])
// fromList [2,4,6]
mapMonotonic :: (a -> b) (Heap a) -> Heap b | Ord b
mapMonotonic :: (a -> b) !(Heap a) -> Heap b | Ord b
mapMonotonic _ Empty = Empty
mapMonotonic f (Heap s _ t) = Heap s (<=) (fmap f t)
......@@ -339,7 +340,7 @@ mapMonotonic f (Heap s _ t) = Heap s (<=) (fmap f t)
// fromList []
// >>> filter (<'a') (fromList "ab")
// fromList []
filter :: (a -> Bool) (Heap a) -> Heap a
filter :: (a -> Bool) !(Heap a) -> Heap a
filter _ Empty = Empty
filter p (Heap _ leq t) = foldMap f t
where
......@@ -350,7 +351,7 @@ filter p (Heap _ leq t) = foldMap f t
//
// >>> partition (>'a') (fromList "ab")
// (fromList "b",fromList "a")
partition :: (a -> Bool) (Heap a) -> (Heap a, Heap a)
partition :: (a -> Bool) !(Heap a) -> (Heap a, Heap a)
partition _ Empty = (Empty, Empty)
partition p (Heap _ leq t) = foldMap f t
where
......@@ -361,7 +362,7 @@ partition p (Heap _ leq t) = foldMap f t
//
// >>> split 'h' (fromList "hello")
// (fromList "e",fromList "h",fromList "llo")
split :: a (Heap a) -> (Heap a, Heap a, Heap a)
split :: a !(Heap a) -> (Heap a, Heap a, Heap a)
split a Empty = (Empty, Empty, Empty)
split a (Heap s leq t) = foldMap f t
where
......@@ -427,7 +428,7 @@ dropWhile :== withList o 'Data.List'.dropWhile
//
// >>> nub (fromList [1,1,2,6,6])
// fromList [1,2,6]
nub :: (Heap a) -> Heap a
nub :: !(Heap a) -> Heap a
nub Empty = Empty
nub h=:(Heap _ leq t) = insertWith leq x (nub zs)
where
......@@ -439,7 +440,7 @@ nub h=:(Heap _ leq t) = insertWith leq x (nub zs)
//
// >>> concatMap (\a -> fromList [a,a+1]) (fromList [1,4])
// fromList [1,4,5,2]
concatMap :: (a -> Heap b) (Heap a) -> Heap b | Ord b
concatMap :: (a -> Heap b) !(Heap a) -> Heap b | Ord b
concatMap _ Empty = Empty
concatMap f h=:(Heap _ _ t) = foldMap f t
......@@ -447,12 +448,12 @@ concatMap f h=:(Heap _ _ t) = foldMap f t
//
// >>> group (fromList "hello")
// fromList [fromList "e",fromList "h",fromList "ll",fromList "o"]
group :: (Heap a) -> Heap (Heap a)
group :: !(Heap a) -> Heap (Heap a)
group Empty = Empty
group h=:(Heap _ leq _) = groupBy (flip leq) h
// /O(n log n)/. Group using a user supplied function.
groupBy :: (a a -> Bool) (Heap a) -> Heap (Heap a)
groupBy :: (a a -> Bool) !(Heap a) -> Heap (Heap a)
groupBy f Empty = Empty
groupBy f h=:(Heap _ leq t) = insert (insertWith leq x ys) (groupBy f zs)
where
......@@ -461,7 +462,7 @@ groupBy f h=:(Heap _ leq t) = insert (insertWith leq x ys) (groupBy f zs)
(ys,zs) = span (f x) xs
// /O(n log n + m log m)/. Intersect the values in two heaps, returning the value in the left heap that compares as equal
intersect :: (Heap a) (Heap a) -> Heap a
intersect :: !(Heap a) (Heap a) -> Heap a
intersect Empty _ = Empty
intersect _ Empty = Empty
intersect a=:(Heap _ leq _) b = go leq ('Data.Foldable'.toList a) ('Data.Foldable'.toList b)
......@@ -478,7 +479,7 @@ intersect a=:(Heap _ leq _) b = go leq ('Data.Foldable'.toList a) ('Data.Foldabl
intersect _ _ = abort "error in intersect\n"
/// /O(n log n + m log m)/. Intersect the values in two heaps using a function to generate the elements in the right heap.
intersectWith :: (a a -> b) (Heap a) (Heap a) -> Heap b | Ord b
intersectWith :: (a a -> b) !(Heap a) (Heap a) -> Heap b | Ord b
intersectWith _ Empty _ = Empty
intersectWith _ _ Empty = Empty
intersectWith f a=:(Heap _ leq _) b = go leq f ('Data.Foldable'.toList a) ('Data.Foldable'.toList b)
......@@ -636,11 +637,11 @@ splitForest r zs ts (Cons t1 (Cons t2 cf))
r2 = rank t2
splitForest _ _ _ _ = abort "Heap.splitForest: invalid arguments"
withList :: ([a] -> [a]) (Heap a) -> Heap a
withList :: ([a] -> [a]) !(Heap a) -> Heap a
withList _ Empty = Empty
withList f hp=:(Heap _ leq _) = fromListWith leq (f ('Data.Foldable'.toList hp))
splitWithList :: ([a] -> ([a], [a])) (Heap a) -> (Heap a, Heap a)
splitWithList :: ([a] -> ([a], [a])) !(Heap a) -> (Heap a, Heap a)
splitWithList _ Empty = (Empty, Empty)
splitWithList f hp=:(Heap _ leq _) = both (fromListWith leq) (f ('Data.Foldable'.toList hp))
......
......@@ -50,7 +50,7 @@ foldrWithKey :: (Int a b -> b) b !(IntMap a) -> b
* where
* distinctAscList = sort $ removeDup list
*/
fromDistinctAscList :: ![(!Int, !a)] -> IntMap a
fromDistinctAscList :: ![(Int, a)] -> IntMap a
union :: !(IntMap a) !(IntMap a) -> IntMap a
......
......@@ -1488,15 +1488,15 @@ fromAscListWithKey f [x0 : xs0] = fromDistinctAscList (combineEq x0 xs0)
// /The precondition (input list is strictly ascending) is not checked./
//
// > fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")]
fromDistinctAscList :: ![(!Int, !a)] -> IntMap a
fromDistinctAscList :: ![(Int, a)] -> IntMap a
fromDistinctAscList [] = Nil
fromDistinctAscList [z0 : zs0] = work z0 zs0 Nada
where
work :: !(!Int, !a) ![(!Int, !a)] !(Stack a) -> IntMap a
work :: !(!Int, !a) ![(Int, a)] !(Stack a) -> IntMap a
work (kx,vx) [] stk = finish kx (Tip kx vx) stk
work (kx,vx) [z=:(kz,_):zs] stk = reduce z zs (branchMask kx kz) kx (Tip kx vx) stk
reduce :: !(!Int, !a) ![(!Int, !a)] !Mask !Prefix !(IntMap a) !(Stack a) -> IntMap a
reduce :: !(!Int, !a) ![(Int, a)] !Mask !Prefix !(IntMap a) !(Stack a) -> IntMap a
reduce z zs _ px tx Nada = work z zs (Push px tx Nada)
reduce z zs m px tx stk=:(Push py ty stk`) =
let mxy = branchMask px py
......
......@@ -149,7 +149,7 @@ map :: !(a -> b) !(IntMap a) -> IntMap b
// > mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")]
mapWithKey :: !(Int a -> b) !(IntMap a) -> IntMap b
mapSt :: !(a *st -> *(!b, !*st)) !.(IntMap a) !*st -> *(!IntMap b, !*st)
mapSt :: !(a *st -> *(b, *st)) !.(IntMap a) !*st -> *(!IntMap b, !*st)
/**
* @property is distinct and sorted: A.list :: [(Int, a)]:
......@@ -157,14 +157,14 @@ mapSt :: !(a *st -> *(!b, !*st)) !.(IntMap a) !*st -> *(!IntMap b, !*st)
* where
* distinctAscList = sort $ removeDup list
*/
toList :: !(IntMap a) -> [(!Int, !a)]
toList :: !(IntMap a) -> [(Int, a)]
toAscList :: !(IntMap a) -> [(!Int, !a)]
toAscList :: !(IntMap a) -> [(Int, a)]
fromList :: ![(!Int, !a)] -> IntMap a
fromList :: ![(Int, a)] -> IntMap a
// | /O(n*min(n,W))/. Create a map from a list of key\/value pairs with a combining function. See also 'fromAscListWith'.
//
// > fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]
// > fromListWith (++) [] == empty
fromListWith :: !(a a -> a) ![(!Int, !a)] -> IntMap a
fromListWith :: !(a a -> a) ![(Int, a)] -> IntMap a
......@@ -513,7 +513,7 @@ mapWithKey f t
//
// > let f a b = (a ++ b, b ++ "X")
// > mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
mapAccum :: !(a b -> (!a, !c)) !a !(IntMap b) -> (!a, !IntMap c)
mapAccum :: !(a b -> (a, c)) !a !(IntMap b) -> (!a, !IntMap c)
mapAccum f v m = mapAccumWithKey (\a` _ x -> f a` x) v m
// | /O(n)/. The function @'mapAccumWithKey'@ threads an accumulating
......@@ -521,14 +521,14 @@ mapAccum f v m = mapAccumWithKey (\a` _ x -> f a` x) v m
//
// > let f a k b = (a ++ " " ++ (show k) ++ "-" ++ b, b ++ "X")
// > mapAccumWithKey f "Everything:" (fromList [(5,"a"), (3,"b")]) == ("Everything: 3-b 5-a", fromList [(3, "bX"), (5, "aX")])
mapAccumWithKey :: !(a Int b -> (!a, !c)) !a !(IntMap b) -> (!a, !IntMap c)
mapAccumWithKey :: !(a Int b -> (a, c)) !a !(IntMap b) -> (!a, !IntMap c)
mapAccumWithKey f a t = mapAccumL f a t
// | /O(n)/. The function @'mapAccumL'@ threads an accumulating
// argument through the map in ascending order of keys. Strict in
// the accumulating argument and the both elements of the
// result of the function.
mapAccumL :: !(a Int b -> (!a, !c)) !a !(IntMap b) -> (!a, !IntMap c)
mapAccumL :: !(a Int b -> (a, c)) !a !(IntMap b) -> (!a, !IntMap c)
mapAccumL f a t
= case t of
Bin p m l r
......@@ -542,7 +542,7 @@ mapAccumL f a t
// | /O(n)/. The function @'mapAccumR'@ threads an accumulating
// argument through the map in descending order of keys.
mapAccumRWithKey :: !(a Int b -> (!a, !c)) !a !(IntMap b) -> (!a, !IntMap c)
mapAccumRWithKey :: !(a Int b -> (a, c)) !a !(IntMap b) -> (!a, !IntMap c)
mapAccumRWithKey f a t
= case t of
Bin p m l r
......@@ -645,7 +645,7 @@ mapEitherWithKey _ Nil = (Nil, Nil)
// > fromList [] == empty
// > fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")]
// > fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")]
fromList :: ![(!Int, !a)] -> IntMap a
fromList :: ![(Int, a)] -> IntMap a
fromList xs
= foldlStrict ins empty xs
where
......@@ -655,14 +655,14 @@ fromList xs
//
// > fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]
// > fromListWith (++) [] == empty
fromListWith :: !(a a -> a) ![(!Int, !a)] -> IntMap a
fromListWith :: !(a a -> a) ![(Int, a)] -> IntMap a
fromListWith f xs = fromListWithKey (\_ x y -> f x y) xs
// | /O(n*min(n,W))/. Build a map from a list of key\/value pairs with a combining function. See also fromAscListWithKey'.
//
// > fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]
// > fromListWith (++) [] == empty
fromListWithKey :: !(Int a a -> a) ![(!Int, !a)] -> IntMap a
fromListWithKey :: !(Int a a -> a) ![(Int, a)] -> IntMap a
fromListWithKey f xs = foldlStrict ins empty xs
where
ins t (k,x) = insertWithKey f k x t
......@@ -672,7 +672,7 @@ fromListWithKey f xs = foldlStrict ins empty xs
//
// > fromAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")]
// > fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")]
fromAscList :: ![(!Int, a)] -> IntMap a
fromAscList :: ![(Int, a)] -> IntMap a
fromAscList xs = fromAscListWithKey (\_ x _ -> x) xs
// | /O(n)/. Build a map from a list of key\/value pairs where
......@@ -680,7 +680,7 @@ fromAscList xs = fromAscListWithKey (\_ x _ -> x) xs
// /The precondition (input list is ascending) is not checked./
//
// > fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")]
fromAscListWith :: !(a a -> a) ![(!Int, !a)] -> IntMap a
fromAscListWith :: !(a a -> a) ![(Int, a)] -> IntMap a
fromAscListWith f xs = fromAscListWithKey (\_ x y -> f x y) xs
// | /O(n)/. Build a map from a list of key\/value pairs where
......@@ -688,7 +688,7 @@ fromAscListWith f xs = fromAscListWithKey (\_ x y -> f x y) xs
// /The precondition (input list is ascending) is not checked./
//
// > fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")]
fromAscListWithKey :: !(Int a a -> a) ![(!Int, !a)] -> IntMap a
fromAscListWithKey :: !(Int a a -> a) ![(Int, a)] -> IntMap a
fromAscListWithKey _ [] = Nil
fromAscListWithKey f [x0 : xs0] = fromDistinctAscList (combineEq x0 xs0)
where
......@@ -705,14 +705,14 @@ fromAscListWithKey f [x0 : xs0] = fromDistinctAscList (combineEq x0 xs0)
// /The precondition (input list is strictly ascending) is not checked./
//
// > fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")]
//fromDistinctAscList :: ![(!Int, !a)] -> IntMap a
//fromDistinctAscList :: ![(Int, a)] -> IntMap a
//fromDistinctAscList [] = Nil
//fromDistinctAscList [z0 : zs0] = work z0 zs0 Nada
//where
//work (kx,vx) [] stk = finish kx (Tip kx vx) stk
//work (kx,vx) [z=:(kz,_):zs] stk = reduce z zs (branchMask kx kz) kx (Tip kx vx) stk
//reduce :: !(!Int, !a) ![(!Int, !a)] !Mask !Prefix !(IntMap a) !(Stack a) -> IntMap a
//reduce :: !(!Int, !a) ![(Int, a)] !Mask !Prefix !(IntMap a) !(Stack a) -> IntMap a
//reduce z zs _ px tx Nada = work z zs (Push px tx Nada)
//reduce z zs m px tx stk=:(Push py ty stk`) =
//let mxy = branchMask px py
......@@ -733,7 +733,7 @@ instance Functor IntMap where
fmap f (Tip n x) = Tip n (f x)
fmap f (Bin p m l r) = Bin p m (fmap f l) (fmap f r)
mapSt :: !(a *st -> *(!b, !*st)) !.(IntMap a) !*st -> *(!IntMap b, !*st)
mapSt :: !(a *st -> *(b, *st)) !.(IntMap a) !*st -> *(!IntMap b, !*st)
mapSt _ Nil st = (Nil, st)
mapSt f (Tip n x) st
#! (x, st) = f x st
......@@ -829,12 +829,12 @@ maybe_link p1 t1 p2 t2 = link p1 t1 p2 t2
//
// > toList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
// > toList empty == []
toList :: !(IntMap a) -> [(!Int, !a)]
toList :: !(IntMap a) -> [(Int, a)]
toList m = toAscList m
// | /O(n)/. Convert the map to a list of key\/value pairs where the
// keys are in ascending order. Subject to list fusion.
//
// > toAscList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
toAscList :: !(IntMap a) -> [(!Int, !a)]
toAscList :: !(IntMap a) -> [(Int, a)]
toAscList m = foldrWithKey (\k x xs -> [(k,x):xs]) [] m
......@@ -24,6 +24,6 @@ definition module Data.IntSet.Base
:: BitMap :== Int
:: Key :== Int
member :: !Key IntSet -> Bool
member :: !Key !IntSet -> Bool
fromList :: [Key] -> IntSet
fromList :: ![Key] -> IntSet
......@@ -133,7 +133,7 @@ size Nil = 0
// | /O(min(n,W))/. Is the value a member of the set?
// See Note: Local 'go' functions and capturing]
member :: !Key IntSet -> Bool
member :: !Key !IntSet -> Bool
member x is = go is
where
go (Bin p m l r)
......@@ -758,7 +758,7 @@ toDescList :: IntSet -> [Key]
toDescList s = foldl (\xs x -> [x:xs]) [] s
// | /O(n*min(n,W))/. Create a set from a list of integers.
fromList :: [Key] -> IntSet
fromList :: ![Key] -> IntSet
fromList xs
= 'StdList'.foldl ins empty xs
where
......
......@@ -79,7 +79,7 @@ unzip5 :: ![(.a,.b,.c,.d,.e)] -> ([.a],[.b],[.c],[.d],[.e])
* @result The original list, with all elements x for which p r x holds replaced by r
*/
replaceInList :: !(a a -> Bool) !a ![a] -> [a]
sortByIndex :: ![(!Int,!a)] -> [a]
sortByIndex :: ![(Int,a)] -> [a]
intersperse :: !a ![a] -> [a]