mini 1.6.1.0 → 1.6.2.0
raw patch · 34 files changed
+5144/−4988 lines, 34 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Mini.Random.Class: class Generator g
+ Mini.Random.Class: class Random a
+ Mini.Random.Class: instance Mini.Random.Class.Generator Mini.Hash.Murmur32.Hash32
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Int.Int16
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Int.Int32
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Int.Int64
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Int.Int8
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Num.Integer.Integer
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Types.Bool
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Types.Char
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Types.Double
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Types.Float
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Types.Int
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Types.Word
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Word.Word16
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Word.Word32
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Word.Word64
+ Mini.Random.Class: instance Mini.Random.Class.Random GHC.Word.Word8
+ Mini.Random.Class: nextWord32 :: Generator g => g -> (Word32, g)
+ Mini.Random.Class: nextWord64 :: Generator g => g -> (Word64, g)
+ Mini.Random.Class: random :: (Random a, Generator g) => g -> (a, g)
+ Mini.Random.Class: randoms :: (Random a, Generator g) => g -> [a]
Files
- CHANGELOG.md +4/−0
- LICENSE +1/−1
- Mini/Data/Array.hs +0/−83
- Mini/Data/Graph.hs +0/−429
- Mini/Data/Map.hs +0/−1486
- Mini/Data/Recursion.hs +0/−816
- Mini/Data/Set.hs +0/−1084
- Mini/Hash/Class.hs +0/−100
- Mini/Hash/Murmur32.hs +0/−136
- Mini/Optics/Lens.hs +0/−60
- Mini/Transformers/Class.hs +0/−23
- Mini/Transformers/EitherT.hs +0/−104
- Mini/Transformers/MaybeT.hs +0/−102
- Mini/Transformers/ParserT.hs +0/−296
- Mini/Transformers/ReaderT.hs +0/−85
- Mini/Transformers/StateT.hs +0/−94
- Mini/Transformers/WriterT.hs +0/−87
- mini.cabal +5/−2
- src/Mini/Data/Array.hs +83/−0
- src/Mini/Data/Graph.hs +429/−0
- src/Mini/Data/Map.hs +1486/−0
- src/Mini/Data/Recursion.hs +816/−0
- src/Mini/Data/Set.hs +1084/−0
- src/Mini/Hash/Class.hs +100/−0
- src/Mini/Hash/Murmur32.hs +136/−0
- src/Mini/Optics/Lens.hs +60/−0
- src/Mini/Random/Class.hs +149/−0
- src/Mini/Transformers/Class.hs +23/−0
- src/Mini/Transformers/EitherT.hs +104/−0
- src/Mini/Transformers/MaybeT.hs +102/−0
- src/Mini/Transformers/ParserT.hs +296/−0
- src/Mini/Transformers/ReaderT.hs +85/−0
- src/Mini/Transformers/StateT.hs +94/−0
- src/Mini/Transformers/WriterT.hs +87/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+1.6.2.0 [2026-05-01]+--------------------+* Create Mini.Random.Class: A pure interface for pseudorandom value generation+ 1.6.1.0 [2026-02-10] -------------------- * Create Mini.Hash.Class: The class of hashable types
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2023-2025 Victor Wallsten+Copyright (c) 2023-2026 Victor Wallsten Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
− Mini/Data/Array.hs
@@ -1,83 +0,0 @@--- | Curated re-export of immutable non-strict (boxed) arrays from "GHC.Arr"-module Mini.Data.Array (- -- * Type- Array,-- -- * Class- Ix (- inRange,- index,- range,- rangeSize,- unsafeIndex,- unsafeRangeSize- ),-- -- * Construction- accumArray,- array,- listArray,-- -- * Conversion- assocs,- elems,- indices,-- -- * Modification- (//),- accum,- ixmap,-- -- * Query- (!),- (!?),- bounds,- numElements,-) where--import Data.Bool (- bool,- )-import GHC.Arr (- Array,- Ix (- inRange,- index,- range,- rangeSize,- unsafeIndex,- unsafeRangeSize- ),- accum,- accumArray,- array,- assocs,- bounds,- elems,- indices,- ixmap,- listArray,- numElements,- unsafeAt,- (!),- (//),- )-import Prelude (- Maybe (- Just,- Nothing- ),- ($),- (.),- )--infixl 9 !?---- | The value at the given index in an array, unless out of range.-(!?) :: (Ix i) => Array i e -> i -> Maybe e-arr !? i =- let b = bounds arr- in bool- Nothing- (Just . unsafeAt arr $ unsafeIndex b i)- $ inRange b i
− Mini/Data/Graph.hs
@@ -1,429 +0,0 @@--- | A structure representing unique vertices and their interrelations-module Mini.Data.Graph (- -- * Type- Graph,- graph,-- -- * Algorithms- distance,- layers,- path,- reachable,- sort,-- -- * Construction- empty,- fromList,- singleton,-- -- * Modification- add,- connect,- disconnect,- remove,- transpose,-- -- * Query- assocs,- edges,- indegree,- indegrees,- lookup,- lookupGE,- lookupGT,- lookupLE,- lookupLT,- lookupMax,- lookupMin,- member,- outdegree,- outdegrees,- sinkMax,- sinkMin,- sinks,- sourceMax,- sourceMin,- sources,- vertices,-) where--import Data.Bifunctor (- second,- )-import Data.List (- unfoldr,- )-import Mini.Data.Map (- Map,- )-import qualified Mini.Data.Map as Map (- delete,- empty,- foldlWithKey,- foldrWithKey,- insertWith,- lookup,- lookupGE,- lookupGT,- lookupLE,- lookupLT,- lookupMax,- lookupMin,- member,- singleton,- toAscList,- unionWith,- )-import Mini.Data.Recursion (- bool,- maybe,- uncurry,- )-import Mini.Data.Set (- Set,- )-import qualified Mini.Data.Set as Set (- delete,- difference,- empty,- fromList,- member,- null,- singleton,- size,- toAscList,- )-import Prelude (- Bool,- Eq,- Foldable,- Int,- Maybe (- Just,- Nothing- ),- Monoid,- Ord,- Semigroup,- Show,- any,- compare,- concat,- flip,- fmap,- foldMap,- foldr,- fst,- mempty,- show,- ($),- (+),- (.),- (<$>),- (<>),- (==),- )---- Type---- | A graph with directed edges between vertices of type /a/-data Graph a- = Graph- (Map a (Set a))- (Map a (Set a))--instance (Eq a) => Eq (Graph a) where- (Graph _ oes1) == (Graph _ oes2) = oes1 == oes2--instance (Ord a) => Ord (Graph a) where- compare (Graph _ oes1) (Graph _ oes2) = compare oes1 oes2--instance (Show a) => Show (Graph a) where- show = show . assocs--instance Foldable Graph where- foldr f b = foldr f b . vertices--instance (Ord a) => Semigroup (Graph a) where- (Graph ies1 oes1) <> (Graph ies2 oes2) =- Graph- (Map.unionWith (<>) ies1 ies2)- (Map.unionWith (<>) oes1 oes2)--instance (Ord a) => Monoid (Graph a) where- mempty = empty---- | Primitive recursion on graphs (internally represented by adjacency lists)-graph- :: (Map a (Set a) -> Map a (Set a) -> b)- -- ^ Function applied to the adjacency lists of the graph:- -- incoming edges, outgoing edges- -> Graph a- -- ^ The graph- -> b-graph f (Graph ies oes) = f ies oes---- Algorithms---- | Get the shortest distance in a graph between a vertex and another-distance :: (Ord a) => Graph a -> a -> a -> Maybe Int-distance g s t =- foldr- (\a b -> bool ((+ 1) <$> b) (Just 0) $ t `Set.member` a)- Nothing- $ bfs g s---- | Breadth-first search for the hierarchy in a graph from a starting vertex-layers :: (Ord a) => Graph a -> a -> [[a]]-layers g = fmap Set.toAscList . bfs g---- | Check whether there is a path in a graph from a vertex to another-path :: (Ord a) => Graph a -> a -> a -> Bool-path g s t = any (t `Set.member`) $ bfs g s---- | Get the reachable vertices in a graph from a starting vertex-reachable :: (Ord a) => Graph a -> a -> [a]-reachable g = concat . layers g---- | Topologically sort a graph (assumes acyclicity)-sort :: (Ord a) => Graph a -> [a]-sort = unfoldr $ \g -> (\u -> (u, remove u g)) <$> sourceMin g---- Construction---- | The empty graph-empty :: Graph a-empty = Graph Map.empty Map.empty---- | Make a graph from a list of vertex associations-fromList :: (Ord a) => [(a, [a])] -> Graph a-fromList = foldr (uncurry connect) empty---- | Make a graph with an isolated vertex-singleton :: a -> Graph a-singleton u = Graph (Map.singleton u Set.empty) (Map.singleton u Set.empty)---- Modification---- | Add an isolated vertex to a graph unless already present-add :: (Ord a) => a -> Graph a -> Graph a-add u = connect u []---- | Add edges from a vertex to a list of vertices in a graph-connect :: (Ord a) => a -> [a] -> Graph a -> Graph a-connect u vs (Graph ies oes) =- uncurry Graph $- foldr- ( \v (ies', oes') ->- ( Map.insertWith (<>) v (Set.singleton u) ies'- , Map.insertWith (<>) v Set.empty oes'- )- )- ( Map.insertWith (<>) u Set.empty ies- , Map.insertWith (<>) u (Set.fromList vs) oes- )- vs---- | Remove edges from a vertex to a list of vertices in a graph-disconnect :: (Ord a) => a -> [a] -> Graph a -> Graph a-disconnect u vs (Graph ies oes) =- Graph- ( foldr- (\v -> Map.insertWith (flip Set.difference) v $ Set.singleton u)- ies- vs- )- (Map.insertWith (flip Set.difference) u (Set.fromList vs) oes)---- | Remove a vertex and its associations from a graph-remove :: (Ord a) => a -> Graph a -> Graph a-remove u (Graph ies oes) =- Graph- (Set.delete u <$> Map.delete u ies)- (Set.delete u <$> Map.delete u oes)---- | Reverse the edges of a graph-transpose :: Graph a -> Graph a-transpose (Graph ies oes) = Graph oes ies---- Query---- | Get the vertex associations of a graph-assocs :: Graph a -> [(a, [a])]-assocs (Graph _ oes) = second Set.toAscList <$> Map.toAscList oes---- | Get the edges of a graph-edges :: Graph a -> [(a, a)]-edges (Graph _ oes) =- Map.foldrWithKey- (\u -> flip $ foldr (\v -> (:) (u, v)))- []- oes---- | Get the number of incoming edges to a vertex in a graph-indegree :: (Ord a) => a -> Graph a -> Maybe Int-indegree v (Graph ies _) = Set.size <$> Map.lookup v ies---- | Get the number of incoming edges of each vertex in a graph-indegrees :: Graph a -> [(a, Int)]-indegrees (Graph ies _) = Map.toAscList $ Set.size <$> ies---- | Get the associations of a vertex from a graph-lookup :: (Ord a) => a -> Graph a -> Maybe [a]-lookup u (Graph _ oes) = Set.toAscList <$> Map.lookup u oes---- | Get the associations of the least vertex greater than or equal to a vertex-lookupGE :: (Ord a) => a -> Graph a -> Maybe (a, [a])-lookupGE a (Graph _ oes) = second Set.toAscList <$> Map.lookupGE a oes---- | Get the associations of the least vertex strictly greater than a vertex-lookupGT :: (Ord a) => a -> Graph a -> Maybe (a, [a])-lookupGT a (Graph _ oes) = second Set.toAscList <$> Map.lookupGT a oes---- | Get the associations of the greatest vertex less than or equal to a vertex-lookupLE :: (Ord a) => a -> Graph a -> Maybe (a, [a])-lookupLE a (Graph _ oes) = second Set.toAscList <$> Map.lookupLE a oes---- | Get the associations of the greatest vertex strictly less than a vertex-lookupLT :: (Ord a) => a -> Graph a -> Maybe (a, [a])-lookupLT a (Graph _ oes) = second Set.toAscList <$> Map.lookupLT a oes---- | Get the associations of the maximum vertex from a graph-lookupMax :: Graph a -> Maybe (a, [a])-lookupMax (Graph _ oes) = second Set.toAscList <$> Map.lookupMax oes---- | Get the associations of the minimum vertex from a graph-lookupMin :: Graph a -> Maybe (a, [a])-lookupMin (Graph _ oes) = second Set.toAscList <$> Map.lookupMin oes---- | Check whether a vertex is in a graph-member :: (Ord a) => a -> Graph a -> Bool-member u (Graph _ oes) = u `Map.member` oes---- | Get the number of outgoing edges from a vertex in a graph-outdegree :: (Ord a) => a -> Graph a -> Maybe Int-outdegree u (Graph _ oes) = Set.size <$> Map.lookup u oes---- | Get the number of outgoing edges of each vertex in a graph-outdegrees :: Graph a -> [(a, Int)]-outdegrees (Graph _ oes) = Map.toAscList $ Set.size <$> oes---- | Get the maximum vertex with no outgoing edges from a graph-sinkMax :: Graph a -> Maybe a-sinkMax (Graph _ oes) =- Map.foldlWithKey- ( \b k ->- bool- b- (Just k)- . Set.null- )- Nothing- oes---- | Get the minimum vertex with no outgoing edges from a graph-sinkMin :: Graph a -> Maybe a-sinkMin (Graph _ oes) =- Map.foldrWithKey- ( \k a b ->- bool- b- (Just k)- $ Set.null a- )- Nothing- oes---- | Get the vertices with no outgoing edges from a graph-sinks :: Graph a -> [a]-sinks (Graph _ oes) =- Map.foldrWithKey- ( \k a b ->- bool- b- (k : b)- $ Set.null a- )- []- oes---- | Get the maximum vertex with no incoming edges from a graph-sourceMax :: Graph a -> Maybe a-sourceMax (Graph ies _) =- Map.foldlWithKey- ( \b k ->- bool- b- (Just k)- . Set.null- )- Nothing- ies---- | Get the minimum vertex with no incoming edges from a graph-sourceMin :: Graph a -> Maybe a-sourceMin (Graph ies _) =- Map.foldrWithKey- ( \k a b ->- bool- b- (Just k)- $ Set.null a- )- Nothing- ies---- | Get the vertices with no incoming edges from a graph-sources :: Graph a -> [a]-sources (Graph ies _) =- Map.foldrWithKey- ( \k a b ->- bool- b- (k : b)- $ Set.null a- )- []- ies---- | Get the vertices of a graph-vertices :: Graph a -> [a]-vertices (Graph _ oes) = fst <$> Map.toAscList oes---- Helpers---- | Breadth-first search for the hierarchy in a graph from a starting vertex-bfs :: (Ord a) => Graph a -> a -> [Set a]-bfs (Graph _ oes) s =- foldMap- ( \vs ->- Set.singleton s- : unfoldr- ( \((us, es), ds) ->- bool- ( Just- ( us- ,- ( foldr- ( \u b@(us', es') ->- maybe- b- ( \vs' ->- ( (us' <> vs') `Set.difference` ds- , Map.delete u es'- )- )- $ Map.lookup u es- )- (Set.empty, es)- us- , ds <> us- )- )- )- Nothing- $ Set.null us- )- ((vs, oes), Set.singleton s)- )- $ Map.lookup s oes
− Mini/Data/Map.hs
@@ -1,1486 +0,0 @@-{-# LANGUAGE LambdaCase #-}--- incomplete patterns in 'fromDistinct{Asc,Desc}List'-{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}---- | A structure mapping unique keys to values-module Mini.Data.Map (- -- * Type- Map,- map,-- -- * Construction- empty,- fromAscList,- fromAscListWith,- fromAscListWithKey,- fromDescList,- fromDescListWith,- fromDescListWithKey,- fromDistinctAscList,- fromDistinctDescList,- fromList,- fromListWith,- fromListWithKey,- singleton,-- -- * Combination- compose,- difference,- differenceWith,- differenceWithKey,- intersection,- intersectionWith,- intersectionWithKey,- union,- unionWith,- unionWithKey,- unions,- unionsWith,- unionsWithKey,-- -- * Conversion- toAscList,- toDescList,-- -- * Fold- foldlWithKey,- foldrWithKey,-- -- * Modification- adjust,- adjustMax,- adjustMaxWithKey,- adjustMin,- adjustMinWithKey,- adjustWithKey,- delete,- deleteMax,- deleteMin,- filter,- filterWithKey,- insert,- insertWith,- insertWithKey,- update,- updateMax,- updateMaxWithKey,- updateMin,- updateMinWithKey,- updateWithKey,-- -- * Partition- partition,- partitionWithKey,- split,- splitMax,- splitMin,-- -- * Query- disjoint,- isSubmapOf,- isSubmapOfBy,- lookup,- lookupGE,- lookupGT,- lookupLE,- lookupLT,- lookupMax,- lookupMin,- member,- null,- size,-- -- * Traversal- fmapWithKey,- traverseWithKey,-- -- * Validation- valid,-) where--import Control.Applicative (- liftA2,- (<|>),- )-import Data.Bifunctor (- bimap,- first,- second,- )-import Data.Bool (- bool,- )-import Data.Function (- on,- )-import Mini.Data.Recursion (- list,- ordering,- )-import Prelude (- Applicative,- Bool (- False,- True- ),- Eq,- Foldable,- Functor,- Int,- Maybe (- Just,- Nothing- ),- Monoid,- Ord,- Semigroup,- Show,- Traversable,- compare,- const,- div,- error,- flip,- fmap,- foldl,- foldr,- fst,- length,- max,- maybe,- mempty,- not,- pure,- show,- splitAt,- traverse,- uncurry,- until,- ($),- (&&),- (*),- (+),- (-),- (.),- (<),- (<$>),- (<*>),- (<>),- (==),- (>),- (||),- )---- Type---- | A map from keys /k/ to values /a/, internally structured as an AVL tree-data Map k a- = -- | Empty bin- E- | -- | Left-heavy bin- L (Map k a) k a (Map k a)- | -- | Balanced bin- B (Map k a) k a (Map k a)- | -- | Right-heavy bin- R (Map k a) k a (Map k a)--instance (Eq k, Eq a) => Eq (Map k a) where- (==) = (==) `on` toAscList--instance (Ord k, Ord a) => Ord (Map k a) where- compare = compare `on` toAscList--instance (Show k, Show a) => Show (Map k a) where- show = show . toAscList--instance Functor (Map k) where- fmap = fmapWithKey . const--instance Foldable (Map k) where- foldr = foldrWithKey . const--instance Traversable (Map k) where- traverse = traverseWithKey . const--instance (Ord k) => Semigroup (Map k a) where- (<>) = union--instance (Ord k) => Monoid (Map k a) where- mempty = empty---- | Primitive recursion on maps (internally structured as trees)-map- :: b- -- ^ Value yielded in case of empty node- -> (Map k a -> k -> a -> Map k a -> b -> b -> b)- -- ^ Function applied in case of non-empty node:- -- left child, key, value, right child, left recursion, right recursion- -- (keys are lesser to the left, greater to the right)- -> Map k a- -- ^ Object of the case analysis- -> b-map e f = map' e f f f---- Primitive recursion on maps-map'- :: b- -- ^ Value yielded in case of empty node- -> (Map k a -> k -> a -> Map k a -> b -> b -> b)- -- ^ Function applied in case of left-heavy node:- -- left child, key, value, right child, left recursion, right recursion- -- (keys are lesser to the left, greater to the right)- -> (Map k a -> k -> a -> Map k a -> b -> b -> b)- -- ^ Function applied in case of balanced node:- -- left child, key, value, right child, left recursion, right recursion- -- (keys are lesser to the left, greater to the right)- -> (Map k a -> k -> a -> Map k a -> b -> b -> b)- -- ^ Function applied in case of right-heavy node:- -- left child, key, value, right child, left recursion, right recursion- -- (keys are lesser to the left, greater to the right)- -> Map k a- -- ^ Object of the case analysis- -> b-map' e f g h = \case- L l k a r -> f l k a r (map' e f g h l) (map' e f g h r)- R l k a r -> h l k a r (map' e f g h l) (map' e f g h r)- B l k a r -> g l k a r (map' e f g h l) (map' e f g h r)- E -> e---- Construction---- | /O(1)/ The empty map-empty :: Map k a-empty = E---- | /O(n)/ Make a map from a tail-biased list of key-sorted pairs-fromAscList :: (Eq k) => [(k, a)] -> Map k a-fromAscList = fromDistinctAscList . essence---- | /O(n)/ Make a map from a list of key-sorted pairs, combining matching keys-fromAscListWith :: (Ord k) => (a -> a -> a) -> [(k, a)] -> Map k a-fromAscListWith = fromAscListWithKey . const---- | /O(n)/ Make a map from a list of key-sorted pairs, combining matching keys-fromAscListWithKey :: (Ord k) => (k -> a -> a -> a) -> [(k, a)] -> Map k a-fromAscListWithKey f = fromDistinctAscList . essenceWithKey f---- | /O(n)/ Make a map from a tail-biased list of key-sorted pairs-fromDescList :: (Eq k) => [(k, a)] -> Map k a-fromDescList = fromDistinctDescList . essence---- | /O(n)/ Make a map from a list of key-sorted pairs, combining matching keys-fromDescListWith :: (Ord k) => (a -> a -> a) -> [(k, a)] -> Map k a-fromDescListWith = fromDescListWithKey . const---- | /O(n)/ Make a map from a list of key-sorted pairs, combining matching keys-fromDescListWithKey :: (Ord k) => (k -> a -> a -> a) -> [(k, a)] -> Map k a-fromDescListWithKey f = fromDistinctDescList . essenceWithKey f---- | /O(n)/ Make a map from a sorted list of key-distinct pairs-fromDistinctAscList :: [(k, a)] -> Map k a-fromDistinctAscList = go <*> power- where- go ps n = list E go' ps- where- go' (k, a) = const . list (B E k a E) go''- where- go'' _ _ _ =- let len = length ps- n' = n `div` 2- c = bool B L $ len == n- (l, (k', a') : r) = splitAt (len `div` 2) ps- in c (go l n') k' a' (go r n')---- | /O(n)/ Make a map from a sorted list of key-distinct pairs-fromDistinctDescList :: [(k, a)] -> Map k a-fromDistinctDescList = go <*> power- where- go ps n = list E go' ps- where- go' (k, a) = const . list (B E k a E) go''- where- go'' _ _ _ =- let len = length ps- n' = n `div` 2- c = bool B R $ len == n- (l, (k', a') : r) = splitAt (len `div` 2) ps- in c (go r n') k' a' (go l n')---- | /O(n log n)/ Make a map from a tail-biased list of @(key, value)@ pairs-fromList :: (Ord k) => [(k, a)] -> Map k a-fromList = fromListWithKey $ const const---- | /O(n log n)/ Make a map from a list of pairs, combining matching keys-fromListWith :: (Ord k) => (a -> a -> a) -> [(k, a)] -> Map k a-fromListWith = fromListWithKey . const---- | /O(n log n)/ Make a map from a list of pairs, combining matching keys-fromListWithKey :: (Ord k) => (k -> a -> a -> a) -> [(k, a)] -> Map k a-fromListWithKey f = foldl (flip . uncurry $ insertWithKey f) empty---- | /O(1)/ Make a map with a single bin-singleton :: k -> a -> Map k a-singleton k a = B E k a E---- Combination---- | /O(n log m)/ Compose the keys of one set with the values of another-compose :: (Ord b) => Map b c -> Map a b -> Map a c-compose t1 t2 = map' empty go go go t1- where- go _ _ _ _ _ _ =- fromDistinctAscList $- foldrWithKey- (\a b ac -> maybe ac (\c -> (a, c) : ac) $ lookup b t1)- []- t2---- | /O(m log n)/ Subtract a map by another via key matching-difference :: (Ord k) => Map k a -> Map k b -> Map k a-difference t1 t2 = map' empty go go go t1- where- go _ _ _ _ _ _ = foldrWithKey (\k _ b -> delete k b) t1 t2---- | /O(m log n)/ Subtract a map by another, updating bins of matching keys-differenceWith- :: (Ord k) => (a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a-differenceWith = differenceWithKey . const---- | /O(m log n)/ Subtract a map by another, updating bins of matching keys-differenceWithKey- :: (Ord k) => (k -> a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a-differenceWithKey f t1 t2 = map' empty go go go t1- where- go _ _ _ _ _ _ =- foldrWithKey- ( \k b t' ->- maybe- t'- ( \a ->- maybe- (delete' k t')- (\a' -> insert k a' t')- $ f k a b- )- $ lookup k t1- )- t1- t2---- | /O(n log m)/ Intersect a map with another via left-biased key matching-intersection :: (Ord k) => Map k a -> Map k b -> Map k a-intersection = intersectionWithKey $ const const---- | /O(n log m)/ Intersect a map with another by key matching, combining values-intersectionWith :: (Ord k) => (a -> b -> c) -> Map k a -> Map k b -> Map k c-intersectionWith = intersectionWithKey . const---- | /O(n log m)/ Intersect a map with another by key matching, combining values-intersectionWithKey- :: (Ord k) => (k -> a -> b -> c) -> Map k a -> Map k b -> Map k c-intersectionWithKey f t1 t2 = map' empty go go go t2- where- go _ _ _ _ _ _ =- fromDistinctAscList $- foldrWithKey- (\k a c -> maybe c (\b -> (k, f k a b) : c) $ lookup k t2)- []- t1---- | /O(m log n)/ Unite a map with another via left-biased key matching-union :: (Ord k) => Map k a -> Map k a -> Map k a-union = unionWithKey $ const const---- | /O(m log n)/ Unite a map with another, combining values of matching keys-unionWith :: (Ord k) => (a -> a -> a) -> Map k a -> Map k a -> Map k a-unionWith = unionWithKey . const---- | /O(m log n)/ Unite a map with another, combining values of matching keys-unionWithKey :: (Ord k) => (k -> a -> a -> a) -> Map k a -> Map k a -> Map k a-unionWithKey f t1 t2 = map' t1 go go go t2- where- go _ _ _ _ _ _ = foldrWithKey (insertWithKey f) t2 t1---- | Unite a collection of maps via left-biased key matching-unions :: (Foldable t, Ord k) => t (Map k a) -> Map k a-unions = unionsWithKey $ const const---- | Unite a collection of maps, combining values of matching keys-unionsWith :: (Foldable t, Ord k) => (a -> a -> a) -> t (Map k a) -> Map k a-unionsWith = unionsWithKey . const---- | Unite a collection of maps, combining values of matching keys-unionsWithKey :: (Foldable t, Ord k) => (k -> a -> a -> a) -> t (Map k a) -> Map k a-unionsWithKey f = foldr (unionWithKey f) empty---- Conversion---- | /O(n)/ Turn a map into a list of @(key, value)@ pairs in ascending order-toAscList :: Map k a -> [(k, a)]-toAscList = foldrWithKey (\k a b -> (k, a) : b) []---- | /O(n)/ Turn a map into a list of @(key, value)@ pairs in descending order-toDescList :: Map k a -> [(k, a)]-toDescList = foldlWithKey (\b k a -> (k, a) : b) []---- Fold---- | /O(n)/ Reduce a map with a left-associative operation and an accumulator-foldlWithKey :: (b -> k -> a -> b) -> b -> Map k a -> b-foldlWithKey f b = map' b go go go- where- go _ k a r recl _ = foldlWithKey f (f recl k a) r---- | /O(n)/ Reduce a map with a right-associative operation and an accumulator-foldrWithKey :: (k -> a -> b -> b) -> b -> Map k a -> b-foldrWithKey f b = map' b go go go- where- go l k a _ _ recr = foldrWithKey f (f k a recr) l---- Modification---- | /O(log n)/ Adjust with an operation the value of a key in a map-adjust :: (Ord k) => (a -> a) -> k -> Map k a -> Map k a-adjust = adjustWithKey . const---- | /O(log n)/ Adjust with an operation the value of the maximum key in a map-adjustMax :: (a -> a) -> Map k a -> Map k a-adjustMax = adjustMaxWithKey . const---- | /O(log n)/ Adjust with an operation the value of the maximum key in a map-adjustMaxWithKey :: (k -> a -> a) -> Map k a -> Map k a-adjustMaxWithKey f = map' E (go L) (go B) (go R)- where- go c l k a r _ recr = map' (c l k (f k a) r) go' go' go' r- where- go' _ _ _ _ _ _ = c l k a recr---- | /O(log n)/ Adjust with an operation the value of the minimum key in a map-adjustMin :: (a -> a) -> Map k a -> Map k a-adjustMin = adjustMinWithKey . const---- | /O(log n)/ Adjust with an operation the value of the minimum key in a map-adjustMinWithKey :: (k -> a -> a) -> Map k a -> Map k a-adjustMinWithKey f = map' E (go L) (go B) (go R)- where- go c l k a r recl _ = map' (c l k (f k a) r) go' go' go' l- where- go' _ _ _ _ _ _ = c recl k a r---- | /O(log n)/ Adjust with an operation the value of a key in a map-adjustWithKey :: (Ord k) => (k -> a -> a) -> k -> Map k a -> Map k a-adjustWithKey f k0 = map' E (go L) (go B) (go R)- where- go c l k a r recl recr =- ordering- (c recl k a r)- (c l k (f k a) r)- (c l k a recr)- $ compare k0 k---- | /O(log n)/ Delete a key from a map-delete :: (Ord k) => k -> Map k a -> Map k a-delete k t = bool t (delete' k t) $ k `member` t---- | /O(log n)/ Delete the maximum key from a map-deleteMax :: (Ord k) => Map k a -> Map k a-deleteMax t = maybe t (flip delete' t . fst) $ lookupMax t---- | /O(log n)/ Delete the minimum key from a map-deleteMin :: (Ord k) => Map k a -> Map k a-deleteMin t = maybe t (flip delete' t . fst) $ lookupMin t---- | /O(n)/ Keep the bins whose values satisfy a predicate-filter :: (a -> Bool) -> Map k a -> Map k a-filter = filterWithKey . const---- | /O(n)/ Keep the bins whose keys and values satisfy a predicate-filterWithKey :: (k -> a -> Bool) -> Map k a -> Map k a-filterWithKey p =- fromDistinctAscList- . foldrWithKey (\k a b -> bool b ((k, a) : b) $ p k a) []---- | /O(log n)/ Insert a key and its value into a map, overwriting if present-insert :: (Ord k) => k -> a -> Map k a -> Map k a-insert = insertWithKey $ const const---- | /O(log n)/ Insert a key and its value, combining new and old if present-insertWith :: (Ord k) => (a -> a -> a) -> k -> a -> Map k a -> Map k a-insertWith = insertWithKey . const---- | /O(log n)/ Modify the value of a key or delete its bin with an operation-update :: (Ord k) => (a -> Maybe a) -> k -> Map k a -> Map k a-update = updateWithKey . const---- | /O(log n)/ Modify the value of the maximum key or delete its bin-updateMax :: (Ord k) => (a -> Maybe a) -> Map k a -> Map k a-updateMax = updateMaxWithKey . const---- | /O(log n)/ Modify the value of the maximum key or delete its bin-updateMaxWithKey :: (Ord k) => (k -> a -> Maybe a) -> Map k a -> Map k a-updateMaxWithKey f t =- maybe- t- ( \(k, a) ->- maybe- (delete' k t)- (\a' -> insert k a' t)- $ f k a- )- $ lookupMax t---- | /O(log n)/ Modify the value of the minimum key or delete its bin-updateMin :: (Ord k) => (a -> Maybe a) -> Map k a -> Map k a-updateMin = updateMinWithKey . const---- | /O(log n)/ Modify the value of the minimum key or delete its bin-updateMinWithKey :: (Ord k) => (k -> a -> Maybe a) -> Map k a -> Map k a-updateMinWithKey f t =- maybe- t- ( \(k, a) ->- maybe- (delete' k t)- (\a' -> insert k a' t)- $ f k a- )- $ lookupMin t---- | /O(log n)/ Modify the value of a key or delete its bin with an operation-updateWithKey :: (Ord k) => (k -> a -> Maybe a) -> k -> Map k a -> Map k a-updateWithKey f k t =- maybe- t- ( maybe- (delete' k t)- (\a' -> insert k a' t)- . f k- )- $ lookup k t---- Partition---- | /O(n)/ Partition a map with a predicate into @(true, false)@ submaps-partition :: (a -> Bool) -> Map k a -> (Map k a, Map k a)-partition = partitionWithKey . const---- | /O(n)/ Partition a map with a predicate into @(true, false)@ submaps-partitionWithKey :: (k -> a -> Bool) -> Map k a -> (Map k a, Map k a)-partitionWithKey p =- bimap fromDistinctAscList fromDistinctAscList- . foldrWithKey- (\k a -> bool second first (p k a) ((k, a) :))- ([], [])---- | /O(n)/ Split a map by a key into @(lt, eq, gt)@ submaps-split :: (Ord k) => k -> Map k a -> (Map k a, Maybe a, Map k a)-split k0 =- (\(lt, a, gt) -> (fromDistinctAscList lt, a, fromDistinctAscList gt))- . foldrWithKey- ( \k a (lt, a', gt) ->- ordering- ((k, a) : lt, a', gt)- (lt, Just a, gt)- (lt, a', (k, a) : gt)- $ compare k k0- )- ([], Nothing, [])---- | /O(log n)/ Split a map by its maximum key-splitMax :: (Ord k) => Map k a -> Maybe ((k, a), Map k a)-splitMax t = ((,) <*> flip delete' t . fst) <$> lookupMax t---- | /O(log n)/ Split a map by its minimum key-splitMin :: (Ord k) => Map k a -> Maybe ((k, a), Map k a)-splitMin t = ((,) <*> flip delete' t . fst) <$> lookupMin t---- Query---- | /O(m log n)/ Check whether two maps have no keys in common-disjoint :: (Ord k) => Map k a -> Map k a -> Bool-disjoint t1 t2 = map' True go go go t1- where- go _ _ _ _ _ _ = not $ foldrWithKey (\k _ b -> k `member` t1 || b) False t2---- | /O(n log m)/ Check whether the bins of one map exist in the other-isSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool-isSubmapOf = isSubmapOfBy (==)---- | /O(n log m)/ Check if the bins of one map exist in the other by combination-isSubmapOfBy :: (Ord k) => (a -> b -> Bool) -> Map k a -> Map k b -> Bool-isSubmapOfBy p t1 t2 = map' (null t1) go go go t2- where- go _ _ _ _ _ _ =- foldrWithKey- (\k a b -> maybe False ((&& b) . p a) $ lookup k t2)- True- t1---- | /O(log n)/ Fetch the value of a key in a map-lookup :: (Ord k) => k -> Map k a -> Maybe a-lookup k = map' Nothing go go go- where- go _ k' a _ recl recr =- ordering- recl- (Just a)- recr- $ compare k k'---- | /O(log n)/ Fetch the least bin greater than or equal to a key-lookupGE :: (Ord k) => k -> Map k a -> Maybe (k, a)-lookupGE k0 = map' Nothing go go go- where- go _ k a _ recl recr =- ordering- recr- (Just (k, a))- (recl <|> Just (k, a))- $ compare k k0---- | /O(log n)/ Fetch the least bin strictly greater than a key-lookupGT :: (Ord k) => k -> Map k a -> Maybe (k, a)-lookupGT k0 = map' Nothing go go go- where- go _ k a _ recl recr =- ordering- recr- recr- (recl <|> Just (k, a))- $ compare k k0---- | /O(log n)/ Fetch the greatest bin less than or equal to a key-lookupLE :: (Ord k) => k -> Map k a -> Maybe (k, a)-lookupLE k0 = map' Nothing go go go- where- go _ k a _ recl recr =- ordering- (recr <|> Just (k, a))- (Just (k, a))- recl- $ compare k k0---- | /O(log n)/ Fetch the greatest bin strictly less than a key-lookupLT :: (Ord k) => k -> Map k a -> Maybe (k, a)-lookupLT k0 = map' Nothing go go go- where- go _ k a _ recl recr =- ordering- (recr <|> Just (k, a))- recl- recl- $ compare k k0---- | /O(log n)/ Fetch the bin with the maximum key-lookupMax :: Map k a -> Maybe (k, a)-lookupMax = map' Nothing go go go- where- go _ k a r _ recr = map' (Just (k, a)) go' go' go' r- where- go' _ _ _ _ _ _ = recr---- | /O(log n)/ Fetch the bin with the minimum key-lookupMin :: Map k a -> Maybe (k, a)-lookupMin = map' Nothing go go go- where- go l k a _ recl _ = map' (Just (k, a)) go' go' go' l- where- go' _ _ _ _ _ _ = recl---- | /O(log n)/ Check whether a key is in a map-member :: (Ord k) => k -> Map k a -> Bool-member k0 = map' False go go go- where- go _ k _ _ recl recr =- ordering- recl- True- recr- $ compare k0 k---- | /O(1)/ Check whether a map is empty-null :: Map k a -> Bool-null = map' True go go go where go _ _ _ _ _ _ = False---- | /O(n)/ Get the size of a map-size :: Map k a -> Int-size = map' 0 go go go where go _ _ _ _ recl recr = 1 + recl + recr---- Traversal---- | /O(n)/ Apply an operation across a map, transforming its values-fmapWithKey :: (k -> a -> b) -> Map k a -> Map k b-fmapWithKey f = map' E (go L) (go B) (go R)- where- go c _ k a _ recl = c recl k (f k a)---- | /O(n)/ Lift a map with a lifting operation on keys and values-traverseWithKey :: (Applicative f) => (k -> a -> f b) -> Map k a -> f (Map k b)-traverseWithKey f = map' (pure E) (go L) (go B) (go R)- where- go c _ k a _ recl recr = c <$> recl <*> pure k <*> f k a <*> recr---- Validation---- | /O(n^2)/ Check whether a map is internally height-balanced and ordered-valid :: (Ord k) => Map k a -> Bool-valid = liftA2 (&&) balanced ordered- where- balanced =- map'- True- (\l _ _ r recl recr -> levels l - levels r == 1 && recl && recr)- (\l _ _ r recl recr -> levels l - levels r == 0 && recl && recr)- (\l _ _ r recl recr -> levels r - levels l == 1 && recl && recr)- levels = map' 0 go go go- where- go _ _ _ _ recl recr = 1 + max recl recr :: Int- ordered = map' True go go go- where- go l k _ r recl recr =- map' True lt lt lt l- && map' True gt gt gt r- where- lt _ lk _ _ _ _ = lk < k && recl && recr- gt _ rk _ _ _ _ = rk > k && recl && recr---- Helpers---- O(n) 'nub' on keys for sorted lists of pairs-essence :: (Eq k) => [(k, a)] -> [(k, a)]-essence = list [] go- where- go p1@(k1, _) ps rec = list [p1] go' ps- where- go' (k2, _) _ _ = bool (p1 : rec) rec $ k1 == k2---- O(n) 'nub' with a combining function for sorted lists of pairs-essenceWithKey :: (Eq k) => (k -> a -> a -> a) -> [(k, a)] -> [(k, a)]-essenceWithKey f = list [] (\p -> const . go p)- where- go p1@(k1, a1) = list [p1] go'- where- go' p2@(k2, a2) ps _ =- bool- (p1 : go p2 ps)- (go (k1, f k1 a2 a1) ps)- $ k1 == k2---- O(log n) The greatest power of 2 <= the length of a non-empty collection-power :: (Foldable t) => t a -> Int-power as = until (> length as) (* 2) 2 `div` 2--{-- - Let this comment serve as your warning. Return from whence you came and your- - sanity will be spared. You have been admonished.- -}---- O(log n) Delete a key from a map without checking for membership-delete' :: (Ord k) => k -> Map k a -> Map k a-delete' k0 =- map'- (error "Map.delete: L0")- ( \l k a r _ _ ->- ordering- (deleteLl l k a r)- (substituteL l r)- (deleteLr l k a r)- $ compare k0 k- )- ( \l k a r _ _ ->- ordering- (deleteBl l k a r)- (substituteBr l r)- (deleteBr l k a r)- $ compare k0 k- )- ( \l k a r _ _ ->- ordering- (deleteRl l k a r)- (substituteR l r)- (deleteRr l k a r)- $ compare k0 k- )- where- deleteRl l k a r =- map'- (error "Map.delete: L1")- ( \ll lk la lr _ _ ->- ordering- (checkLeftR (deleteLl ll lk la lr) k a r)- (checkLeftR (substituteL ll lr) k a r)- (checkLeftR (deleteLr ll lk la lr) k a r)- $ compare k0 lk- )- ( \ll lk la lr _ _ ->- ordering- (R (deleteBl ll lk la lr) k a r)- (checkLeftR' (substituteBr ll lr) k a r)- (R (deleteBr ll lk la lr) k a r)- $ compare k0 lk- )- ( \ll lk la lr _ _ ->- ordering- (checkLeftR (deleteRl ll lk la lr) k a r)- (checkLeftR (substituteR ll lr) k a r)- (checkLeftR (deleteRr ll lk la lr) k a r)- $ compare k0 lk- )- l- deleteRr l k a =- map'- (error "Map.delete: L2")- ( \rl rk ra rr _ _ ->- ordering- (checkRightR l k a $ deleteLl rl rk ra rr)- (checkRightR l k a $ substituteL rl rr)- (checkRightR l k a $ deleteLr rl rk ra rr)- $ compare k0 rk- )- ( \rl rk ra rr _ _ ->- ordering- (R l k a $ deleteBl rl rk ra rr)- (checkRightR' l k a $ substituteBl rl rr)- (R l k a $ deleteBr rl rk ra rr)- $ compare k0 rk- )- ( \rl rk ra rr _ _ ->- ordering- (checkRightR l k a $ deleteRl rl rk ra rr)- (checkRightR l k a $ substituteR rl rr)- (checkRightR l k a $ deleteRr rl rk ra rr)- $ compare k0 rk- )- deleteBl l k a r =- map'- (error "Map.delete: L3")- ( \ll lk la lr _ _ ->- ordering- (checkLeftB (deleteLl ll lk la lr) k a r)- (checkLeftB (substituteL ll lr) k a r)- (checkLeftB (deleteLr ll lk la lr) k a r)- $ compare k0 lk- )- ( \ll lk la lr _ _ ->- ordering- (B (deleteBl ll lk la lr) k a r)- (checkLeftB' (substituteBr ll lr) k a r)- (B (deleteBr ll lk la lr) k a r)- $ compare k0 lk- )- ( \ll lk la lr _ _ ->- ordering- (checkLeftB (deleteRl ll lk la lr) k a r)- (checkLeftB (substituteR ll lr) k a r)- (checkLeftB (deleteRr ll lk la lr) k a r)- $ compare k0 lk- )- l- deleteBr l k a =- map'- (error "Map.delete: L4")- ( \rl rk ra rr _ _ ->- ordering- (checkRightB l k a $ deleteLl rl rk ra rr)- (checkRightB l k a $ substituteL rl rr)- (checkRightB l k a $ deleteLr rl rk ra rr)- $ compare k0 rk- )- ( \rl rk ra rr _ _ ->- ordering- (B l k a $ deleteBl rl rk ra rr)- (checkRightB' l k a $ substituteBl rl rr)- (B l k a $ deleteBr rl rk ra rr)- $ compare k0 rk- )- ( \rl rk ra rr _ _ ->- ordering- (checkRightB l k a $ deleteRl rl rk ra rr)- (checkRightB l k a $ substituteR rl rr)- (checkRightB l k a $ deleteRr rl rk ra rr)- $ compare k0 rk- )- deleteLl l k a r =- map'- (error "Map.delete: L5")- ( \ll lk la lr _ _ ->- ordering- (checkLeftL (deleteLl ll lk la lr) k a r)- (checkLeftL (substituteL ll lr) k a r)- (checkLeftL (deleteLr ll lk la lr) k a r)- $ compare k0 lk- )- ( \ll lk la lr _ _ ->- ordering- (L (deleteBl ll lk la lr) k a r)- (checkLeftL' (substituteBr ll lr) k a r)- (L (deleteBr ll lk la lr) k a r)- $ compare k0 lk- )- ( \ll lk la lr _ _ ->- ordering- (checkLeftL (deleteRl ll lk la lr) k a r)- (checkLeftL (substituteR ll lr) k a r)- (checkLeftL (deleteRr ll lk la lr) k a r)- $ compare k0 lk- )- l- deleteLr l k a =- map'- (error "Map.delete: L6")- ( \rl rk ra rr _ _ ->- ordering- (checkRightL l k a $ deleteLl rl rk ra rr)- (checkRightL l k a $ substituteL rl rr)- (checkRightL l k a $ deleteLr rl rk ra rr)- $ compare k0 rk- )- ( \rl rk ra rr _ _ ->- ordering- (L l k a $ deleteBl rl rk ra rr)- (checkRightL' l k a $ substituteBl rl rr)- (L l k a $ deleteBr rl rk ra rr)- $ compare k0 rk- )- ( \rl rk ra rr _ _ ->- ordering- (checkRightL l k a $ deleteRl rl rk ra rr)- (checkRightL l k a $ substituteR rl rr)- (checkRightL l k a $ deleteRr rl rk ra rr)- $ compare k0 rk- )- rebalanceR l k a =- map'- (error "Map.delete: L7")- ( \rl rk ra rr _ _ ->- map'- (error "Map.delete: L8")- (\rll rlk rla rlr _ _ -> B (B l k a rll) rlk rla $ R rlr rk ra rr)- (\rll rlk rla rlr _ _ -> B (B l k a rll) rlk rla $ B rlr rk ra rr)- (\rll rlk rla rlr _ _ -> B (L l k a rll) rlk rla $ B rlr rk ra rr)- rl- )- (\rl rk ra rr _ _ -> L (R l k a rl) rk ra rr)- (\rl rk ra rr _ _ -> B (B l k a rl) rk ra rr)- rebalanceL l k a r =- map'- (error "Map.delete: L9")- (\ll lk la lr _ _ -> B ll lk la $ B lr k a r)- (\ll lk la lr _ _ -> R ll lk la $ L lr k a r)- ( \ll lk la lr _ _ ->- map'- (error "Map.delete: L10")- (\lrl lrk lra lrr _ _ -> B (B ll lk la lrl) lrk lra $ R lrr k a r)- (\lrl lrk lra lrr _ _ -> B (B ll lk la lrl) lrk lra $ B lrr k a r)- (\lrl lrk lra lrr _ _ -> B (L ll lk la lrl) lrk lra $ B lrr k a r)- lr- )- l- checkLeftR l k a r =- map'- (error "Map.delete: L11")- (\_ _ _ _ _ _ -> R l k a r)- (\_ _ _ _ _ _ -> rebalanceR l k a r)- (\_ _ _ _ _ _ -> R l k a r)- l- checkLeftB l k a r =- map'- (error "Map.delete: L12")- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> R l k a r)- (\_ _ _ _ _ _ -> B l k a r)- l- checkLeftL l k a r =- map'- (error "Map.delete: L13")- (\_ _ _ _ _ _ -> L l k a r)- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> L l k a r)- l- checkRightR l k a r =- map'- (error "Map.delete: L14")- (\_ _ _ _ _ _ -> R l k a r)- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> R l k a r)- r- checkRightB l k a r =- map'- (error "Map.delete: L15")- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> L l k a r)- (\_ _ _ _ _ _ -> B l k a r)- r- checkRightL l k a r =- map'- (error "Map.delete: L16")- (\_ _ _ _ _ _ -> L l k a r)- (\_ _ _ _ _ _ -> rebalanceL l k a r)- (\_ _ _ _ _ _ -> L l k a r)- r- substituteR l =- map'- (error "Map.delete: L17")- ( \rl rk ra rr _ _ ->- (\(k, a, r) -> checkRightR l k a r) $- popLeftL rl rk ra rr- )- ( \rl rk ra rr _ _ ->- (\(k, a, r) -> checkRightR' l k a r) $- popLeftB rl rk ra rr- )- ( \rl rk ra rr _ _ ->- (\(k, a, r) -> checkRightR l k a r) $- popLeftR rl rk ra rr- )- substituteBr l =- map'- E- ( \rl rk ra rr _ _ ->- (\(k, a, r) -> checkRightB l k a r) $- popLeftL rl rk ra rr- )- ( \rl rk ra rr _ _ ->- (\(k, a, r) -> checkRightB' l k a r) $- popLeftB rl rk ra rr- )- ( \rl rk ra rr _ _ ->- (\(k, a, r) -> checkRightB l k a r) $- popLeftR rl rk ra rr- )- substituteBl l r =- map'- E- ( \ll lk la lr _ _ ->- (\(l', k, a) -> checkLeftB l' k a r) $- popRightL ll lk la lr- )- ( \ll lk la lr _ _ ->- (\(l', k, a) -> checkLeftB' l' k a r) $- popRightB ll lk la lr- )- ( \ll lk la lr _ _ ->- (\(l', k, a) -> checkLeftB l' k a r) $- popRightR ll lk la lr- )- l- substituteL l r =- map'- (error "Map.delete: L18")- ( \ll lk la lr _ _ ->- (\(l', k, a) -> checkLeftL l' k a r) $- popRightL ll lk la lr- )- ( \ll lk la lr _ _ ->- (\(l', k, a) -> checkLeftL' l' k a r) $- popRightB ll lk la lr- )- ( \ll lk la lr _ _ ->- (\(l', k, a) -> checkLeftL l' k a r) $- popRightR ll lk la lr- )- l- checkLeftR' l k a r =- map'- (rebalanceR l k a r)- (\_ _ _ _ _ _ -> R l k a r)- (\_ _ _ _ _ _ -> R l k a r)- (\_ _ _ _ _ _ -> R l k a r)- l- checkLeftB' l k a r =- map'- (R l k a r)- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> B l k a r)- l- checkLeftL' l k a r =- map'- (B l k a r)- (\_ _ _ _ _ _ -> L l k a r)- (\_ _ _ _ _ _ -> L l k a r)- (\_ _ _ _ _ _ -> L l k a r)- l- checkRightR' l k a r =- map'- (B l k a r)- (\_ _ _ _ _ _ -> R l k a r)- (\_ _ _ _ _ _ -> R l k a r)- (\_ _ _ _ _ _ -> R l k a r)- r- checkRightB' l k a r =- map'- (L l k a r)- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> B l k a r)- r- checkRightL' l k a r =- map'- (rebalanceL l k a r)- (\_ _ _ _ _ _ -> L l k a r)- (\_ _ _ _ _ _ -> L l k a r)- (\_ _ _ _ _ _ -> L l k a r)- r- popLeftR l k a r =- map'- (k, a, r)- ( \ll lk la lr _ _ ->- (\(k', a', l') -> (k', a', checkLeftR l' k a r)) $- popLeftL ll lk la lr- )- (\ll lk la lr _ _ -> popLeftRB ll lk la lr k a r)- ( \ll lk la lr _ _ ->- (\(k', a', l') -> (k', a', checkLeftR l' k a r)) $- popLeftR ll lk la lr- )- l- popLeftB l k a r =- map'- (k, a, E)- (\ll lk la lr _ _ -> popLeftBL ll lk la lr k a r)- (\ll lk la lr _ _ -> popLeftBB ll lk la lr k a r)- (\ll lk la lr _ _ -> popLeftBR ll lk la lr k a r)- l- popLeftL l k a r =- map'- (error "Map.delete: L19")- ( \ll lk la lr _ _ ->- (\(k', a', l') -> (k', a', checkLeftL l' k a r)) $- popLeftL ll lk la lr- )- (\ll lk la lr _ _ -> popLeftLB ll lk la lr k a r)- ( \ll lk la lr _ _ ->- (\(k', a', l') -> (k', a', checkLeftL l' k a r)) $- popLeftR ll lk la lr- )- l- popLeftRB ll lk la lr k a r =- map'- (lk, la, rebalanceR E k a r)- ( \lll llk lla llr _ _ ->- (\(k', a', l) -> (k', a', R l k a r)) $- popLeftBL lll llk lla llr lk la lr- )- ( \lll llk lla llr _ _ ->- (\(k', a', l) -> (k', a', R l k a r)) $- popLeftBB lll llk lla llr lk la lr- )- ( \lll llk lla llr _ _ ->- (\(k', a', l) -> (k', a', R l k a r)) $- popLeftBR lll llk lla llr lk la lr- )- ll- popLeftBB ll lk la lr k a r =- map'- (lk, la, R E k a r)- ( \lll llk lla llr _ _ ->- (\(k', a', l) -> (k', a', B l k a r)) $- popLeftBL lll llk lla llr lk la lr- )- ( \lll llk lla llr _ _ ->- (\(k', a', l) -> (k', a', B l k a r)) $- popLeftBB lll llk lla llr lk la lr- )- ( \lll llk lla llr _ _ ->- (\(k', a', l) -> (k', a', B l k a r)) $- popLeftBR lll llk lla llr lk la lr- )- ll- popLeftLB ll lk la lr k a r =- map'- (lk, la, B E k a E)- ( \lll llk lla llr _ _ ->- (\(k', a', l) -> (k', a', L l k a r)) $- popLeftBL lll llk lla llr lk la lr- )- ( \lll llk lla llr _ _ ->- (\(k', a', l) -> (k', a', L l k a r)) $- popLeftBB lll llk lla llr lk la lr- )- ( \lll llk lla llr _ _ ->- (\(k', a', l) -> (k', a', L l k a r)) $- popLeftBR lll llk lla llr lk la lr- )- ll- popLeftBR ll lk la lr k a r =- (\(k', a', l) -> (k', a', checkLeftB l k a r)) $- popLeftR ll lk la lr- popLeftBL ll lk la lr k a r =- (\(k', a', l) -> (k', a', checkLeftB l k a r)) $- popLeftL ll lk la lr- popRightR l k a =- map'- (error "Map.delete: L20")- ( \rl rk ra rr _ _ ->- (\(r, k', a') -> (checkRightR l k a r, k', a')) $- popRightL rl rk ra rr- )- (\rl rk ra rr _ _ -> popRightRB l k a rl rk ra rr)- ( \rl rk ra rr _ _ ->- (\(r, k', a') -> (checkRightR l k a r, k', a')) $- popRightR rl rk ra rr- )- popRightB l k a =- map'- (E, k, a)- (\rl rk ra rr _ _ -> popRightBL l k a rl rk ra rr)- (\rl rk ra rr _ _ -> popRightBB l k a rl rk ra rr)- (\rl rk ra rr _ _ -> popRightBR l k a rl rk ra rr)- popRightL l k a =- map'- (l, k, a)- ( \rl rk ra rr _ _ ->- (\(r, k', a') -> (checkRightL l k a r, k', a')) $- popRightL rl rk ra rr- )- (\rl rk ra rr _ _ -> popRightLB l k a rl rk ra rr)- ( \rl rk ra rr _ _ ->- (\(r, k', a') -> (checkRightL l k a r, k', a')) $- popRightR rl rk ra rr- )- popRightRB l k a rl rk ra =- map'- (B E k a E, rk, ra)- ( \rrl rrk rra rrr _ _ ->- (\(r, k', a') -> (R l k a r, k', a')) $- popRightBL rl rk ra rrl rrk rra rrr- )- ( \rrl rrk rra rrr _ _ ->- (\(r, k', a') -> (R l k a r, k', a')) $- popRightBB rl rk ra rrl rrk rra rrr- )- ( \rrl rrk rra rrr _ _ ->- (\(r, k', a') -> (R l k a r, k', a')) $- popRightBR rl rk ra rrl rrk rra rrr- )- popRightBB l k a rl rk ra =- map'- (L l k a E, rk, ra)- ( \rrl rrk rra rrr _ _ ->- (\(r, k', a') -> (B l k a r, k', a')) $- popRightBL rl rk ra rrl rrk rra rrr- )- ( \rrl rrk rra rrr _ _ ->- (\(r, k', a') -> (B l k a r, k', a')) $- popRightBB rl rk ra rrl rrk rra rrr- )- ( \rrl rrk rra rrr _ _ ->- (\(r, k', a') -> (B l k a r, k', a')) $- popRightBR rl rk ra rrl rrk rra rrr- )- popRightLB l k a rl rk ra =- map'- (rebalanceL l k a E, rk, ra)- ( \rrl rrk rra rrr _ _ ->- (\(r, k', a') -> (L l k a r, k', a')) $- popRightBL rl rk ra rrl rrk rra rrr- )- ( \rrl rrk rra rrr _ _ ->- (\(r, k', a') -> (L l k a r, k', a')) $- popRightBB rl rk ra rrl rrk rra rrr- )- ( \rrl rrk rra rrr _ _ ->- (\(r, k', a') -> (L l k a r, k', a')) $- popRightBR rl rk ra rrl rrk rra rrr- )- popRightBR l k a rl rk ra rr =- (\(r, k', a') -> (checkRightB l k a r, k', a')) $- popRightR rl rk ra rr- popRightBL l k a rl rk ra rr =- (\(r, k', a') -> (checkRightB l k a r, k', a')) $- popRightL rl rk ra rr---- | /O(log n)/ Insert a key and its value, combining new and old if present-insertWithKey :: (Ord k) => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a-insertWithKey f k0 a0 =- map'- (B E k0 a0 E)- (\l k a r _ _ -> insertL l k a r)- (\l k a r _ _ -> insertB l k a r)- (\l k a r _ _ -> insertR l k a r)- where- insertR l k a r =- ordering- (insertRl l k a r)- (R l k (f k a0 a) r)- (insertRr l k a r)- $ compare k0 k- insertB l k a r =- ordering- (insertBl l k a r)- (B l k (f k a0 a) r)- (insertBr l k a r)- $ compare k0 k- insertL l k a r =- ordering- (insertLl l k a r)- (L l k (f k a0 a) r)- (insertLr l k a r)- $ compare k0 k- insertRl l k a r =- map'- (B (B E k0 a0 E) k a r)- (\ll lk la lr _ _ -> R (insertL ll lk la lr) k a r)- ( \ll lk la lr _ _ ->- let l' = insertB ll lk la lr- in map'- (error "Map.insert: L0")- (\_ _ _ _ _ _ -> B l' k a r)- (\_ _ _ _ _ _ -> R l' k a r)- (\_ _ _ _ _ _ -> B l' k a r)- l'- )- (\ll lk la lr _ _ -> R (insertR ll lk la lr) k a r)- l- insertBl l k a r =- map'- (L (B E k0 a0 E) k a r)- (\ll lk la lr _ _ -> B (insertL ll lk la lr) k a r)- ( \ll lk la lr _ _ ->- let l' = insertB ll lk la lr- in map'- (error "Map.insert: L1")- (\_ _ _ _ _ _ -> L l' k a r)- (\_ _ _ _ _ _ -> B l' k a r)- (\_ _ _ _ _ _ -> L l' k a r)- l'- )- (\ll lk la lr _ _ -> B (insertR ll lk la lr) k a r)- l- insertBr l k a =- map'- (R l k a $ B E k0 a0 E)- (\rl rk ra rr _ _ -> B l k a $ insertL rl rk ra rr)- ( \rl rk ra rr _ _ ->- let r = insertB rl rk ra rr- in map'- (error "Map.insert: L2")- (\_ _ _ _ _ _ -> R l k a r)- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> R l k a r)- r- )- (\rl rk ra rr _ _ -> B l k a $ insertR rl rk ra rr)- insertLr l k a =- map'- (B l k a $ B E k0 a0 E)- (\rl rk ra rr _ _ -> L l k a $ insertL rl rk ra rr)- ( \rl rk ra rr _ _ ->- let r = insertB rl rk ra rr- in map'- (error "Map.insert: L3")- (\_ _ _ _ _ _ -> B l k a r)- (\_ _ _ _ _ _ -> L l k a r)- (\_ _ _ _ _ _ -> B l k a r)- r- )- (\rl rk ra rr _ _ -> L l k a $ insertR rl rk ra rr)- insertRr l k a =- map'- (error "Map.insert: L4")- (\rl rk ra rr _ _ -> R l k a $ insertL rl rk ra rr)- ( \rl rk ra rr _ _ ->- ordering- (insertRrl l k a rl rk ra rr)- (R l k a $ B rl rk (f rk a0 ra) rr)- (insertRrr l k a rl rk ra rr)- $ compare k0 rk- )- (\rl rk ra rr _ _ -> R l k a $ insertR rl rk ra rr)- insertLl l k a r =- map'- (error "Map.insert: L5")- (\ll lk la lr _ _ -> L (insertL ll lk la lr) k a r)- ( \ll lk la lr _ _ ->- ordering- (insertLll ll lk la lr k a r)- (L (B ll lk (f lk a0 la) lr) k a r)- (insertLlr ll lk la lr k a r)- $ compare k0 lk- )- (\ll lk la lr _ _ -> L (insertR ll lk la lr) k a r)- l- insertRrr l k a rl rk ra =- map'- (B (B l k a rl) rk ra $ B E k0 a0 E)- (\rrl rrk rra rrr _ _ -> R l k a . B rl rk ra $ insertL rrl rrk rra rrr)- ( \rrl rrk rra rrr _ _ ->- let rr = insertB rrl rrk rra rrr- in map'- (error "Map.insert: L6")- (\_ _ _ _ _ _ -> B (B l k a rl) rk ra rr)- (\_ _ _ _ _ _ -> R l k a $ B rl rk ra rr)- (\_ _ _ _ _ _ -> B (B l k a rl) rk ra rr)- rr- )- (\rrl rrk rra rrr _ _ -> R l k a . B rl rk ra $ insertR rrl rrk rra rrr)- insertLll ll lk la lr k a r =- map'- (B (B E k0 a0 E) lk la $ B lr k a r)- (\lll llk lla llr _ _ -> L (B (insertL lll llk lla llr) lk la lr) k a r)- ( \lll llk lla llr _ _ ->- let ll' = insertB lll llk lla llr- in map'- (error "Map.insert: L7")- (\_ _ _ _ _ _ -> B ll' lk la $ B lr k a r)- (\_ _ _ _ _ _ -> L (B ll' lk la lr) k a r)- (\_ _ _ _ _ _ -> B ll' lk la $ B lr k a r)- ll'- )- (\lll llk lla llr _ _ -> L (B (insertR lll llk lla llr) lk la lr) k a r)- ll- insertRrl l k a rl rk ra rr =- map'- (B (B l k a E) k0 a0 $ B E rk ra rr)- (\rll rlk rla rlr _ _ -> R l k a $ B (insertL rll rlk rla rlr) rk ra rr)- ( \rll rlk rla rlr _ _ ->- let rl' = insertB rll rlk rla rlr- in map'- (error "Map.insert: L8")- ( \rll' rlk' rla' rlr' _ _ ->- B- (B l k a rll')- rlk'- rla'- (R rlr' rk ra rr)- )- (\_ _ _ _ _ _ -> R l k a $ B rl' rk ra rr)- ( \rll' rlk' rla' rlr' _ _ ->- B- (L l k a rll')- rlk'- rla'- (B rlr' rk ra rr)- )- rl'- )- (\rll rlk rla rlr _ _ -> R l k a $ B (insertR rll rlk rla rlr) rk ra rr)- rl- insertLlr ll lk la lr k a r =- map'- (B (B ll lk la E) k0 a0 $ B E k a r)- (\lrl lrk lra lrr _ _ -> L (B ll lk la $ insertL lrl lrk lra lrr) k a r)- ( \lrl lrk lra lrr _ _ ->- let lr' = insertB lrl lrk lra lrr- in map'- (error "Map.insert: L9")- ( \lrl' lrk' lra' lrr' _ _ ->- B- (B ll lk la lrl')- lrk'- lra'- (R lrr' k a r)- )- (\_ _ _ _ _ _ -> L (B ll lk la lr') k a r)- ( \lrl' lrk' lra' lrr' _ _ ->- B- (L ll lk la lrl')- lrk'- lra'- (B lrr' k a r)- )- lr'- )- (\lrl lrk lra lrr _ _ -> L (B ll lk la $ insertR lrl lrk lra lrr) k a r)- lr
− Mini/Data/Recursion.hs
@@ -1,816 +0,0 @@-{-# LANGUAGE LambdaCase #-}---- | Primitive recursive functions on basic data structures-module Mini.Data.Recursion (- -- * Re-exports- bool,- either,- maybe,- uncurry,-- -- * Lists- list,- nonEmpty,-- -- * Orderings- ordering,-- -- * n-Tuples (3 to 64)- uncurry3,- uncurry4,- uncurry5,- uncurry6,- uncurry7,- uncurry8,- uncurry9,- uncurry10,- uncurry11,- uncurry12,- uncurry13,- uncurry14,- uncurry15,- uncurry16,- uncurry17,- uncurry18,- uncurry19,- uncurry20,- uncurry21,- uncurry22,- uncurry23,- uncurry24,- uncurry25,- uncurry26,- uncurry27,- uncurry28,- uncurry29,- uncurry30,- uncurry31,- uncurry32,- uncurry33,- uncurry34,- uncurry35,- uncurry36,- uncurry37,- uncurry38,- uncurry39,- uncurry40,- uncurry41,- uncurry42,- uncurry43,- uncurry44,- uncurry45,- uncurry46,- uncurry47,- uncurry48,- uncurry49,- uncurry50,- uncurry51,- uncurry52,- uncurry53,- uncurry54,- uncurry55,- uncurry56,- uncurry57,- uncurry58,- uncurry59,- uncurry60,- uncurry61,- uncurry62,- uncurry63,- uncurry64,-) where--import Data.Bool (- Bool,- )-import qualified Data.Bool as Bool (- bool,- )-import Data.Either (- Either,- )-import qualified Data.Either as Either (- either,- )-import Data.List.NonEmpty (- NonEmpty (- (:|)- ),- )-import Data.Maybe (- Maybe,- )-import qualified Data.Maybe as Maybe (- maybe,- )-import Data.Ord (- Ordering (- EQ,- GT,- LT- ),- )-import qualified Data.Tuple as Tuple (- uncurry,- )---- Re-exports---- | Primitive recursion on bools-bool- :: a- -- ^ Value yielded in case of 'Bool.False'- -> a- -- ^ Value yielded in case of 'Bool.True'- -> Bool- -- ^ Object of the case analysis- -> a-bool = Bool.bool---- | Primitive recursion on eithers-either- :: (a -> c)- -- ^ Function applied to @a@ in case of @'Either.Left' a@- -> (b -> c)- -- ^ Function applied to @b@ in case of @'Either.Right' b@- -> Either a b- -- ^ Object of the case analysis- -> c-either = Either.either---- | Primitive recursion on maybes-maybe- :: b- -- ^ Value yielded in case of 'Maybe.Nothing'- -> (a -> b)- -- ^ Function applied to @a@ in case of @'Maybe.Just' a@- -> Maybe a- -- ^ Object of the case analysis- -> b-maybe = Maybe.maybe---- | Primitive recursion on 2-tuples-uncurry- :: (t1 -> t2 -> t3)- -- ^ Function applied to the elements of the 2-tuple- -> (t1, t2)- -- ^ The 2-tuple- -> t3-uncurry = Tuple.uncurry---- Lists---- | Primitive recursion on lists-list- :: b- -- ^ Value yielded in case of empty list- -> (a -> [a] -> b -> b)- -- ^ Function applied in case of non-empty list: head, tail, recursion- -> [a]- -- ^ Object of the case analysis- -> b-list e f = \case- a : as -> f a as (list e f as)- [] -> e---- | Primitive recursion on non-empty lists-nonEmpty- :: (a -> [a] -> b)- -- ^ Function applied to the head and tail of the non-empty list- -> NonEmpty a- -- ^ The non-empty list- -> b-nonEmpty f (a :| as) = f a as---- Orderings---- | Primitive recursion on orderings-ordering- :: a- -- ^ Value yielded in case of 'LT'- -> a- -- ^ Value yielded in case of 'EQ'- -> a- -- ^ Value yielded in case of 'GT'- -> Ordering- -- ^ Object of the case analysis- -> a-ordering lt eq gt = \case- LT -> lt- GT -> gt- EQ -> eq---- n-Tuples (3 to 64)---- | Primitive recursion on 3-tuples-uncurry3- :: (t1 -> t2 -> t3 -> t4)- -- ^ Function applied to the elements of the 3-tuple- -> (t1, t2, t3)- -- ^ The 3-tuple- -> t4-uncurry3 f (t1, t2, t3) = f t1 t2 t3---- | Primitive recursion on 4-tuples-uncurry4- :: (t1 -> t2 -> t3 -> t4 -> t5)- -- ^ Function applied to the elements of the 4-tuple- -> (t1, t2, t3, t4)- -- ^ The 4-tuple- -> t5-uncurry4 f (t1, t2, t3, t4) = f t1 t2 t3 t4---- | Primitive recursion on 5-tuples-uncurry5- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6)- -- ^ Function applied to the elements of the 5-tuple- -> (t1, t2, t3, t4, t5)- -- ^ The 5-tuple- -> t6-uncurry5 f (t1, t2, t3, t4, t5) = f t1 t2 t3 t4 t5---- | Primitive recursion on 6-tuples-uncurry6- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7)- -- ^ Function applied to the elements of the 6-tuple- -> (t1, t2, t3, t4, t5, t6)- -- ^ The 6-tuple- -> t7-uncurry6 f (t1, t2, t3, t4, t5, t6) = f t1 t2 t3 t4 t5 t6---- | Primitive recursion on 7-tuples-uncurry7- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8)- -- ^ Function applied to the elements of the 7-tuple- -> (t1, t2, t3, t4, t5, t6, t7)- -- ^ The 7-tuple- -> t8-uncurry7 f (t1, t2, t3, t4, t5, t6, t7) = f t1 t2 t3 t4 t5 t6 t7---- | Primitive recursion on 8-tuples-uncurry8- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9)- -- ^ Function applied to the elements of the 8-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8)- -- ^ The 8-tuple- -> t9-uncurry8 f (t1, t2, t3, t4, t5, t6, t7, t8) = f t1 t2 t3 t4 t5 t6 t7 t8---- | Primitive recursion on 9-tuples-uncurry9- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10)- -- ^ Function applied to the elements of the 9-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9)- -- ^ The 9-tuple- -> t10-uncurry9 f (t1, t2, t3, t4, t5, t6, t7, t8, t9) = f t1 t2 t3 t4 t5 t6 t7 t8 t9---- | Primitive recursion on 10-tuples-uncurry10- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11)- -- ^ Function applied to the elements of the 10-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)- -- ^ The 10-tuple- -> t11-uncurry10 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10---- | Primitive recursion on 11-tuples-uncurry11- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12)- -- ^ Function applied to the elements of the 11-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11)- -- ^ The 11-tuple- -> t12-uncurry11 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11---- | Primitive recursion on 12-tuples-uncurry12- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13)- -- ^ Function applied to the elements of the 12-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12)- -- ^ The 12-tuple- -> t13-uncurry12 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12---- | Primitive recursion on 13-tuples-uncurry13- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14)- -- ^ Function applied to the elements of the 13-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13)- -- ^ The 13-tuple- -> t14-uncurry13 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13---- | Primitive recursion on 14-tuples-uncurry14- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15)- -- ^ Function applied to the elements of the 14-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14)- -- ^ The 14-tuple- -> t15-uncurry14 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14---- | Primitive recursion on 15-tuples-uncurry15- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16)- -- ^ Function applied to the elements of the 15-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15)- -- ^ The 15-tuple- -> t16-uncurry15 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15---- | Primitive recursion on 16-tuples-uncurry16- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17)- -- ^ Function applied to the elements of the 16-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16)- -- ^ The 16-tuple- -> t17-uncurry16 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16---- | Primitive recursion on 17-tuples-uncurry17- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18)- -- ^ Function applied to the elements of the 17-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17)- -- ^ The 17-tuple- -> t18-uncurry17 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17---- | Primitive recursion on 18-tuples-uncurry18- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19)- -- ^ Function applied to the elements of the 18-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18)- -- ^ The 18-tuple- -> t19-uncurry18 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18---- | Primitive recursion on 19-tuples-uncurry19- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20)- -- ^ Function applied to the elements of the 19-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19)- -- ^ The 19-tuple- -> t20-uncurry19 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19---- | Primitive recursion on 20-tuples-uncurry20- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21)- -- ^ Function applied to the elements of the 20-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20)- -- ^ The 20-tuple- -> t21-uncurry20 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20---- | Primitive recursion on 21-tuples-uncurry21- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22)- -- ^ Function applied to the elements of the 21-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21)- -- ^ The 21-tuple- -> t22-uncurry21 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21---- | Primitive recursion on 22-tuples-uncurry22- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23)- -- ^ Function applied to the elements of the 22-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22)- -- ^ The 22-tuple- -> t23-uncurry22 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22---- | Primitive recursion on 23-tuples-uncurry23- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24)- -- ^ Function applied to the elements of the 23-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23)- -- ^ The 23-tuple- -> t24-uncurry23 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23---- | Primitive recursion on 24-tuples-uncurry24- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25)- -- ^ Function applied to the elements of the 24-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24)- -- ^ The 24-tuple- -> t25-uncurry24 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24---- | Primitive recursion on 25-tuples-uncurry25- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26)- -- ^ Function applied to the elements of the 25-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25)- -- ^ The 25-tuple- -> t26-uncurry25 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25---- | Primitive recursion on 26-tuples-uncurry26- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27)- -- ^ Function applied to the elements of the 26-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26)- -- ^ The 26-tuple- -> t27-uncurry26 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26---- | Primitive recursion on 27-tuples-uncurry27- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28)- -- ^ Function applied to the elements of the 27-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27)- -- ^ The 27-tuple- -> t28-uncurry27 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27---- | Primitive recursion on 28-tuples-uncurry28- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29)- -- ^ Function applied to the elements of the 28-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28)- -- ^ The 28-tuple- -> t29-uncurry28 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28---- | Primitive recursion on 29-tuples-uncurry29- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30)- -- ^ Function applied to the elements of the 29-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29)- -- ^ The 29-tuple- -> t30-uncurry29 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29---- | Primitive recursion on 30-tuples-uncurry30- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31)- -- ^ Function applied to the elements of the 30-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30)- -- ^ The 30-tuple- -> t31-uncurry30 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30---- | Primitive recursion on 31-tuples-uncurry31- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32)- -- ^ Function applied to the elements of the 31-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31)- -- ^ The 31-tuple- -> t32-uncurry31 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31---- | Primitive recursion on 32-tuples-uncurry32- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33)- -- ^ Function applied to the elements of the 32-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32)- -- ^ The 32-tuple- -> t33-uncurry32 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32---- | Primitive recursion on 33-tuples-uncurry33- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34)- -- ^ Function applied to the elements of the 33-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33)- -- ^ The 33-tuple- -> t34-uncurry33 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33---- | Primitive recursion on 34-tuples-uncurry34- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35)- -- ^ Function applied to the elements of the 34-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34)- -- ^ The 34-tuple- -> t35-uncurry34 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34---- | Primitive recursion on 35-tuples-uncurry35- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36)- -- ^ Function applied to the elements of the 35-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35)- -- ^ The 35-tuple- -> t36-uncurry35 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35---- | Primitive recursion on 36-tuples-uncurry36- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37)- -- ^ Function applied to the elements of the 36-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36)- -- ^ The 36-tuple- -> t37-uncurry36 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36---- | Primitive recursion on 37-tuples-uncurry37- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38)- -- ^ Function applied to the elements of the 37-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37)- -- ^ The 37-tuple- -> t38-uncurry37 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37---- | Primitive recursion on 38-tuples-uncurry38- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39)- -- ^ Function applied to the elements of the 38-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38)- -- ^ The 38-tuple- -> t39-uncurry38 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38---- | Primitive recursion on 39-tuples-uncurry39- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40)- -- ^ Function applied to the elements of the 39-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39)- -- ^ The 39-tuple- -> t40-uncurry39 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39---- | Primitive recursion on 40-tuples-uncurry40- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41)- -- ^ Function applied to the elements of the 40-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40)- -- ^ The 40-tuple- -> t41-uncurry40 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40---- | Primitive recursion on 41-tuples-uncurry41- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42)- -- ^ Function applied to the elements of the 41-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41)- -- ^ The 41-tuple- -> t42-uncurry41 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41---- | Primitive recursion on 42-tuples-uncurry42- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43)- -- ^ Function applied to the elements of the 42-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42)- -- ^ The 42-tuple- -> t43-uncurry42 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42---- | Primitive recursion on 43-tuples-uncurry43- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44)- -- ^ Function applied to the elements of the 43-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43)- -- ^ The 43-tuple- -> t44-uncurry43 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43---- | Primitive recursion on 44-tuples-uncurry44- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45)- -- ^ Function applied to the elements of the 44-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44)- -- ^ The 44-tuple- -> t45-uncurry44 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44---- | Primitive recursion on 45-tuples-uncurry45- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46)- -- ^ Function applied to the elements of the 45-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45)- -- ^ The 45-tuple- -> t46-uncurry45 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45---- | Primitive recursion on 46-tuples-uncurry46- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47)- -- ^ Function applied to the elements of the 46-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46)- -- ^ The 46-tuple- -> t47-uncurry46 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46---- | Primitive recursion on 47-tuples-uncurry47- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48)- -- ^ Function applied to the elements of the 47-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47)- -- ^ The 47-tuple- -> t48-uncurry47 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47---- | Primitive recursion on 48-tuples-uncurry48- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49)- -- ^ Function applied to the elements of the 48-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48)- -- ^ The 48-tuple- -> t49-uncurry48 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48---- | Primitive recursion on 49-tuples-uncurry49- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50)- -- ^ Function applied to the elements of the 49-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49)- -- ^ The 49-tuple- -> t50-uncurry49 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49---- | Primitive recursion on 50-tuples-uncurry50- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51)- -- ^ Function applied to the elements of the 50-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50)- -- ^ The 50-tuple- -> t51-uncurry50 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50---- | Primitive recursion on 51-tuples-uncurry51- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52)- -- ^ Function applied to the elements of the 51-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51)- -- ^ The 51-tuple- -> t52-uncurry51 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51---- | Primitive recursion on 52-tuples-uncurry52- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53)- -- ^ Function applied to the elements of the 52-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52)- -- ^ The 52-tuple- -> t53-uncurry52 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52---- | Primitive recursion on 53-tuples-uncurry53- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54)- -- ^ Function applied to the elements of the 53-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53)- -- ^ The 53-tuple- -> t54-uncurry53 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53---- | Primitive recursion on 54-tuples-uncurry54- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55)- -- ^ Function applied to the elements of the 54-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54)- -- ^ The 54-tuple- -> t55-uncurry54 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54---- | Primitive recursion on 55-tuples-uncurry55- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56)- -- ^ Function applied to the elements of the 55-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55)- -- ^ The 55-tuple- -> t56-uncurry55 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55---- | Primitive recursion on 56-tuples-uncurry56- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57)- -- ^ Function applied to the elements of the 56-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56)- -- ^ The 56-tuple- -> t57-uncurry56 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56---- | Primitive recursion on 57-tuples-uncurry57- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58)- -- ^ Function applied to the elements of the 57-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57)- -- ^ The 57-tuple- -> t58-uncurry57 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57---- | Primitive recursion on 58-tuples-uncurry58- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59)- -- ^ Function applied to the elements of the 58-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58)- -- ^ The 58-tuple- -> t59-uncurry58 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58---- | Primitive recursion on 59-tuples-uncurry59- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60)- -- ^ Function applied to the elements of the 59-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59)- -- ^ The 59-tuple- -> t60-uncurry59 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59---- | Primitive recursion on 60-tuples-uncurry60- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61)- -- ^ Function applied to the elements of the 60-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60)- -- ^ The 60-tuple- -> t61-uncurry60 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60---- | Primitive recursion on 61-tuples-uncurry61- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61 -> t62)- -- ^ Function applied to the elements of the 61-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61)- -- ^ The 61-tuple- -> t62-uncurry61 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60 t61---- | Primitive recursion on 62-tuples-uncurry62- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61 -> t62 -> t63)- -- ^ Function applied to the elements of the 62-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62)- -- ^ The 62-tuple- -> t63-uncurry62 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60 t61 t62---- | Primitive recursion on 63-tuples-uncurry63- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61 -> t62 -> t63 -> t64)- -- ^ Function applied to the elements of the 63-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63)- -- ^ The 63-tuple- -> t64-uncurry63 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60 t61 t62 t63---- | Primitive recursion on 64-tuples-uncurry64- :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61 -> t62 -> t63 -> t64 -> t65)- -- ^ Function applied to the elements of the 64-tuple- -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63, t64)- -- ^ The 64-tuple- -> t65-uncurry64 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63, t64) =- f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60 t61 t62 t63 t64
− Mini/Data/Set.hs
@@ -1,1084 +0,0 @@-{-# LANGUAGE LambdaCase #-}--- incomplete patterns in 'from{Asc,Desc}List'-{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}---- | A structure containing unique elements-module Mini.Data.Set (- -- * Type- Set,- set,-- -- * Construction- empty,- fromAscList,- fromDescList,- fromDistinctAscList,- fromDistinctDescList,- fromList,- singleton,-- -- * Combination- difference,- intersection,- union,- unions,-- -- * Conversion- toAscList,- toDescList,-- -- * Modification- delete,- deleteMax,- deleteMin,- filter,- insert,-- -- * Partition- partition,- split,- splitMax,- splitMin,-- -- * Query- disjoint,- isSubsetOf,- lookupGE,- lookupGT,- lookupLE,- lookupLT,- lookupMax,- lookupMin,- member,- null,- size,-- -- * Validation- valid,-) where--import Control.Applicative (- liftA2,- (<|>),- )-import Data.Bifunctor (- bimap,- first,- second,- )-import Data.Bool (- bool,- )-import Data.Function (- on,- )-import Mini.Data.Recursion (- list,- ordering,- )-import Prelude (- Bool (- False,- True- ),- Eq,- Foldable,- Int,- Maybe (- Just,- Nothing- ),- Monoid,- Ord,- Semigroup,- Show,- all,- any,- compare,- const,- div,- error,- flip,- foldl,- foldr,- length,- max,- maybe,- mempty,- not,- show,- splitAt,- uncurry,- until,- ($),- (&&),- (*),- (+),- (-),- (.),- (<),- (<$>),- (<*>),- (<>),- (==),- (>),- )---- Type---- | A set containing elements of type /a/, internally structured as an AVL tree-data Set a- = -- | Empty node- E- | -- | Left-heavy node- L (Set a) a (Set a)- | -- | Balanced node- B (Set a) a (Set a)- | -- | Right-heavy node- R (Set a) a (Set a)--instance (Eq a) => Eq (Set a) where- (==) = (==) `on` toAscList--instance (Ord a) => Ord (Set a) where- compare = compare `on` toAscList--instance (Show a) => Show (Set a) where- show = show . toAscList--instance Foldable Set where- foldr f b = set' b go go go- where- go l a _ _ recr = foldr f (f a recr) l--instance (Ord a) => Semigroup (Set a) where- (<>) = union--instance (Ord a) => Monoid (Set a) where- mempty = empty---- | Primitive recursion on sets (internally structured as trees)-set- :: b- -- ^ Value yielded in case of empty node- -> (Set a -> a -> Set a -> b -> b -> b)- -- ^ Function applied in case of non-empty node:- -- left child, element, right child, left recursion, right recursion- -- (elements are lesser to the left, greater to the right)- -> Set a- -- ^ Object of the case analysis- -> b-set e f = set' e f f f---- Primitive recursion on sets-set'- :: b- -- ^ Value yielded in case of empty node- -> (Set a -> a -> Set a -> b -> b -> b)- -- ^ Function applied in case of left-heavy node:- -- left child, element, right child, left recursion, right recursion- -- (elements are lesser to the left, greater to the right)- -> (Set a -> a -> Set a -> b -> b -> b)- -- ^ Function applied in case of balanced node:- -- left child, element, right child, left recursion, right recursion- -- (elements are lesser to the left, greater to the right)- -> (Set a -> a -> Set a -> b -> b -> b)- -- ^ Function applied in case of right-heavy node:- -- left child, element, right child, left recursion, right recursion- -- (elements are lesser to the left, greater to the right)- -> Set a- -- ^ Object of the case analysis- -> b-set' e f g h = \case- L l a r -> f l a r (set' e f g h l) (set' e f g h r)- R l a r -> h l a r (set' e f g h l) (set' e f g h r)- B l a r -> g l a r (set' e f g h l) (set' e f g h r)- E -> e---- Construction---- | /O(1)/ The empty set-empty :: Set a-empty = E---- | /O(n)/ Make a set from a sorted list of elements-fromAscList :: (Eq a) => [a] -> Set a-fromAscList = fromDistinctAscList . essence---- | /O(n)/ Make a set from a sorted list of elements-fromDescList :: (Eq a) => [a] -> Set a-fromDescList = fromDistinctDescList . essence---- | /O(n)/ Make a set from a sorted list of distinct elements-fromDistinctAscList :: [a] -> Set a-fromDistinctAscList = go <*> power- where- go as n = list E go' as- where- go' a = const . list (B E a E) go''- where- go'' _ _ _ =- let len = length as- n' = n `div` 2- c = bool B L $ len == n- (l, a' : r) = splitAt (len `div` 2) as- in c (go l n') a' (go r n')---- | /O(n)/ Make a set from a sorted list of distinct elements-fromDistinctDescList :: [a] -> Set a-fromDistinctDescList = go <*> power- where- go as n = list E go' as- where- go' a = const . list (B E a E) go''- where- go'' _ _ _ =- let len = length as- n' = n `div` 2- c = bool B R $ len == n- (l, a' : r) = splitAt (len `div` 2) as- in c (go r n') a' (go l n')---- | /O(n log n)/ Make a set from a list of elements-fromList :: (Ord a) => [a] -> Set a-fromList = foldl (flip insert) empty---- | /O(1)/ Make a set with a single element-singleton :: a -> Set a-singleton a = B E a E---- Combination---- | /O(m log n)/ Subtract a set by another-difference :: (Ord a) => Set a -> Set a -> Set a-difference t1 t2 = set' empty go go go t1- where- go _ _ _ _ _ = foldr delete t1 t2---- | /O(m log n)/ Intersect a set with another-intersection :: (Ord a) => Set a -> Set a -> Set a-intersection t1 t2 = set' empty go go go t2- where- go _ _ _ _ _ =- fromDistinctAscList $- foldr- (\a b -> bool b (a : b) $ a `member` t2)- []- t1---- | /O(m log n)/ Unite a set with another-union :: (Ord a) => Set a -> Set a -> Set a-union t1 t2 = set' t2 go go go t1- where- go _ _ _ _ _ = foldr insert t1 t2---- | Unite a collection of sets-unions :: (Foldable t, Ord a) => t (Set a) -> Set a-unions = foldr union empty---- Conversion---- | /O(n)/ Turn a set into a list of elements in ascending order-toAscList :: Set a -> [a]-toAscList = foldr (:) []---- | /O(n)/ Turn a set into a list of elements in descending order-toDescList :: Set a -> [a]-toDescList = foldl (flip (:)) []---- Modification---- | /O(log n)/ Delete an element from a set-delete :: (Ord a) => a -> Set a -> Set a-delete a t = bool t (delete' a t) $ a `member` t---- | /O(log n)/ Delete the maximum element from a set-deleteMax :: (Ord a) => Set a -> Set a-deleteMax t = maybe t (`delete'` t) $ lookupMax t---- | /O(log n)/ Delete the minimum element from a set-deleteMin :: (Ord a) => Set a -> Set a-deleteMin t = maybe t (`delete'` t) $ lookupMin t---- | /O(n)/ Keep the elements satisfying a predicate-filter :: (a -> Bool) -> Set a -> Set a-filter p = fromDistinctAscList . foldr (\a b -> bool b (a : b) $ p a) []---- | /O(log n)/ Insert an element into a set-insert :: (Ord a) => a -> Set a -> Set a-insert a t = bool (insert' a t) t $ a `member` t---- Partition---- | /O(n)/ Partition a set with a predicate into @(true, false)@ subsets-partition :: (a -> Bool) -> Set a -> (Set a, Set a)-partition p =- bimap fromDistinctAscList fromDistinctAscList- . foldr- (\a -> bool second first (p a) (a :))- ([], [])---- | /O(n)/ Split a set by an element into @(lt, eq, gt)@ subsets-split :: (Ord a) => a -> Set a -> (Set a, Bool, Set a)-split a0 =- (\(lt, a, gt) -> (fromDistinctAscList lt, a, fromDistinctAscList gt))- . foldr- ( \a (lt, a', gt) ->- ordering- (a : lt, a', gt)- (lt, True, gt)- (lt, a', a : gt)- $ compare a a0- )- ([], False, [])---- | /O(log n)/ Split a set by its maximum element-splitMax :: (Ord a) => Set a -> Maybe (a, Set a)-splitMax t = ((,) <*> flip delete' t) <$> lookupMax t---- | /O(log n)/ Split a set by its minimum element-splitMin :: (Ord a) => Set a -> Maybe (a, Set a)-splitMin t = ((,) <*> flip delete' t) <$> lookupMin t---- Query---- | /O(m log n)/ Check whether two sets have no elements in common-disjoint :: (Ord a) => Set a -> Set a -> Bool-disjoint t1 t2 = set' True go go go t1- where- go _ _ _ _ _ = not $ any (`member` t1) t2---- | /O(n log m)/ Check whether the elements of a set exist in the other-isSubsetOf :: (Ord a) => Set a -> Set a -> Bool-isSubsetOf t1 t2 = set' (null t1) go go go t2- where- go _ _ _ _ _ = all (`member` t2) t1---- | /O(log n)/ Fetch the least element greater than or equal to the given one-lookupGE :: (Ord a) => a -> Set a -> Maybe a-lookupGE a0 = set' Nothing go go go- where- go _ a _ recl recr =- ordering- recr- (Just a)- (recl <|> Just a)- $ compare a a0---- | /O(log n)/ Fetch the least element strictly greater than the given one-lookupGT :: (Ord a) => a -> Set a -> Maybe a-lookupGT a0 = set' Nothing go go go- where- go _ a _ recl recr =- ordering- recr- recr- (recl <|> Just a)- $ compare a a0---- | /O(log n)/ Fetch the greatest element less than or equal to the given one-lookupLE :: (Ord a) => a -> Set a -> Maybe a-lookupLE a0 = set' Nothing go go go- where- go _ a _ recl recr =- ordering- (recr <|> Just a)- (Just a)- recl- $ compare a a0---- | /O(log n)/ Fetch the greatest element strictly less than the given one-lookupLT :: (Ord a) => a -> Set a -> Maybe a-lookupLT a0 = set' Nothing go go go- where- go _ a _ recl recr =- ordering- (recr <|> Just a)- recl- recl- $ compare a a0---- | /O(log n)/ Fetch the maximum element-lookupMax :: Set a -> Maybe a-lookupMax = set' Nothing go go go- where- go _ a r _ recr = set' (Just a) go' go' go' r- where- go' _ _ _ _ _ = recr---- | /O(log n)/ Fetch the minimum element-lookupMin :: Set a -> Maybe a-lookupMin = set' Nothing go go go- where- go l a _ recl _ = set' (Just a) go' go' go' l- where- go' _ _ _ _ _ = recl---- | /O(log n)/ Check whether an element is in a set-member :: (Ord a) => a -> Set a -> Bool-member a0 = set' False go go go- where- go _ a _ recl recr =- ordering- recl- True- recr- $ compare a0 a---- | /O(1)/ Check whether a set is empty-null :: Set a -> Bool-null = set' True go go go where go _ _ _ _ _ = False---- | /O(n)/ Get the size of a set-size :: Set a -> Int-size = set' 0 go go go where go _ _ _ recl recr = 1 + recl + recr---- Validation---- | /O(n^2)/ Check whether a set is internally height-balanced and ordered-valid :: (Ord a) => Set a -> Bool-valid = liftA2 (&&) balanced ordered- where- balanced =- set'- True- (\l _ r recl recr -> levels l - levels r == 1 && recl && recr)- (\l _ r recl recr -> levels l - levels r == 0 && recl && recr)- (\l _ r recl recr -> levels r - levels l == 1 && recl && recr)- levels = set' 0 go go go- where- go _ _ _ recl recr = 1 + max recl recr :: Int- ordered = set' True go go go- where- go l a r recl recr =- set' True lt lt lt l- && set' True gt gt gt r- where- lt _ la _ _ _ = la < a && recl && recr- gt _ ra _ _ _ = ra > a && recl && recr---- Helpers---- O(n) 'nub' for sorted lists-essence :: (Eq a) => [a] -> [a]-essence = list [] go- where- go a1 as rec = list [a1] go' as- where- go' a2 _ _ = bool (a1 : rec) rec $ a1 == a2---- The greatest power of 2 <= the length of a non-empty collection-power :: (Foldable t) => t a -> Int-power as = until (> length as) (* 2) 2 `div` 2--{-- - Let this comment serve as your warning. Return from whence you came and your- - sanity will be spared. You have been admonished.- -}---- O(log n) Delete an element from a set without checking for membership-delete' :: (Ord a) => a -> Set a -> Set a-delete' a0 =- set'- (error "Set.delete: L0")- ( \l a r _ _ ->- ordering- (deleteLl l a r)- (substituteL l r)- (deleteLr l a r)- $ compare a0 a- )- ( \l a r _ _ ->- ordering- (deleteBl l a r)- (substituteBr l r)- (deleteBr l a r)- $ compare a0 a- )- ( \l a r _ _ ->- ordering- (deleteRl l a r)- (substituteR l r)- (deleteRr l a r)- $ compare a0 a- )- where- deleteRl l a r =- set'- (error "Set.delete: L1")- ( \ll la lr _ _ ->- ordering- (checkLeftR (deleteLl ll la lr) a r)- (checkLeftR (substituteL ll lr) a r)- (checkLeftR (deleteLr ll la lr) a r)- $ compare a0 la- )- ( \ll la lr _ _ ->- ordering- (R (deleteBl ll la lr) a r)- (checkLeftR' (substituteBr ll lr) a r)- (R (deleteBr ll la lr) a r)- $ compare a0 la- )- ( \ll la lr _ _ ->- ordering- (checkLeftR (deleteRl ll la lr) a r)- (checkLeftR (substituteR ll lr) a r)- (checkLeftR (deleteRr ll la lr) a r)- $ compare a0 la- )- l- deleteRr l a =- set'- (error "Set.delete: L2")- ( \rl ra rr _ _ ->- ordering- (checkRightR l a $ deleteLl rl ra rr)- (checkRightR l a $ substituteL rl rr)- (checkRightR l a $ deleteLr rl ra rr)- $ compare a0 ra- )- ( \rl ra rr _ _ ->- ordering- (R l a $ deleteBl rl ra rr)- (checkRightR' l a $ substituteBl rl rr)- (R l a $ deleteBr rl ra rr)- $ compare a0 ra- )- ( \rl ra rr _ _ ->- ordering- (checkRightR l a $ deleteRl rl ra rr)- (checkRightR l a $ substituteR rl rr)- (checkRightR l a $ deleteRr rl ra rr)- $ compare a0 ra- )- deleteBl l a r =- set'- (error "Set.delete: L3")- ( \ll la lr _ _ ->- ordering- (checkLeftB (deleteLl ll la lr) a r)- (checkLeftB (substituteL ll lr) a r)- (checkLeftB (deleteLr ll la lr) a r)- $ compare a0 la- )- ( \ll la lr _ _ ->- ordering- (B (deleteBl ll la lr) a r)- (checkLeftB' (substituteBr ll lr) a r)- (B (deleteBr ll la lr) a r)- $ compare a0 la- )- ( \ll la lr _ _ ->- ordering- (checkLeftB (deleteRl ll la lr) a r)- (checkLeftB (substituteR ll lr) a r)- (checkLeftB (deleteRr ll la lr) a r)- $ compare a0 la- )- l- deleteBr l a =- set'- (error "Set.delete: L4")- ( \rl ra rr _ _ ->- ordering- (checkRightB l a $ deleteLl rl ra rr)- (checkRightB l a $ substituteL rl rr)- (checkRightB l a $ deleteLr rl ra rr)- $ compare a0 ra- )- ( \rl ra rr _ _ ->- ordering- (B l a $ deleteBl rl ra rr)- (checkRightB' l a $ substituteBl rl rr)- (B l a $ deleteBr rl ra rr)- $ compare a0 ra- )- ( \rl ra rr _ _ ->- ordering- (checkRightB l a $ deleteRl rl ra rr)- (checkRightB l a $ substituteR rl rr)- (checkRightB l a $ deleteRr rl ra rr)- $ compare a0 ra- )- deleteLl l a r =- set'- (error "Set.delete: L5")- ( \ll la lr _ _ ->- ordering- (checkLeftL (deleteLl ll la lr) a r)- (checkLeftL (substituteL ll lr) a r)- (checkLeftL (deleteLr ll la lr) a r)- $ compare a0 la- )- ( \ll la lr _ _ ->- ordering- (L (deleteBl ll la lr) a r)- (checkLeftL' (substituteBr ll lr) a r)- (L (deleteBr ll la lr) a r)- $ compare a0 la- )- ( \ll la lr _ _ ->- ordering- (checkLeftL (deleteRl ll la lr) a r)- (checkLeftL (substituteR ll lr) a r)- (checkLeftL (deleteRr ll la lr) a r)- $ compare a0 la- )- l- deleteLr l a =- set'- (error "Set.delete: L6")- ( \rl ra rr _ _ ->- ordering- (checkRightL l a $ deleteLl rl ra rr)- (checkRightL l a $ substituteL rl rr)- (checkRightL l a $ deleteLr rl ra rr)- $ compare a0 ra- )- ( \rl ra rr _ _ ->- ordering- (L l a $ deleteBl rl ra rr)- (checkRightL' l a $ substituteBl rl rr)- (L l a $ deleteBr rl ra rr)- $ compare a0 ra- )- ( \rl ra rr _ _ ->- ordering- (checkRightL l a $ deleteRl rl ra rr)- (checkRightL l a $ substituteR rl rr)- (checkRightL l a $ deleteRr rl ra rr)- $ compare a0 ra- )- rebalanceR l a =- set'- (error "Set.delete: L7")- ( \rl ra rr _ _ ->- set'- (error "Set.delete: L8")- (\rll rla rlr _ _ -> B (B l a rll) rla $ R rlr ra rr)- (\rll rla rlr _ _ -> B (B l a rll) rla $ B rlr ra rr)- (\rll rla rlr _ _ -> B (L l a rll) rla $ B rlr ra rr)- rl- )- (\rl ra rr _ _ -> L (R l a rl) ra rr)- (\rl ra rr _ _ -> B (B l a rl) ra rr)- rebalanceL l a r =- set'- (error "Set.delete: L9")- (\ll la lr _ _ -> B ll la $ B lr a r)- (\ll la lr _ _ -> R ll la $ L lr a r)- ( \ll la lr _ _ ->- set'- (error "Set.delete: L10")- (\lrl lra lrr _ _ -> B (B ll la lrl) lra $ R lrr a r)- (\lrl lra lrr _ _ -> B (B ll la lrl) lra $ B lrr a r)- (\lrl lra lrr _ _ -> B (L ll la lrl) lra $ B lrr a r)- lr- )- l- checkLeftR l a r =- set'- (error "Set.delete: L11")- (\_ _ _ _ _ -> R l a r)- (\_ _ _ _ _ -> rebalanceR l a r)- (\_ _ _ _ _ -> R l a r)- l- checkLeftB l a r =- set'- (error "Set.delete: L12")- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> R l a r)- (\_ _ _ _ _ -> B l a r)- l- checkLeftL l a r =- set'- (error "Set.delete: L13")- (\_ _ _ _ _ -> L l a r)- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> L l a r)- l- checkRightR l a r =- set'- (error "Set.delete: L14")- (\_ _ _ _ _ -> R l a r)- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> R l a r)- r- checkRightB l a r =- set'- (error "Set.delete: L15")- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> L l a r)- (\_ _ _ _ _ -> B l a r)- r- checkRightL l a r =- set'- (error "Set.delete: L16")- (\_ _ _ _ _ -> L l a r)- (\_ _ _ _ _ -> rebalanceL l a r)- (\_ _ _ _ _ -> L l a r)- r- substituteR l =- set'- (error "Set.delete: L17")- (\rl ra rr _ _ -> uncurry (checkRightR l) $ popLeftL rl ra rr)- (\rl ra rr _ _ -> uncurry (checkRightR' l) $ popLeftB rl ra rr)- (\rl ra rr _ _ -> uncurry (checkRightR l) $ popLeftR rl ra rr)- substituteBr l =- set'- E- (\rl ra rr _ _ -> uncurry (checkRightB l) $ popLeftL rl ra rr)- (\rl ra rr _ _ -> uncurry (checkRightB' l) $ popLeftB rl ra rr)- (\rl ra rr _ _ -> uncurry (checkRightB l) $ popLeftR rl ra rr)- substituteBl l r =- set'- E- (\ll la lr _ _ -> (\(l', a) -> checkLeftB l' a r) $ popRightL ll la lr)- (\ll la lr _ _ -> (\(l', a) -> checkLeftB' l' a r) $ popRightB ll la lr)- (\ll la lr _ _ -> (\(l', a) -> checkLeftB l' a r) $ popRightR ll la lr)- l- substituteL l r =- set'- (error "Set.delete: L18")- (\ll la lr _ _ -> (\(l', a) -> checkLeftL l' a r) $ popRightL ll la lr)- (\ll la lr _ _ -> (\(l', a) -> checkLeftL' l' a r) $ popRightB ll la lr)- (\ll la lr _ _ -> (\(l', a) -> checkLeftL l' a r) $ popRightR ll la lr)- l- checkLeftR' l a r =- set'- (rebalanceR l a r)- (\_ _ _ _ _ -> R l a r)- (\_ _ _ _ _ -> R l a r)- (\_ _ _ _ _ -> R l a r)- l- checkLeftB' l a r =- set'- (R l a r)- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> B l a r)- l- checkLeftL' l a r =- set'- (B l a r)- (\_ _ _ _ _ -> L l a r)- (\_ _ _ _ _ -> L l a r)- (\_ _ _ _ _ -> L l a r)- l- checkRightR' l a r =- set'- (B l a r)- (\_ _ _ _ _ -> R l a r)- (\_ _ _ _ _ -> R l a r)- (\_ _ _ _ _ -> R l a r)- r- checkRightB' l a r =- set'- (L l a r)- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> B l a r)- r- checkRightL' l a r =- set'- (rebalanceL l a r)- (\_ _ _ _ _ -> L l a r)- (\_ _ _ _ _ -> L l a r)- (\_ _ _ _ _ -> L l a r)- r- popLeftR l a r =- set'- (a, r)- ( \ll la lr _ _ ->- (\(a', l') -> (a', checkLeftR l' a r)) $- popLeftL ll la lr- )- (\ll la lr _ _ -> popLeftRB ll la lr a r)- ( \ll la lr _ _ ->- (\(a', l') -> (a', checkLeftR l' a r)) $- popLeftR ll la lr- )- l- popLeftB l a r =- set'- (a, E)- (\ll la lr _ _ -> popLeftBL ll la lr a r)- (\ll la lr _ _ -> popLeftBB ll la lr a r)- (\ll la lr _ _ -> popLeftBR ll la lr a r)- l- popLeftL l a r =- set'- (error "Set.delete: L19")- ( \ll la lr _ _ ->- (\(a', l') -> (a', checkLeftL l' a r)) $- popLeftL ll la lr- )- (\ll la lr _ _ -> popLeftLB ll la lr a r)- ( \ll la lr _ _ ->- (\(a', l') -> (a', checkLeftL l' a r)) $- popLeftR ll la lr- )- l- popLeftRB ll la lr a r =- set'- (la, rebalanceR E a r)- ( \lll lla llr _ _ ->- (\(a', l) -> (a', R l a r)) $- popLeftBL lll lla llr la lr- )- ( \lll lla llr _ _ ->- (\(a', l) -> (a', R l a r)) $- popLeftBB lll lla llr la lr- )- ( \lll lla llr _ _ ->- (\(a', l) -> (a', R l a r)) $- popLeftBR lll lla llr la lr- )- ll- popLeftBB ll la lr a r =- set'- (la, R E a r)- ( \lll lla llr _ _ ->- (\(a', l) -> (a', B l a r)) $- popLeftBL lll lla llr la lr- )- ( \lll lla llr _ _ ->- (\(a', l) -> (a', B l a r)) $- popLeftBB lll lla llr la lr- )- ( \lll lla llr _ _ ->- (\(a', l) -> (a', B l a r)) $- popLeftBR lll lla llr la lr- )- ll- popLeftLB ll la lr a r =- set'- (la, B E a E)- ( \lll lla llr _ _ ->- (\(a', l) -> (a', L l a r)) $- popLeftBL lll lla llr la lr- )- ( \lll lla llr _ _ ->- (\(a', l) -> (a', L l a r)) $- popLeftBB lll lla llr la lr- )- ( \lll lla llr _ _ ->- (\(a', l) -> (a', L l a r)) $- popLeftBR lll lla llr la lr- )- ll- popLeftBR ll la lr a r =- (\(a', l) -> (a', checkLeftB l a r)) $- popLeftR ll la lr- popLeftBL ll la lr a r =- (\(a', l) -> (a', checkLeftB l a r)) $- popLeftL ll la lr- popRightR l a =- set'- (error "Set.delete: L20")- (\rl ra rr _ _ -> first (checkRightR l a) $ popRightL rl ra rr)- (\rl ra rr _ _ -> popRightRB l a rl ra rr)- (\rl ra rr _ _ -> first (checkRightR l a) $ popRightR rl ra rr)- popRightB l a =- set'- (E, a)- (\rl ra rr _ _ -> popRightBL l a rl ra rr)- (\rl ra rr _ _ -> popRightBB l a rl ra rr)- (\rl ra rr _ _ -> popRightBR l a rl ra rr)- popRightL l a =- set'- (l, a)- (\rl ra rr _ _ -> first (checkRightL l a) $ popRightL rl ra rr)- (\rl ra rr _ _ -> popRightLB l a rl ra rr)- (\rl ra rr _ _ -> first (checkRightL l a) $ popRightR rl ra rr)- popRightRB l a rl ra =- set'- (B E a E, ra)- (\rrl rra rrr _ _ -> first (R l a) $ popRightBL rl ra rrl rra rrr)- (\rrl rra rrr _ _ -> first (R l a) $ popRightBB rl ra rrl rra rrr)- (\rrl rra rrr _ _ -> first (R l a) $ popRightBR rl ra rrl rra rrr)- popRightBB l a rl ra =- set'- (L l a E, ra)- (\rrl rra rrr _ _ -> first (B l a) $ popRightBL rl ra rrl rra rrr)- (\rrl rra rrr _ _ -> first (B l a) $ popRightBB rl ra rrl rra rrr)- (\rrl rra rrr _ _ -> first (B l a) $ popRightBR rl ra rrl rra rrr)- popRightLB l a rl ra =- set'- (rebalanceL l a E, ra)- (\rrl rra rrr _ _ -> first (L l a) $ popRightBL rl ra rrl rra rrr)- (\rrl rra rrr _ _ -> first (L l a) $ popRightBB rl ra rrl rra rrr)- (\rrl rra rrr _ _ -> first (L l a) $ popRightBR rl ra rrl rra rrr)- popRightBR l a rl ra rr = first (checkRightB l a) $ popRightR rl ra rr- popRightBL l a rl ra rr = first (checkRightB l a) $ popRightL rl ra rr---- O(log n) Insert an element into a set without checking for membership-insert' :: (Ord a) => a -> Set a -> Set a-insert' a0 =- set'- (B E a0 E)- (\l a r _ _ -> insertL l a r)- (\l a r _ _ -> insertB l a r)- (\l a r _ _ -> insertR l a r)- where- insertR l a r =- ordering- (insertRl l a r)- (R l a0 r)- (insertRr l a r)- $ compare a0 a- insertB l a r =- ordering- (insertBl l a r)- (B l a0 r)- (insertBr l a r)- $ compare a0 a- insertL l a r =- ordering- (insertLl l a r)- (L l a0 r)- (insertLr l a r)- $ compare a0 a- insertRl l a r =- set'- (B (B E a0 E) a r)- (\ll la lr _ _ -> R (insertL ll la lr) a r)- ( \ll la lr _ _ ->- let l' = insertB ll la lr- in set'- (error "Set.insert: L0")- (\_ _ _ _ _ -> B l' a r)- (\_ _ _ _ _ -> R l' a r)- (\_ _ _ _ _ -> B l' a r)- l'- )- (\ll la lr _ _ -> R (insertR ll la lr) a r)- l- insertBl l a r =- set'- (L (B E a0 E) a r)- (\ll la lr _ _ -> B (insertL ll la lr) a r)- ( \ll la lr _ _ ->- let l' = insertB ll la lr- in set'- (error "Set.insert: L1")- (\_ _ _ _ _ -> L l' a r)- (\_ _ _ _ _ -> B l' a r)- (\_ _ _ _ _ -> L l' a r)- l'- )- (\ll la lr _ _ -> B (insertR ll la lr) a r)- l- insertBr l a =- set'- (R l a $ B E a0 E)- (\rl ra rr _ _ -> B l a $ insertL rl ra rr)- ( \rl ra rr _ _ ->- let r = insertB rl ra rr- in set'- (error "Set.insert: L2")- (\_ _ _ _ _ -> R l a r)- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> R l a r)- r- )- (\rl ra rr _ _ -> B l a $ insertR rl ra rr)- insertLr l a =- set'- (B l a $ B E a0 E)- (\rl ra rr _ _ -> L l a $ insertL rl ra rr)- ( \rl ra rr _ _ ->- let r = insertB rl ra rr- in set'- (error "Set.insert: L3")- (\_ _ _ _ _ -> B l a r)- (\_ _ _ _ _ -> L l a r)- (\_ _ _ _ _ -> B l a r)- r- )- (\rl ra rr _ _ -> L l a $ insertR rl ra rr)- insertRr l a =- set'- (error "Set.insert: L4")- (\rl ra rr _ _ -> R l a $ insertL rl ra rr)- ( \rl ra rr _ _ ->- ordering- (insertRrl l a rl ra rr)- (R l a $ B rl a0 rr)- (insertRrr l a rl ra rr)- $ compare a0 ra- )- (\rl ra rr _ _ -> R l a $ insertR rl ra rr)- insertLl l a r =- set'- (error "Set.insert: L5")- (\ll la lr _ _ -> L (insertL ll la lr) a r)- ( \ll la lr _ _ ->- ordering- (insertLll ll la lr a r)- (L (B ll a0 lr) a r)- (insertLlr ll la lr a r)- $ compare a0 la- )- (\ll la lr _ _ -> L (insertR ll la lr) a r)- l- insertRrr l a rl ra =- set'- (B (B l a rl) ra $ B E a0 E)- (\rrl rra rrr _ _ -> R l a . B rl ra $ insertL rrl rra rrr)- ( \rrl rra rrr _ _ ->- let rr = insertB rrl rra rrr- in set'- (error "Set.insert: L6")- (\_ _ _ _ _ -> B (B l a rl) ra rr)- (\_ _ _ _ _ -> R l a $ B rl ra rr)- (\_ _ _ _ _ -> B (B l a rl) ra rr)- rr- )- (\rrl rra rrr _ _ -> R l a . B rl ra $ insertR rrl rra rrr)- insertLll ll la lr a r =- set'- (B (B E a0 E) la $ B lr a r)- (\lll lla llr _ _ -> L (B (insertL lll lla llr) la lr) a r)- ( \lll lla llr _ _ ->- let ll' = insertB lll lla llr- in set'- (error "Set.insert: L7")- (\_ _ _ _ _ -> B ll' la $ B lr a r)- (\_ _ _ _ _ -> L (B ll' la lr) a r)- (\_ _ _ _ _ -> B ll' la $ B lr a r)- ll'- )- (\lll lla llr _ _ -> L (B (insertR lll lla llr) la lr) a r)- ll- insertRrl l a rl ra rr =- set'- (B (B l a E) a0 $ B E ra rr)- (\rll rla rlr _ _ -> R l a $ B (insertL rll rla rlr) ra rr)- ( \rll rla rlr _ _ ->- let rl' = insertB rll rla rlr- in set'- (error "Set.insert: L8")- (\rll' rla' rlr' _ _ -> B (B l a rll') rla' $ R rlr' ra rr)- (\_ _ _ _ _ -> R l a $ B rl' ra rr)- (\rll' rla' rlr' _ _ -> B (L l a rll') rla' $ B rlr' ra rr)- rl'- )- (\rll rla rlr _ _ -> R l a $ B (insertR rll rla rlr) ra rr)- rl- insertLlr ll la lr a r =- set'- (B (B ll la E) a0 $ B E a r)- (\lrl lra lrr _ _ -> L (B ll la $ insertL lrl lra lrr) a r)- ( \lrl lra lrr _ _ ->- let lr' = insertB lrl lra lrr- in set'- (error "Set.insert: L9")- (\lrl' lra' lrr' _ _ -> B (B ll la lrl') lra' $ R lrr' a r)- (\_ _ _ _ _ -> L (B ll la lr') a r)- (\lrl' lra' lrr' _ _ -> B (L ll la lrl') lra' $ B lrr' a r)- lr'- )- (\lrl lra lrr _ _ -> L (B ll la $ insertR lrl lra lrr) a r)- lr
− Mini/Hash/Class.hs
@@ -1,100 +0,0 @@--- | The class of hashable types-module Mini.Hash.Class (- -- * Class- Hashable (- toBytes- ),-) where--import Data.Bits (- FiniteBits,- finiteBitSize,- shiftR,- )-import Data.Int (- Int,- Int16,- Int32,- Int64,- Int8,- )-import Data.Word (- Word,- Word16,- Word32,- Word64,- Word8,- )-import Prelude (- Bool,- Char,- Enum,- Integral,- concatMap,- div,- fmap,- fromEnum,- fromIntegral,- iterate,- pure,- take,- ($),- (.),- )---- Class---- | Instances should use little-endian byte order-class Hashable a where- -- | Convert a hashable type to a sequence of bytes- toBytes :: a -> [Word8]--instance Hashable Bool where- toBytes = enumToBytes--instance Hashable Char where- toBytes = enumToBytes--instance Hashable Int where- toBytes = finiteBitsIntegralToBytes--instance Hashable Int8 where- toBytes = finiteBitsIntegralToBytes--instance Hashable Int16 where- toBytes = finiteBitsIntegralToBytes--instance Hashable Int32 where- toBytes = finiteBitsIntegralToBytes--instance Hashable Int64 where- toBytes = finiteBitsIntegralToBytes--instance Hashable Word where- toBytes = finiteBitsIntegralToBytes--instance Hashable Word8 where- toBytes = pure--instance Hashable Word16 where- toBytes = finiteBitsIntegralToBytes--instance Hashable Word32 where- toBytes = finiteBitsIntegralToBytes--instance Hashable Word64 where- toBytes = finiteBitsIntegralToBytes--instance (Hashable a) => Hashable [a] where- toBytes = concatMap toBytes---- Helpers--enumToBytes :: (Enum a) => a -> [Word8]-enumToBytes = pure . fromIntegral . fromEnum--finiteBitsIntegralToBytes :: (FiniteBits a, Integral a) => a -> [Word8]-finiteBitsIntegralToBytes w =- take (finiteBitSize w `div` 8)- . fmap fromIntegral- $ iterate (`shiftR` 8) w
− Mini/Hash/Murmur32.hs
@@ -1,136 +0,0 @@--- | An implementation of MurmurHash3_x86_32 supporting incremental addition-module Mini.Hash.Murmur32 (- -- * Type- Hash32,-- -- * Construction- seed,-- -- * Operations- add,- digest,-) where--import Data.Bits (- rotateL,- shiftL,- shiftR,- xor,- )-import Data.Function (- on,- )-import Data.Word (- Word32,- Word8,- )-import Mini.Data.Recursion (- bool,- uncurry3,- )-import Mini.Hash.Class (- Hashable,- toBytes,- )-import Numeric (- showHex,- )-import Prelude (- Eq,- Ord,- Show,- compare,- foldr,- fromIntegral,- null,- showsPrec,- ($),- (*),- (+),- (.),- (<>),- (==),- )---- Type---- | Abstract representation of a 32-bit hash value-data Hash32 = Hash32 Word32 Word32 [Word8]--instance Eq Hash32 where- (==) = (==) `on` digest--instance Ord Hash32 where- compare = compare `on` digest--instance Show Hash32 where- showsPrec _ = showHex . digest---- Construction---- | Make a hash from a seed-seed :: Word32 -> Hash32-seed s = Hash32 s 0 []---- Operations---- | Add a hashable type to a hash-add :: (Hashable a) => a -> Hash32 -> Hash32-add a = addBytes $ toBytes a---- | Get the digest of a hash-digest :: Hash32 -> Word32-digest (Hash32 h1 len t) =- let (k0, tlen) =- foldr- (\a (b, n) -> (fromIntegral a `xor` (b `shiftL` 8), n + 1))- (0, 0)- t- len' = len + tlen- k1 = k0 * 0xcc9e2d51- k2 = k1 `rotateL` 15- k3 = k2 * 0x1b873593- h2 = h1 `xor` k3- in mix- . bool- (h2 `xor` len')- (h1 `xor` len)- $ null t---- Helpers--addBytes :: [Word8] -> Hash32 -> Hash32-addBytes new (Hash32 h0 len0 old) = uncurry3 Hash32 $ go h0 len0 (old <> new)- where- go h len (a : b : c : d : rest) =- let d' = fromIntegral d `shiftL` 24- c' = fromIntegral c `shiftL` 16- b' = fromIntegral b `shiftL` 8- a' = fromIntegral a- w = a' `xor` b' `xor` c' `xor` d'- h' = murmur w h- len' = len + 4- in go h' len' rest- go h len bs = (h, len, bs)--murmur :: Word32 -> Word32 -> Word32-murmur k1 h1 =- let c1 = 0xcc9e2d51- c2 = 0x1b873593- c3 = 0xe6546b64- k2 = k1 * c1- k3 = k2 `rotateL` 15- k4 = k3 * c2- h2 = h1 `xor` k4- h3 = h2 `rotateL` 13- h4 = h3 * 5 + c3- in h4--mix :: Word32 -> Word32-mix h1 =- let h2 = h1 `xor` (h1 `shiftR` 16)- h3 = h2 * 0x85ebca6b- h4 = h3 `xor` (h3 `shiftR` 13)- h5 = h4 * 0xc2b2ae35- h6 = h5 `xor` (h5 `shiftR` 16)- in h6
− Mini/Optics/Lens.hs
@@ -1,60 +0,0 @@-{-# LANGUAGE RankNTypes #-}---- | Compose polymorphic record updates with /van Laarhoven/ lenses-module Mini.Optics.Lens (- -- * Type- Lens,-- -- * Construction- lens,-- -- * Operations- over,- set,- view,-) where--import Control.Applicative (- Const (- Const- ),- getConst,- )-import Data.Functor.Identity (- Identity (- Identity- ),- runIdentity,- )-import Prelude (- Functor,- const,- ($),- (.),- (<$>),- )---- Type---- | A reference updating structures from /s/ to /t/ and fields from /a/ to /b/-type Lens s t a b = forall f. (Functor f) => (a -> f b) -> (s -> f t)---- Construction---- | Make a lens from a getter and a setter-lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b-lens sa sbt ab s = sbt s <$> ab (sa s)---- Operations---- | Update the field referenced by a lens with an operation on a structure-over :: Lens s t a b -> (a -> b) -> s -> t-over o ab = runIdentity . o (Identity . ab)---- | Overwrite the field referenced by a lens with a value on a structure-set :: Lens s t a b -> b -> s -> t-set o b = runIdentity . o (const $ Identity b)---- | Fetch the field referenced by a lens from a structure-view :: Lens s t a b -> s -> a-view o = getConst . o Const
− Mini/Transformers/Class.hs
@@ -1,23 +0,0 @@--- | The class of monad transformers-module Mini.Transformers.Class (- -- * Class- MonadTrans (- lift- ),-) where--import Prelude (- Monad,- )---- Class--{- | Instances should satisfy the following laws:--> lift . pure = pure--> lift (m >>= f) = lift m >>= (lift . f)--}-class MonadTrans t where- -- | Lift a computation from the inner monad to the transformer monad- lift :: (Monad m) => m a -> t m a
− Mini/Transformers/EitherT.hs
@@ -1,104 +0,0 @@--- | Extend a monad with the ability to terminate a computation with a value-module Mini.Transformers.EitherT (- -- * Type- EitherT (- EitherT- ),- runEitherT,-- -- * Operations- anticipate,- left,-) where--import Control.Applicative (- Alternative,- empty,- (<|>),- )-import Control.Monad (- ap,- liftM,- (>=>),- )-import Control.Monad.IO.Class (- MonadIO,- liftIO,- )-import Mini.Transformers.Class (- MonadTrans,- lift,- )-import Prelude (- Applicative,- Either (- Left,- Right- ),- Functor,- Monad,- MonadFail,- Monoid,- either,- fail,- fmap,- mappend,- mempty,- pure,- ($),- (.),- (<$>),- (<*>),- (>>=),- )---- Type---- | A terminable transformer with termination /e/, inner monad /m/, return /a/-newtype EitherT e m a = EitherT- { runEitherT :: m (Either e a)- -- ^ Unwrap a transformer computation- }--instance (Monad m) => Functor (EitherT e m) where- fmap = liftM--instance (Monad m) => Applicative (EitherT e m) where- pure = EitherT . pure . Right- (<*>) = ap--instance (Monad m, Monoid e) => Alternative (EitherT e m) where- empty = left mempty- m <|> n =- EitherT $- runEitherT m- >>= either- (\e -> either (Left . mappend e) Right <$> runEitherT n)- (pure . Right)--instance (Monad m) => Monad (EitherT e m) where- m >>= k =- EitherT $- runEitherT m- >>= either- (pure . Left)- (runEitherT . k)--instance MonadTrans (EitherT e) where- lift = EitherT . fmap Right--instance (MonadFail m) => MonadFail (EitherT e m) where- fail = EitherT . fail--instance (MonadIO m) => MonadIO (EitherT e m) where- liftIO = lift . liftIO---- Operations---- | Run a computation and get its result-anticipate :: (Monad m) => EitherT e m a -> EitherT e m (Either e a)-anticipate = lift . runEitherT . (Right <$>) >=> either (pure . Left) pure---- | Terminate the computation with a value-left :: (Applicative m) => e -> EitherT e m a-left = EitherT . pure . Left
− Mini/Transformers/MaybeT.hs
@@ -1,102 +0,0 @@--- | Extend a monad with the ability to terminate a computation without a value-module Mini.Transformers.MaybeT (- -- * Type- MaybeT (- MaybeT- ),- runMaybeT,-- -- * Operations- anticipate,- nothing,-) where--import Control.Applicative (- Alternative,- empty,- (<|>),- )-import Control.Monad (- ap,- liftM,- (>=>),- )-import Control.Monad.IO.Class (- MonadIO,- liftIO,- )-import Mini.Transformers.Class (- MonadTrans,- lift,- )-import Prelude (- Applicative,- Functor,- Maybe (- Just,- Nothing- ),- Monad,- MonadFail,- const,- fail,- fmap,- maybe,- pure,- ($),- (.),- (<$>),- (<*>),- (>>=),- )---- Type---- | A terminable transformer with inner monad /m/, return /a/-newtype MaybeT m a = MaybeT- { runMaybeT :: m (Maybe a)- -- ^ Unwrap a transformer computation- }--instance (Monad m) => Functor (MaybeT m) where- fmap = liftM--instance (Monad m) => Applicative (MaybeT m) where- pure = MaybeT . pure . Just- (<*>) = ap--instance (Monad m) => Alternative (MaybeT m) where- empty = nothing- m <|> n =- MaybeT $- runMaybeT m- >>= maybe- (runMaybeT n)- (pure . Just)--instance (Monad m) => Monad (MaybeT m) where- m >>= k =- MaybeT $- runMaybeT m- >>= maybe- (pure Nothing)- (runMaybeT . k)--instance MonadTrans MaybeT where- lift = MaybeT . fmap Just--instance (Monad m) => MonadFail (MaybeT m) where- fail = const nothing--instance (MonadIO m) => MonadIO (MaybeT m) where- liftIO = lift . liftIO---- Operations---- | Run a computation and get its result-anticipate :: (Monad m) => MaybeT m a -> MaybeT m (Maybe a)-anticipate = lift . runMaybeT . (Just <$>) >=> maybe (pure Nothing) pure---- | Terminate the computation without a value-nothing :: (Applicative m) => MaybeT m a-nothing = MaybeT $ pure Nothing
− Mini/Transformers/ParserT.hs
@@ -1,296 +0,0 @@-{-# LANGUAGE TupleSections #-}---- | Extend a monad with the ability to parse symbol sequences-module Mini.Transformers.ParserT (- -- * Type- ParserT (- ParserT- ),- runParserT,-- -- * Parsers- eof,- item,- look,- noneOf,- oneOf,- peek,- sat,- string,- symbol,-- -- * Combinators- accept,- atLeast,- atMost,- between,- chainl1,- chainr1,- findAll,- findAll1,- findFirst,- findLast,- option,- range,- reject,- sepBy,- sepBy1,- till,- till1,-) where--import Control.Applicative (- Alternative,- empty,- many,- some,- (<|>),- )-import Control.Monad (- ap,- liftM,- replicateM,- (>=>),- )-import Control.Monad.IO.Class (- MonadIO,- liftIO,- )-import Data.Bool (- bool,- )-import Mini.Data.Recursion (- list,- )-import Mini.Transformers.Class (- MonadTrans,- lift,- )-import Prelude (- Applicative,- Bool (- True- ),- Eq,- Foldable,- Functor,- Int,- Maybe (- Just,- Nothing- ),- Monad,- MonadFail,- Monoid,- Semigroup,- Traversable,- const,- elem,- fail,- flip,- fmap,- fst,- maybe,- mempty,- notElem,- pure,- traverse,- ($),- (*>),- (-),- (.),- (<$),- (<$>),- (<*),- (<*>),- (<>),- (==),- (>),- (>>=),- )---- Type---- | A transformer parsing symbols /s/, inner monad /m/, return /a/-newtype ParserT s m a = ParserT- { runParserT :: [s] -> m (Maybe (a, [s]))- -- ^ Unwrap a transformer computation with a sequence of symbols to parse- }--instance (Monad m) => Functor (ParserT s m) where- fmap = liftM--instance (Monad m) => Applicative (ParserT s m) where- pure a = ParserT $ pure . Just . (a,)- (<*>) = ap--instance (Monad m) => Alternative (ParserT s m) where- empty = ParserT . const $ pure Nothing- m <|> n = ParserT $ \ss -> (<|>) <$> runParserT m ss <*> runParserT n ss--instance (Monad m) => Monad (ParserT s m) where- m >>= k =- ParserT $- runParserT m- >=> maybe- (pure Nothing)- (\(a, ss') -> runParserT (k a) ss')--instance MonadTrans (ParserT s) where- lift m = ParserT $ \ss -> Just . (,ss) <$> m--instance (Monad m, Semigroup a) => Semigroup (ParserT s m a) where- m <> n = (<>) <$> m <*> n--instance (Monad m, Monoid a) => Monoid (ParserT s m a) where- mempty = pure mempty--instance (Monad m) => MonadFail (ParserT s m) where- fail = const empty--instance (MonadIO m) => MonadIO (ParserT s m) where- liftIO = lift . liftIO---- Parsers---- | Parse successfully only at end of input-eof :: (Monad m) => ParserT s m ()-eof = reject item---- | Parse any symbol-item :: (Applicative m) => ParserT s m s-item = sat $ const True---- | Parse the rest of the input without consuming it-look :: (Applicative m) => ParserT s m [s]-look = ParserT $ \ss -> pure $ Just (ss, ss)---- | Parse the next symbol if excluded from a collection-noneOf :: (Applicative m, Foldable t, Eq s) => t s -> ParserT s m s-noneOf = sat . flip notElem---- | Parse the next symbol if included in a collection-oneOf :: (Applicative m, Foldable t, Eq s) => t s -> ParserT s m s-oneOf = sat . flip elem---- | Parse the next symbol without consuming it-peek :: (Monad m) => ParserT s m s-peek = accept item---- | Parse the next symbol if it satisfies a predicate-sat :: (Applicative m) => (s -> Bool) -> ParserT s m s-sat p =- ParserT $- pure- . list- Nothing- ( \s ss _ ->- bool- Nothing- (Just (s, ss))- $ p s- )---- | Parse a sequence of symbols-string :: (Monad m, Traversable t, Eq s) => t s -> ParserT s m (t s)-string = traverse symbol---- | Parse a specific symbol-symbol :: (Applicative m, Eq s) => s -> ParserT s m s-symbol = sat . (==)---- Combinators---- | Parse @p@, without consuming input, iff @p@ succeeds via @accept p@-accept :: (Monad m) => ParserT s m a -> ParserT s m a-accept p = ParserT $ \ss -> fmap ((,ss) . fst) <$> runParserT p ss---- | Parse @n@ or more occurrences of @p@ via @atLeast n p@-atLeast :: (Monad m) => Int -> ParserT s m a -> ParserT s m [a]-atLeast n p = replicateM n p <> many p---- | Parse up to @n@ occurrences of @p@ via @atMost n p@-atMost :: (Monad m) => Int -> ParserT s m a -> ParserT s m [a]-atMost n p =- bool- (pure [])- (option [] $ (:) <$> p <*> atMost (n - 1) p)- $ n > 0---- | Parse @p@ enclosed by @a@ and @b@ via @between a b p@-between- :: (Monad m)- => ParserT s m open- -> ParserT s m close- -> ParserT s m a- -> ParserT s m a-between open close p = open *> p <* close---- | Parse one or more @p@ left-associatively chained by @f@ via @chainl1 p f@-chainl1- :: (Monad m)- => ParserT s m a- -> ParserT s m (a -> a -> a)- -> ParserT s m a-chainl1 p f = p >>= go- where- go a = option a $ f <*> pure a <*> p >>= go---- | Parse one or more @p@ right-associatively chained by @f@ via @chainr1 p f@-chainr1- :: (Monad m)- => ParserT s m a- -> ParserT s m (a -> a -> a)- -> ParserT s m a-chainr1 p f = go- where- go = p >>= rest- rest a = option a $ f <*> pure a <*> go >>= rest---- | Find and parse zero or more occurrences of @p@ via @findAll p@-findAll :: (Monad m) => ParserT s m a -> ParserT s m [a]-findAll = many . findFirst---- | Find and parse one or more occurrences of @p@ via @findAll1 p@-findAll1 :: (Monad m) => ParserT s m a -> ParserT s m [a]-findAll1 = some . findFirst---- | Find and parse the first occurrence of @p@ via @findFirst p@-findFirst :: (Monad m) => ParserT s m a -> ParserT s m a-findFirst p = p <|> (item *> findFirst p)---- | Find and parse the last occurrence of @p@ via @findLast p@-findLast :: (Monad m) => ParserT s m a -> ParserT s m a-findLast p = findFirst p >>= flip option (findLast p)---- | Parse @p@ returning @a@ in case of failure via @option a p@-option :: (Monad m) => a -> ParserT s m a -> ParserT s m a-option a p = p <|> pure a---- | Parse between @lo@ and @hi@ occurrences of @p@ via @range lo hi p@-range :: (Monad m) => Int -> Int -> ParserT s m a -> ParserT s m [a]-range lo hi p = replicateM lo p <> atMost (hi - lo) p---- | Parse @p@, without consuming input, iff @p@ fails via @reject p@-reject :: (Monad m) => ParserT s m a -> ParserT s m ()-reject p = ParserT $ \ss ->- runParserT p ss- >>= maybe- (pure $ Just ((), ss))- (const $ pure Nothing)---- | Parse zero or more @p@ separated by @q@ via @p \`sepBy\` q@-sepBy :: (Monad m) => ParserT s m a -> ParserT s m b -> ParserT s m [a]-sepBy p = option [] . sepBy1 p---- | Parse one or more @p@ separated by @q@ via @p \`sepBy1\` q@-sepBy1 :: (Monad m) => ParserT s m a -> ParserT s m b -> ParserT s m [a]-sepBy1 p sep = (:) <$> p <*> many (sep *> p)---- | Parse zero or more @p@ until @q@ succeeds via @p \`till\` q@-till :: (Monad m) => ParserT s m a -> ParserT s m b -> ParserT s m [a]-till p end = ([] <$ end) <|> till1 p end---- | Parse one or more @p@ until @q@ succeeds via @p \`till1\` q@-till1 :: (Monad m) => ParserT s m a -> ParserT s m b -> ParserT s m [a]-till1 p end = (:) <$> p <*> till p end
− Mini/Transformers/ReaderT.hs
@@ -1,85 +0,0 @@--- | Extend a monad with a read-only environment-module Mini.Transformers.ReaderT (- -- * Type- ReaderT (- ReaderT- ),- runReaderT,-- -- * Operations- ask,- local,-) where--import Control.Applicative (- Alternative,- empty,- (<|>),- )-import Control.Monad (- ap,- liftM,- )-import Control.Monad.IO.Class (- MonadIO,- liftIO,- )-import Mini.Transformers.Class (- MonadTrans,- lift,- )-import Prelude (- Applicative,- Functor,- Monad,- MonadFail,- const,- fail,- fmap,- pure,- ($),- (.),- (<*>),- (>>=),- )---- Type---- | A transformer with read-only /r/, inner monad /m/, return /a/-newtype ReaderT r m a = ReaderT- { runReaderT :: r -> m a- -- ^ Unwrap a transformer computation with an initial read-only value- }--instance (Monad m) => Functor (ReaderT r m) where- fmap = liftM--instance (Monad m) => Applicative (ReaderT r m) where- pure = lift . pure- (<*>) = ap--instance (Monad m, Alternative m) => Alternative (ReaderT r m) where- empty = lift empty- m <|> n = ReaderT $ \r -> runReaderT m r <|> runReaderT n r--instance (Monad m) => Monad (ReaderT r m) where- m >>= k = ReaderT $ \r -> runReaderT m r >>= (`runReaderT` r) . k--instance MonadTrans (ReaderT r) where- lift = ReaderT . const--instance (MonadFail m) => MonadFail (ReaderT r m) where- fail = lift . fail--instance (MonadIO m) => MonadIO (ReaderT r m) where- liftIO = lift . liftIO---- Operations---- | Fetch the read-only environment-ask :: (Monad m) => ReaderT r m r-ask = ReaderT pure---- | Run a computation in a modified environment-local :: (r -> r') -> ReaderT r' m a -> ReaderT r m a-local f m = ReaderT $ runReaderT m . f
− Mini/Transformers/StateT.hs
@@ -1,94 +0,0 @@-{-# LANGUAGE TupleSections #-}---- | Extend a monad with a modifiable environment-module Mini.Transformers.StateT (- -- * Type- StateT (- StateT- ),- runStateT,-- -- * Operations- get,- modify,- put,-) where--import Control.Applicative (- Alternative,- empty,- (<|>),- )-import Control.Monad (- ap,- liftM,- (>=>),- )-import Control.Monad.IO.Class (- MonadIO,- liftIO,- )-import Mini.Transformers.Class (- MonadTrans,- lift,- )-import Prelude (- Applicative,- Functor,- Monad,- MonadFail,- const,- fail,- fmap,- pure,- ($),- (.),- (<$>),- (<*>),- (>>=),- )---- Type---- | A transformer with state /s/, inner monad /m/, return /a/-newtype StateT s m a = StateT- { runStateT :: s -> m (a, s)- -- ^ Unwrap a transformer computation with an initial state- }--instance (Monad m) => Functor (StateT s m) where- fmap = liftM--instance (Monad m) => Applicative (StateT s m) where- pure a = StateT $ pure . (a,)- (<*>) = ap--instance (Monad m, Alternative m) => Alternative (StateT s m) where- empty = StateT $ const empty- m <|> n = StateT $ \s -> runStateT m s <|> runStateT n s--instance (Monad m) => Monad (StateT s m) where- m >>= k = StateT $ runStateT m >=> (\(a, s) -> runStateT (k a) s)--instance MonadTrans (StateT s) where- lift m = StateT $ \s -> (,s) <$> m--instance (MonadFail m) => MonadFail (StateT s m) where- fail = StateT . const . fail--instance (MonadIO m) => MonadIO (StateT s m) where- liftIO = lift . liftIO---- Operations---- | Fetch the current state-get :: (Monad m) => StateT s m s-get = StateT $ \s -> pure (s, s)---- | Update the current state with an operation-modify :: (Monad m) => (s -> s) -> StateT s m ()-modify f = StateT $ pure . ((),) . f---- | Overwrite the current state with a value-put :: (Monad m) => s -> StateT s m ()-put = StateT . const . pure . ((),)
− Mini/Transformers/WriterT.hs
@@ -1,87 +0,0 @@-{-# LANGUAGE TupleSections #-}---- | Extend a monad with an accumulative write-only environment-module Mini.Transformers.WriterT (- -- * Type- WriterT (- WriterT- ),- runWriterT,-- -- * Operations- tell,-) where--import Control.Applicative (- Alternative,- empty,- (<|>),- )-import Control.Monad (- ap,- liftM,- )-import Control.Monad.IO.Class (- MonadIO,- liftIO,- )-import Mini.Transformers.Class (- MonadTrans,- lift,- )-import Prelude (- Applicative,- Functor,- Monad,- MonadFail,- Monoid,- fail,- fmap,- mempty,- pure,- ($),- (.),- (<*>),- (<>),- (>>=),- )---- Type---- | A transformer with monoidal write-only /w/, inner monad /m/, return /a/-newtype WriterT w m a = WriterT- { runWriterT :: m (a, w)- -- ^ Unwrap a transformer computation- }--instance (Monad m, Monoid w) => Functor (WriterT w m) where- fmap = liftM--instance (Monad m, Monoid w) => Applicative (WriterT w m) where- pure = WriterT . pure . (,mempty)- (<*>) = ap--instance (Monad m, Alternative m, Monoid w) => Alternative (WriterT w m) where- empty = WriterT empty- m <|> n = WriterT $ runWriterT m <|> runWriterT n--instance (Monad m, Monoid w) => Monad (WriterT w m) where- m >>= k = WriterT $ do- (a, w) <- runWriterT m- (b, w') <- runWriterT (k a)- pure (b, w <> w')--instance (Monoid w) => MonadTrans (WriterT w) where- lift = WriterT . fmap (,mempty)--instance (MonadFail m, Monoid w) => MonadFail (WriterT w m) where- fail = WriterT . fail--instance (MonadIO m, Monoid w) => MonadIO (WriterT w m) where- liftIO = lift . liftIO---- Operations---- | Append a value to the write-only environment-tell :: (Monad m) => w -> WriterT w m ()-tell = WriterT . pure . ((),)
mini.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: mini-version: 1.6.1.0+version: 1.6.2.0 license: MIT license-file: LICENSE author: Victor Wallsten <victor.wallsten@protonmail.com>@@ -10,7 +10,7 @@ synopsis: Minimal essentials description: Everyday essentials: data structures, primitive recursion, hashing, lenses,- transformers, and parsing.+ randomness, transformers, and parsing. Uncompromisingly light on dependencies. @@ -27,6 +27,8 @@ location: https://gitlab.com/vicwall/mini.git library+ hs-source-dirs:+ src exposed-modules: Mini.Data.Array Mini.Data.Graph@@ -36,6 +38,7 @@ Mini.Hash.Class Mini.Hash.Murmur32 Mini.Optics.Lens+ Mini.Random.Class Mini.Transformers.Class Mini.Transformers.EitherT Mini.Transformers.MaybeT
+ src/Mini/Data/Array.hs view
@@ -0,0 +1,83 @@+-- | Curated re-export of immutable non-strict (boxed) arrays from "GHC.Arr"+module Mini.Data.Array (+ -- * Type+ Array,++ -- * Class+ Ix (+ inRange,+ index,+ range,+ rangeSize,+ unsafeIndex,+ unsafeRangeSize+ ),++ -- * Construction+ accumArray,+ array,+ listArray,++ -- * Conversion+ assocs,+ elems,+ indices,++ -- * Modification+ (//),+ accum,+ ixmap,++ -- * Query+ (!),+ (!?),+ bounds,+ numElements,+) where++import Data.Bool (+ bool,+ )+import GHC.Arr (+ Array,+ Ix (+ inRange,+ index,+ range,+ rangeSize,+ unsafeIndex,+ unsafeRangeSize+ ),+ accum,+ accumArray,+ array,+ assocs,+ bounds,+ elems,+ indices,+ ixmap,+ listArray,+ numElements,+ unsafeAt,+ (!),+ (//),+ )+import Prelude (+ Maybe (+ Just,+ Nothing+ ),+ ($),+ (.),+ )++infixl 9 !?++-- | The value at the given index in an array, unless out of range.+(!?) :: (Ix i) => Array i e -> i -> Maybe e+arr !? i =+ let b = bounds arr+ in bool+ Nothing+ (Just . unsafeAt arr $ unsafeIndex b i)+ $ inRange b i
+ src/Mini/Data/Graph.hs view
@@ -0,0 +1,429 @@+-- | A structure representing unique vertices and their interrelations+module Mini.Data.Graph (+ -- * Type+ Graph,+ graph,++ -- * Algorithms+ distance,+ layers,+ path,+ reachable,+ sort,++ -- * Construction+ empty,+ fromList,+ singleton,++ -- * Modification+ add,+ connect,+ disconnect,+ remove,+ transpose,++ -- * Query+ assocs,+ edges,+ indegree,+ indegrees,+ lookup,+ lookupGE,+ lookupGT,+ lookupLE,+ lookupLT,+ lookupMax,+ lookupMin,+ member,+ outdegree,+ outdegrees,+ sinkMax,+ sinkMin,+ sinks,+ sourceMax,+ sourceMin,+ sources,+ vertices,+) where++import Data.Bifunctor (+ second,+ )+import Data.List (+ unfoldr,+ )+import Mini.Data.Map (+ Map,+ )+import qualified Mini.Data.Map as Map (+ delete,+ empty,+ foldlWithKey,+ foldrWithKey,+ insertWith,+ lookup,+ lookupGE,+ lookupGT,+ lookupLE,+ lookupLT,+ lookupMax,+ lookupMin,+ member,+ singleton,+ toAscList,+ unionWith,+ )+import Mini.Data.Recursion (+ bool,+ maybe,+ uncurry,+ )+import Mini.Data.Set (+ Set,+ )+import qualified Mini.Data.Set as Set (+ delete,+ difference,+ empty,+ fromList,+ member,+ null,+ singleton,+ size,+ toAscList,+ )+import Prelude (+ Bool,+ Eq,+ Foldable,+ Int,+ Maybe (+ Just,+ Nothing+ ),+ Monoid,+ Ord,+ Semigroup,+ Show,+ any,+ compare,+ concat,+ flip,+ fmap,+ foldMap,+ foldr,+ fst,+ mempty,+ show,+ ($),+ (+),+ (.),+ (<$>),+ (<>),+ (==),+ )++-- Type++-- | A graph with directed edges between vertices of type /a/+data Graph a+ = Graph+ (Map a (Set a))+ (Map a (Set a))++instance (Eq a) => Eq (Graph a) where+ (Graph _ oes1) == (Graph _ oes2) = oes1 == oes2++instance (Ord a) => Ord (Graph a) where+ compare (Graph _ oes1) (Graph _ oes2) = compare oes1 oes2++instance (Show a) => Show (Graph a) where+ show = show . assocs++instance Foldable Graph where+ foldr f b = foldr f b . vertices++instance (Ord a) => Semigroup (Graph a) where+ (Graph ies1 oes1) <> (Graph ies2 oes2) =+ Graph+ (Map.unionWith (<>) ies1 ies2)+ (Map.unionWith (<>) oes1 oes2)++instance (Ord a) => Monoid (Graph a) where+ mempty = empty++-- | Primitive recursion on graphs (internally represented by adjacency lists)+graph+ :: (Map a (Set a) -> Map a (Set a) -> b)+ -- ^ Function applied to the adjacency lists of the graph:+ -- incoming edges, outgoing edges+ -> Graph a+ -- ^ The graph+ -> b+graph f (Graph ies oes) = f ies oes++-- Algorithms++-- | Get the shortest distance in a graph between a vertex and another+distance :: (Ord a) => Graph a -> a -> a -> Maybe Int+distance g s t =+ foldr+ (\a b -> bool ((+ 1) <$> b) (Just 0) $ t `Set.member` a)+ Nothing+ $ bfs g s++-- | Breadth-first search for the hierarchy in a graph from a starting vertex+layers :: (Ord a) => Graph a -> a -> [[a]]+layers g = fmap Set.toAscList . bfs g++-- | Check whether there is a path in a graph from a vertex to another+path :: (Ord a) => Graph a -> a -> a -> Bool+path g s t = any (t `Set.member`) $ bfs g s++-- | Get the reachable vertices in a graph from a starting vertex+reachable :: (Ord a) => Graph a -> a -> [a]+reachable g = concat . layers g++-- | Topologically sort a graph (assumes acyclicity)+sort :: (Ord a) => Graph a -> [a]+sort = unfoldr $ \g -> (\u -> (u, remove u g)) <$> sourceMin g++-- Construction++-- | The empty graph+empty :: Graph a+empty = Graph Map.empty Map.empty++-- | Make a graph from a list of vertex associations+fromList :: (Ord a) => [(a, [a])] -> Graph a+fromList = foldr (uncurry connect) empty++-- | Make a graph with an isolated vertex+singleton :: a -> Graph a+singleton u = Graph (Map.singleton u Set.empty) (Map.singleton u Set.empty)++-- Modification++-- | Add an isolated vertex to a graph unless already present+add :: (Ord a) => a -> Graph a -> Graph a+add u = connect u []++-- | Add edges from a vertex to a list of vertices in a graph+connect :: (Ord a) => a -> [a] -> Graph a -> Graph a+connect u vs (Graph ies oes) =+ uncurry Graph $+ foldr+ ( \v (ies', oes') ->+ ( Map.insertWith (<>) v (Set.singleton u) ies'+ , Map.insertWith (<>) v Set.empty oes'+ )+ )+ ( Map.insertWith (<>) u Set.empty ies+ , Map.insertWith (<>) u (Set.fromList vs) oes+ )+ vs++-- | Remove edges from a vertex to a list of vertices in a graph+disconnect :: (Ord a) => a -> [a] -> Graph a -> Graph a+disconnect u vs (Graph ies oes) =+ Graph+ ( foldr+ (\v -> Map.insertWith (flip Set.difference) v $ Set.singleton u)+ ies+ vs+ )+ (Map.insertWith (flip Set.difference) u (Set.fromList vs) oes)++-- | Remove a vertex and its associations from a graph+remove :: (Ord a) => a -> Graph a -> Graph a+remove u (Graph ies oes) =+ Graph+ (Set.delete u <$> Map.delete u ies)+ (Set.delete u <$> Map.delete u oes)++-- | Reverse the edges of a graph+transpose :: Graph a -> Graph a+transpose (Graph ies oes) = Graph oes ies++-- Query++-- | Get the vertex associations of a graph+assocs :: Graph a -> [(a, [a])]+assocs (Graph _ oes) = second Set.toAscList <$> Map.toAscList oes++-- | Get the edges of a graph+edges :: Graph a -> [(a, a)]+edges (Graph _ oes) =+ Map.foldrWithKey+ (\u -> flip $ foldr (\v -> (:) (u, v)))+ []+ oes++-- | Get the number of incoming edges to a vertex in a graph+indegree :: (Ord a) => a -> Graph a -> Maybe Int+indegree v (Graph ies _) = Set.size <$> Map.lookup v ies++-- | Get the number of incoming edges of each vertex in a graph+indegrees :: Graph a -> [(a, Int)]+indegrees (Graph ies _) = Map.toAscList $ Set.size <$> ies++-- | Get the associations of a vertex from a graph+lookup :: (Ord a) => a -> Graph a -> Maybe [a]+lookup u (Graph _ oes) = Set.toAscList <$> Map.lookup u oes++-- | Get the associations of the least vertex greater than or equal to a vertex+lookupGE :: (Ord a) => a -> Graph a -> Maybe (a, [a])+lookupGE a (Graph _ oes) = second Set.toAscList <$> Map.lookupGE a oes++-- | Get the associations of the least vertex strictly greater than a vertex+lookupGT :: (Ord a) => a -> Graph a -> Maybe (a, [a])+lookupGT a (Graph _ oes) = second Set.toAscList <$> Map.lookupGT a oes++-- | Get the associations of the greatest vertex less than or equal to a vertex+lookupLE :: (Ord a) => a -> Graph a -> Maybe (a, [a])+lookupLE a (Graph _ oes) = second Set.toAscList <$> Map.lookupLE a oes++-- | Get the associations of the greatest vertex strictly less than a vertex+lookupLT :: (Ord a) => a -> Graph a -> Maybe (a, [a])+lookupLT a (Graph _ oes) = second Set.toAscList <$> Map.lookupLT a oes++-- | Get the associations of the maximum vertex from a graph+lookupMax :: Graph a -> Maybe (a, [a])+lookupMax (Graph _ oes) = second Set.toAscList <$> Map.lookupMax oes++-- | Get the associations of the minimum vertex from a graph+lookupMin :: Graph a -> Maybe (a, [a])+lookupMin (Graph _ oes) = second Set.toAscList <$> Map.lookupMin oes++-- | Check whether a vertex is in a graph+member :: (Ord a) => a -> Graph a -> Bool+member u (Graph _ oes) = u `Map.member` oes++-- | Get the number of outgoing edges from a vertex in a graph+outdegree :: (Ord a) => a -> Graph a -> Maybe Int+outdegree u (Graph _ oes) = Set.size <$> Map.lookup u oes++-- | Get the number of outgoing edges of each vertex in a graph+outdegrees :: Graph a -> [(a, Int)]+outdegrees (Graph _ oes) = Map.toAscList $ Set.size <$> oes++-- | Get the maximum vertex with no outgoing edges from a graph+sinkMax :: Graph a -> Maybe a+sinkMax (Graph _ oes) =+ Map.foldlWithKey+ ( \b k ->+ bool+ b+ (Just k)+ . Set.null+ )+ Nothing+ oes++-- | Get the minimum vertex with no outgoing edges from a graph+sinkMin :: Graph a -> Maybe a+sinkMin (Graph _ oes) =+ Map.foldrWithKey+ ( \k a b ->+ bool+ b+ (Just k)+ $ Set.null a+ )+ Nothing+ oes++-- | Get the vertices with no outgoing edges from a graph+sinks :: Graph a -> [a]+sinks (Graph _ oes) =+ Map.foldrWithKey+ ( \k a b ->+ bool+ b+ (k : b)+ $ Set.null a+ )+ []+ oes++-- | Get the maximum vertex with no incoming edges from a graph+sourceMax :: Graph a -> Maybe a+sourceMax (Graph ies _) =+ Map.foldlWithKey+ ( \b k ->+ bool+ b+ (Just k)+ . Set.null+ )+ Nothing+ ies++-- | Get the minimum vertex with no incoming edges from a graph+sourceMin :: Graph a -> Maybe a+sourceMin (Graph ies _) =+ Map.foldrWithKey+ ( \k a b ->+ bool+ b+ (Just k)+ $ Set.null a+ )+ Nothing+ ies++-- | Get the vertices with no incoming edges from a graph+sources :: Graph a -> [a]+sources (Graph ies _) =+ Map.foldrWithKey+ ( \k a b ->+ bool+ b+ (k : b)+ $ Set.null a+ )+ []+ ies++-- | Get the vertices of a graph+vertices :: Graph a -> [a]+vertices (Graph _ oes) = fst <$> Map.toAscList oes++-- Helpers++-- | Breadth-first search for the hierarchy in a graph from a starting vertex+bfs :: (Ord a) => Graph a -> a -> [Set a]+bfs (Graph _ oes) s =+ foldMap+ ( \vs ->+ Set.singleton s+ : unfoldr+ ( \((us, es), ds) ->+ bool+ ( Just+ ( us+ ,+ ( foldr+ ( \u b@(us', es') ->+ maybe+ b+ ( \vs' ->+ ( (us' <> vs') `Set.difference` ds+ , Map.delete u es'+ )+ )+ $ Map.lookup u es+ )+ (Set.empty, es)+ us+ , ds <> us+ )+ )+ )+ Nothing+ $ Set.null us+ )+ ((vs, oes), Set.singleton s)+ )+ $ Map.lookup s oes
+ src/Mini/Data/Map.hs view
@@ -0,0 +1,1486 @@+{-# LANGUAGE LambdaCase #-}+-- incomplete patterns in 'fromDistinct{Asc,Desc}List'+{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}++-- | A structure mapping unique keys to values+module Mini.Data.Map (+ -- * Type+ Map,+ map,++ -- * Construction+ empty,+ fromAscList,+ fromAscListWith,+ fromAscListWithKey,+ fromDescList,+ fromDescListWith,+ fromDescListWithKey,+ fromDistinctAscList,+ fromDistinctDescList,+ fromList,+ fromListWith,+ fromListWithKey,+ singleton,++ -- * Combination+ compose,+ difference,+ differenceWith,+ differenceWithKey,+ intersection,+ intersectionWith,+ intersectionWithKey,+ union,+ unionWith,+ unionWithKey,+ unions,+ unionsWith,+ unionsWithKey,++ -- * Conversion+ toAscList,+ toDescList,++ -- * Fold+ foldlWithKey,+ foldrWithKey,++ -- * Modification+ adjust,+ adjustMax,+ adjustMaxWithKey,+ adjustMin,+ adjustMinWithKey,+ adjustWithKey,+ delete,+ deleteMax,+ deleteMin,+ filter,+ filterWithKey,+ insert,+ insertWith,+ insertWithKey,+ update,+ updateMax,+ updateMaxWithKey,+ updateMin,+ updateMinWithKey,+ updateWithKey,++ -- * Partition+ partition,+ partitionWithKey,+ split,+ splitMax,+ splitMin,++ -- * Query+ disjoint,+ isSubmapOf,+ isSubmapOfBy,+ lookup,+ lookupGE,+ lookupGT,+ lookupLE,+ lookupLT,+ lookupMax,+ lookupMin,+ member,+ null,+ size,++ -- * Traversal+ fmapWithKey,+ traverseWithKey,++ -- * Validation+ valid,+) where++import Control.Applicative (+ liftA2,+ (<|>),+ )+import Data.Bifunctor (+ bimap,+ first,+ second,+ )+import Data.Bool (+ bool,+ )+import Data.Function (+ on,+ )+import Mini.Data.Recursion (+ list,+ ordering,+ )+import Prelude (+ Applicative,+ Bool (+ False,+ True+ ),+ Eq,+ Foldable,+ Functor,+ Int,+ Maybe (+ Just,+ Nothing+ ),+ Monoid,+ Ord,+ Semigroup,+ Show,+ Traversable,+ compare,+ const,+ div,+ error,+ flip,+ fmap,+ foldl,+ foldr,+ fst,+ length,+ max,+ maybe,+ mempty,+ not,+ pure,+ show,+ splitAt,+ traverse,+ uncurry,+ until,+ ($),+ (&&),+ (*),+ (+),+ (-),+ (.),+ (<),+ (<$>),+ (<*>),+ (<>),+ (==),+ (>),+ (||),+ )++-- Type++-- | A map from keys /k/ to values /a/, internally structured as an AVL tree+data Map k a+ = -- | Empty bin+ E+ | -- | Left-heavy bin+ L (Map k a) k a (Map k a)+ | -- | Balanced bin+ B (Map k a) k a (Map k a)+ | -- | Right-heavy bin+ R (Map k a) k a (Map k a)++instance (Eq k, Eq a) => Eq (Map k a) where+ (==) = (==) `on` toAscList++instance (Ord k, Ord a) => Ord (Map k a) where+ compare = compare `on` toAscList++instance (Show k, Show a) => Show (Map k a) where+ show = show . toAscList++instance Functor (Map k) where+ fmap = fmapWithKey . const++instance Foldable (Map k) where+ foldr = foldrWithKey . const++instance Traversable (Map k) where+ traverse = traverseWithKey . const++instance (Ord k) => Semigroup (Map k a) where+ (<>) = union++instance (Ord k) => Monoid (Map k a) where+ mempty = empty++-- | Primitive recursion on maps (internally structured as trees)+map+ :: b+ -- ^ Value yielded in case of empty node+ -> (Map k a -> k -> a -> Map k a -> b -> b -> b)+ -- ^ Function applied in case of non-empty node:+ -- left child, key, value, right child, left recursion, right recursion+ -- (keys are lesser to the left, greater to the right)+ -> Map k a+ -- ^ Object of the case analysis+ -> b+map e f = map' e f f f++-- Primitive recursion on maps+map'+ :: b+ -- ^ Value yielded in case of empty node+ -> (Map k a -> k -> a -> Map k a -> b -> b -> b)+ -- ^ Function applied in case of left-heavy node:+ -- left child, key, value, right child, left recursion, right recursion+ -- (keys are lesser to the left, greater to the right)+ -> (Map k a -> k -> a -> Map k a -> b -> b -> b)+ -- ^ Function applied in case of balanced node:+ -- left child, key, value, right child, left recursion, right recursion+ -- (keys are lesser to the left, greater to the right)+ -> (Map k a -> k -> a -> Map k a -> b -> b -> b)+ -- ^ Function applied in case of right-heavy node:+ -- left child, key, value, right child, left recursion, right recursion+ -- (keys are lesser to the left, greater to the right)+ -> Map k a+ -- ^ Object of the case analysis+ -> b+map' e f g h = \case+ L l k a r -> f l k a r (map' e f g h l) (map' e f g h r)+ R l k a r -> h l k a r (map' e f g h l) (map' e f g h r)+ B l k a r -> g l k a r (map' e f g h l) (map' e f g h r)+ E -> e++-- Construction++-- | /O(1)/ The empty map+empty :: Map k a+empty = E++-- | /O(n)/ Make a map from a tail-biased list of key-sorted pairs+fromAscList :: (Eq k) => [(k, a)] -> Map k a+fromAscList = fromDistinctAscList . essence++-- | /O(n)/ Make a map from a list of key-sorted pairs, combining matching keys+fromAscListWith :: (Ord k) => (a -> a -> a) -> [(k, a)] -> Map k a+fromAscListWith = fromAscListWithKey . const++-- | /O(n)/ Make a map from a list of key-sorted pairs, combining matching keys+fromAscListWithKey :: (Ord k) => (k -> a -> a -> a) -> [(k, a)] -> Map k a+fromAscListWithKey f = fromDistinctAscList . essenceWithKey f++-- | /O(n)/ Make a map from a tail-biased list of key-sorted pairs+fromDescList :: (Eq k) => [(k, a)] -> Map k a+fromDescList = fromDistinctDescList . essence++-- | /O(n)/ Make a map from a list of key-sorted pairs, combining matching keys+fromDescListWith :: (Ord k) => (a -> a -> a) -> [(k, a)] -> Map k a+fromDescListWith = fromDescListWithKey . const++-- | /O(n)/ Make a map from a list of key-sorted pairs, combining matching keys+fromDescListWithKey :: (Ord k) => (k -> a -> a -> a) -> [(k, a)] -> Map k a+fromDescListWithKey f = fromDistinctDescList . essenceWithKey f++-- | /O(n)/ Make a map from a sorted list of key-distinct pairs+fromDistinctAscList :: [(k, a)] -> Map k a+fromDistinctAscList = go <*> power+ where+ go ps n = list E go' ps+ where+ go' (k, a) = const . list (B E k a E) go''+ where+ go'' _ _ _ =+ let len = length ps+ n' = n `div` 2+ c = bool B L $ len == n+ (l, (k', a') : r) = splitAt (len `div` 2) ps+ in c (go l n') k' a' (go r n')++-- | /O(n)/ Make a map from a sorted list of key-distinct pairs+fromDistinctDescList :: [(k, a)] -> Map k a+fromDistinctDescList = go <*> power+ where+ go ps n = list E go' ps+ where+ go' (k, a) = const . list (B E k a E) go''+ where+ go'' _ _ _ =+ let len = length ps+ n' = n `div` 2+ c = bool B R $ len == n+ (l, (k', a') : r) = splitAt (len `div` 2) ps+ in c (go r n') k' a' (go l n')++-- | /O(n log n)/ Make a map from a tail-biased list of @(key, value)@ pairs+fromList :: (Ord k) => [(k, a)] -> Map k a+fromList = fromListWithKey $ const const++-- | /O(n log n)/ Make a map from a list of pairs, combining matching keys+fromListWith :: (Ord k) => (a -> a -> a) -> [(k, a)] -> Map k a+fromListWith = fromListWithKey . const++-- | /O(n log n)/ Make a map from a list of pairs, combining matching keys+fromListWithKey :: (Ord k) => (k -> a -> a -> a) -> [(k, a)] -> Map k a+fromListWithKey f = foldl (flip . uncurry $ insertWithKey f) empty++-- | /O(1)/ Make a map with a single bin+singleton :: k -> a -> Map k a+singleton k a = B E k a E++-- Combination++-- | /O(n log m)/ Compose the keys of one set with the values of another+compose :: (Ord b) => Map b c -> Map a b -> Map a c+compose t1 t2 = map' empty go go go t1+ where+ go _ _ _ _ _ _ =+ fromDistinctAscList $+ foldrWithKey+ (\a b ac -> maybe ac (\c -> (a, c) : ac) $ lookup b t1)+ []+ t2++-- | /O(m log n)/ Subtract a map by another via key matching+difference :: (Ord k) => Map k a -> Map k b -> Map k a+difference t1 t2 = map' empty go go go t1+ where+ go _ _ _ _ _ _ = foldrWithKey (\k _ b -> delete k b) t1 t2++-- | /O(m log n)/ Subtract a map by another, updating bins of matching keys+differenceWith+ :: (Ord k) => (a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a+differenceWith = differenceWithKey . const++-- | /O(m log n)/ Subtract a map by another, updating bins of matching keys+differenceWithKey+ :: (Ord k) => (k -> a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a+differenceWithKey f t1 t2 = map' empty go go go t1+ where+ go _ _ _ _ _ _ =+ foldrWithKey+ ( \k b t' ->+ maybe+ t'+ ( \a ->+ maybe+ (delete' k t')+ (\a' -> insert k a' t')+ $ f k a b+ )+ $ lookup k t1+ )+ t1+ t2++-- | /O(n log m)/ Intersect a map with another via left-biased key matching+intersection :: (Ord k) => Map k a -> Map k b -> Map k a+intersection = intersectionWithKey $ const const++-- | /O(n log m)/ Intersect a map with another by key matching, combining values+intersectionWith :: (Ord k) => (a -> b -> c) -> Map k a -> Map k b -> Map k c+intersectionWith = intersectionWithKey . const++-- | /O(n log m)/ Intersect a map with another by key matching, combining values+intersectionWithKey+ :: (Ord k) => (k -> a -> b -> c) -> Map k a -> Map k b -> Map k c+intersectionWithKey f t1 t2 = map' empty go go go t2+ where+ go _ _ _ _ _ _ =+ fromDistinctAscList $+ foldrWithKey+ (\k a c -> maybe c (\b -> (k, f k a b) : c) $ lookup k t2)+ []+ t1++-- | /O(m log n)/ Unite a map with another via left-biased key matching+union :: (Ord k) => Map k a -> Map k a -> Map k a+union = unionWithKey $ const const++-- | /O(m log n)/ Unite a map with another, combining values of matching keys+unionWith :: (Ord k) => (a -> a -> a) -> Map k a -> Map k a -> Map k a+unionWith = unionWithKey . const++-- | /O(m log n)/ Unite a map with another, combining values of matching keys+unionWithKey :: (Ord k) => (k -> a -> a -> a) -> Map k a -> Map k a -> Map k a+unionWithKey f t1 t2 = map' t1 go go go t2+ where+ go _ _ _ _ _ _ = foldrWithKey (insertWithKey f) t2 t1++-- | Unite a collection of maps via left-biased key matching+unions :: (Foldable t, Ord k) => t (Map k a) -> Map k a+unions = unionsWithKey $ const const++-- | Unite a collection of maps, combining values of matching keys+unionsWith :: (Foldable t, Ord k) => (a -> a -> a) -> t (Map k a) -> Map k a+unionsWith = unionsWithKey . const++-- | Unite a collection of maps, combining values of matching keys+unionsWithKey :: (Foldable t, Ord k) => (k -> a -> a -> a) -> t (Map k a) -> Map k a+unionsWithKey f = foldr (unionWithKey f) empty++-- Conversion++-- | /O(n)/ Turn a map into a list of @(key, value)@ pairs in ascending order+toAscList :: Map k a -> [(k, a)]+toAscList = foldrWithKey (\k a b -> (k, a) : b) []++-- | /O(n)/ Turn a map into a list of @(key, value)@ pairs in descending order+toDescList :: Map k a -> [(k, a)]+toDescList = foldlWithKey (\b k a -> (k, a) : b) []++-- Fold++-- | /O(n)/ Reduce a map with a left-associative operation and an accumulator+foldlWithKey :: (b -> k -> a -> b) -> b -> Map k a -> b+foldlWithKey f b = map' b go go go+ where+ go _ k a r recl _ = foldlWithKey f (f recl k a) r++-- | /O(n)/ Reduce a map with a right-associative operation and an accumulator+foldrWithKey :: (k -> a -> b -> b) -> b -> Map k a -> b+foldrWithKey f b = map' b go go go+ where+ go l k a _ _ recr = foldrWithKey f (f k a recr) l++-- Modification++-- | /O(log n)/ Adjust with an operation the value of a key in a map+adjust :: (Ord k) => (a -> a) -> k -> Map k a -> Map k a+adjust = adjustWithKey . const++-- | /O(log n)/ Adjust with an operation the value of the maximum key in a map+adjustMax :: (a -> a) -> Map k a -> Map k a+adjustMax = adjustMaxWithKey . const++-- | /O(log n)/ Adjust with an operation the value of the maximum key in a map+adjustMaxWithKey :: (k -> a -> a) -> Map k a -> Map k a+adjustMaxWithKey f = map' E (go L) (go B) (go R)+ where+ go c l k a r _ recr = map' (c l k (f k a) r) go' go' go' r+ where+ go' _ _ _ _ _ _ = c l k a recr++-- | /O(log n)/ Adjust with an operation the value of the minimum key in a map+adjustMin :: (a -> a) -> Map k a -> Map k a+adjustMin = adjustMinWithKey . const++-- | /O(log n)/ Adjust with an operation the value of the minimum key in a map+adjustMinWithKey :: (k -> a -> a) -> Map k a -> Map k a+adjustMinWithKey f = map' E (go L) (go B) (go R)+ where+ go c l k a r recl _ = map' (c l k (f k a) r) go' go' go' l+ where+ go' _ _ _ _ _ _ = c recl k a r++-- | /O(log n)/ Adjust with an operation the value of a key in a map+adjustWithKey :: (Ord k) => (k -> a -> a) -> k -> Map k a -> Map k a+adjustWithKey f k0 = map' E (go L) (go B) (go R)+ where+ go c l k a r recl recr =+ ordering+ (c recl k a r)+ (c l k (f k a) r)+ (c l k a recr)+ $ compare k0 k++-- | /O(log n)/ Delete a key from a map+delete :: (Ord k) => k -> Map k a -> Map k a+delete k t = bool t (delete' k t) $ k `member` t++-- | /O(log n)/ Delete the maximum key from a map+deleteMax :: (Ord k) => Map k a -> Map k a+deleteMax t = maybe t (flip delete' t . fst) $ lookupMax t++-- | /O(log n)/ Delete the minimum key from a map+deleteMin :: (Ord k) => Map k a -> Map k a+deleteMin t = maybe t (flip delete' t . fst) $ lookupMin t++-- | /O(n)/ Keep the bins whose values satisfy a predicate+filter :: (a -> Bool) -> Map k a -> Map k a+filter = filterWithKey . const++-- | /O(n)/ Keep the bins whose keys and values satisfy a predicate+filterWithKey :: (k -> a -> Bool) -> Map k a -> Map k a+filterWithKey p =+ fromDistinctAscList+ . foldrWithKey (\k a b -> bool b ((k, a) : b) $ p k a) []++-- | /O(log n)/ Insert a key and its value into a map, overwriting if present+insert :: (Ord k) => k -> a -> Map k a -> Map k a+insert = insertWithKey $ const const++-- | /O(log n)/ Insert a key and its value, combining new and old if present+insertWith :: (Ord k) => (a -> a -> a) -> k -> a -> Map k a -> Map k a+insertWith = insertWithKey . const++-- | /O(log n)/ Modify the value of a key or delete its bin with an operation+update :: (Ord k) => (a -> Maybe a) -> k -> Map k a -> Map k a+update = updateWithKey . const++-- | /O(log n)/ Modify the value of the maximum key or delete its bin+updateMax :: (Ord k) => (a -> Maybe a) -> Map k a -> Map k a+updateMax = updateMaxWithKey . const++-- | /O(log n)/ Modify the value of the maximum key or delete its bin+updateMaxWithKey :: (Ord k) => (k -> a -> Maybe a) -> Map k a -> Map k a+updateMaxWithKey f t =+ maybe+ t+ ( \(k, a) ->+ maybe+ (delete' k t)+ (\a' -> insert k a' t)+ $ f k a+ )+ $ lookupMax t++-- | /O(log n)/ Modify the value of the minimum key or delete its bin+updateMin :: (Ord k) => (a -> Maybe a) -> Map k a -> Map k a+updateMin = updateMinWithKey . const++-- | /O(log n)/ Modify the value of the minimum key or delete its bin+updateMinWithKey :: (Ord k) => (k -> a -> Maybe a) -> Map k a -> Map k a+updateMinWithKey f t =+ maybe+ t+ ( \(k, a) ->+ maybe+ (delete' k t)+ (\a' -> insert k a' t)+ $ f k a+ )+ $ lookupMin t++-- | /O(log n)/ Modify the value of a key or delete its bin with an operation+updateWithKey :: (Ord k) => (k -> a -> Maybe a) -> k -> Map k a -> Map k a+updateWithKey f k t =+ maybe+ t+ ( maybe+ (delete' k t)+ (\a' -> insert k a' t)+ . f k+ )+ $ lookup k t++-- Partition++-- | /O(n)/ Partition a map with a predicate into @(true, false)@ submaps+partition :: (a -> Bool) -> Map k a -> (Map k a, Map k a)+partition = partitionWithKey . const++-- | /O(n)/ Partition a map with a predicate into @(true, false)@ submaps+partitionWithKey :: (k -> a -> Bool) -> Map k a -> (Map k a, Map k a)+partitionWithKey p =+ bimap fromDistinctAscList fromDistinctAscList+ . foldrWithKey+ (\k a -> bool second first (p k a) ((k, a) :))+ ([], [])++-- | /O(n)/ Split a map by a key into @(lt, eq, gt)@ submaps+split :: (Ord k) => k -> Map k a -> (Map k a, Maybe a, Map k a)+split k0 =+ (\(lt, a, gt) -> (fromDistinctAscList lt, a, fromDistinctAscList gt))+ . foldrWithKey+ ( \k a (lt, a', gt) ->+ ordering+ ((k, a) : lt, a', gt)+ (lt, Just a, gt)+ (lt, a', (k, a) : gt)+ $ compare k k0+ )+ ([], Nothing, [])++-- | /O(log n)/ Split a map by its maximum key+splitMax :: (Ord k) => Map k a -> Maybe ((k, a), Map k a)+splitMax t = ((,) <*> flip delete' t . fst) <$> lookupMax t++-- | /O(log n)/ Split a map by its minimum key+splitMin :: (Ord k) => Map k a -> Maybe ((k, a), Map k a)+splitMin t = ((,) <*> flip delete' t . fst) <$> lookupMin t++-- Query++-- | /O(m log n)/ Check whether two maps have no keys in common+disjoint :: (Ord k) => Map k a -> Map k a -> Bool+disjoint t1 t2 = map' True go go go t1+ where+ go _ _ _ _ _ _ = not $ foldrWithKey (\k _ b -> k `member` t1 || b) False t2++-- | /O(n log m)/ Check whether the bins of one map exist in the other+isSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool+isSubmapOf = isSubmapOfBy (==)++-- | /O(n log m)/ Check if the bins of one map exist in the other by combination+isSubmapOfBy :: (Ord k) => (a -> b -> Bool) -> Map k a -> Map k b -> Bool+isSubmapOfBy p t1 t2 = map' (null t1) go go go t2+ where+ go _ _ _ _ _ _ =+ foldrWithKey+ (\k a b -> maybe False ((&& b) . p a) $ lookup k t2)+ True+ t1++-- | /O(log n)/ Fetch the value of a key in a map+lookup :: (Ord k) => k -> Map k a -> Maybe a+lookup k = map' Nothing go go go+ where+ go _ k' a _ recl recr =+ ordering+ recl+ (Just a)+ recr+ $ compare k k'++-- | /O(log n)/ Fetch the least bin greater than or equal to a key+lookupGE :: (Ord k) => k -> Map k a -> Maybe (k, a)+lookupGE k0 = map' Nothing go go go+ where+ go _ k a _ recl recr =+ ordering+ recr+ (Just (k, a))+ (recl <|> Just (k, a))+ $ compare k k0++-- | /O(log n)/ Fetch the least bin strictly greater than a key+lookupGT :: (Ord k) => k -> Map k a -> Maybe (k, a)+lookupGT k0 = map' Nothing go go go+ where+ go _ k a _ recl recr =+ ordering+ recr+ recr+ (recl <|> Just (k, a))+ $ compare k k0++-- | /O(log n)/ Fetch the greatest bin less than or equal to a key+lookupLE :: (Ord k) => k -> Map k a -> Maybe (k, a)+lookupLE k0 = map' Nothing go go go+ where+ go _ k a _ recl recr =+ ordering+ (recr <|> Just (k, a))+ (Just (k, a))+ recl+ $ compare k k0++-- | /O(log n)/ Fetch the greatest bin strictly less than a key+lookupLT :: (Ord k) => k -> Map k a -> Maybe (k, a)+lookupLT k0 = map' Nothing go go go+ where+ go _ k a _ recl recr =+ ordering+ (recr <|> Just (k, a))+ recl+ recl+ $ compare k k0++-- | /O(log n)/ Fetch the bin with the maximum key+lookupMax :: Map k a -> Maybe (k, a)+lookupMax = map' Nothing go go go+ where+ go _ k a r _ recr = map' (Just (k, a)) go' go' go' r+ where+ go' _ _ _ _ _ _ = recr++-- | /O(log n)/ Fetch the bin with the minimum key+lookupMin :: Map k a -> Maybe (k, a)+lookupMin = map' Nothing go go go+ where+ go l k a _ recl _ = map' (Just (k, a)) go' go' go' l+ where+ go' _ _ _ _ _ _ = recl++-- | /O(log n)/ Check whether a key is in a map+member :: (Ord k) => k -> Map k a -> Bool+member k0 = map' False go go go+ where+ go _ k _ _ recl recr =+ ordering+ recl+ True+ recr+ $ compare k0 k++-- | /O(1)/ Check whether a map is empty+null :: Map k a -> Bool+null = map' True go go go where go _ _ _ _ _ _ = False++-- | /O(n)/ Get the size of a map+size :: Map k a -> Int+size = map' 0 go go go where go _ _ _ _ recl recr = 1 + recl + recr++-- Traversal++-- | /O(n)/ Apply an operation across a map, transforming its values+fmapWithKey :: (k -> a -> b) -> Map k a -> Map k b+fmapWithKey f = map' E (go L) (go B) (go R)+ where+ go c _ k a _ recl = c recl k (f k a)++-- | /O(n)/ Lift a map with a lifting operation on keys and values+traverseWithKey :: (Applicative f) => (k -> a -> f b) -> Map k a -> f (Map k b)+traverseWithKey f = map' (pure E) (go L) (go B) (go R)+ where+ go c _ k a _ recl recr = c <$> recl <*> pure k <*> f k a <*> recr++-- Validation++-- | /O(n^2)/ Check whether a map is internally height-balanced and ordered+valid :: (Ord k) => Map k a -> Bool+valid = liftA2 (&&) balanced ordered+ where+ balanced =+ map'+ True+ (\l _ _ r recl recr -> levels l - levels r == 1 && recl && recr)+ (\l _ _ r recl recr -> levels l - levels r == 0 && recl && recr)+ (\l _ _ r recl recr -> levels r - levels l == 1 && recl && recr)+ levels = map' 0 go go go+ where+ go _ _ _ _ recl recr = 1 + max recl recr :: Int+ ordered = map' True go go go+ where+ go l k _ r recl recr =+ map' True lt lt lt l+ && map' True gt gt gt r+ where+ lt _ lk _ _ _ _ = lk < k && recl && recr+ gt _ rk _ _ _ _ = rk > k && recl && recr++-- Helpers++-- O(n) 'nub' on keys for sorted lists of pairs+essence :: (Eq k) => [(k, a)] -> [(k, a)]+essence = list [] go+ where+ go p1@(k1, _) ps rec = list [p1] go' ps+ where+ go' (k2, _) _ _ = bool (p1 : rec) rec $ k1 == k2++-- O(n) 'nub' with a combining function for sorted lists of pairs+essenceWithKey :: (Eq k) => (k -> a -> a -> a) -> [(k, a)] -> [(k, a)]+essenceWithKey f = list [] (\p -> const . go p)+ where+ go p1@(k1, a1) = list [p1] go'+ where+ go' p2@(k2, a2) ps _ =+ bool+ (p1 : go p2 ps)+ (go (k1, f k1 a2 a1) ps)+ $ k1 == k2++-- O(log n) The greatest power of 2 <= the length of a non-empty collection+power :: (Foldable t) => t a -> Int+power as = until (> length as) (* 2) 2 `div` 2++{-+ - Let this comment serve as your warning. Return from whence you came and your+ - sanity will be spared. You have been admonished.+ -}++-- O(log n) Delete a key from a map without checking for membership+delete' :: (Ord k) => k -> Map k a -> Map k a+delete' k0 =+ map'+ (error "Map.delete: L0")+ ( \l k a r _ _ ->+ ordering+ (deleteLl l k a r)+ (substituteL l r)+ (deleteLr l k a r)+ $ compare k0 k+ )+ ( \l k a r _ _ ->+ ordering+ (deleteBl l k a r)+ (substituteBr l r)+ (deleteBr l k a r)+ $ compare k0 k+ )+ ( \l k a r _ _ ->+ ordering+ (deleteRl l k a r)+ (substituteR l r)+ (deleteRr l k a r)+ $ compare k0 k+ )+ where+ deleteRl l k a r =+ map'+ (error "Map.delete: L1")+ ( \ll lk la lr _ _ ->+ ordering+ (checkLeftR (deleteLl ll lk la lr) k a r)+ (checkLeftR (substituteL ll lr) k a r)+ (checkLeftR (deleteLr ll lk la lr) k a r)+ $ compare k0 lk+ )+ ( \ll lk la lr _ _ ->+ ordering+ (R (deleteBl ll lk la lr) k a r)+ (checkLeftR' (substituteBr ll lr) k a r)+ (R (deleteBr ll lk la lr) k a r)+ $ compare k0 lk+ )+ ( \ll lk la lr _ _ ->+ ordering+ (checkLeftR (deleteRl ll lk la lr) k a r)+ (checkLeftR (substituteR ll lr) k a r)+ (checkLeftR (deleteRr ll lk la lr) k a r)+ $ compare k0 lk+ )+ l+ deleteRr l k a =+ map'+ (error "Map.delete: L2")+ ( \rl rk ra rr _ _ ->+ ordering+ (checkRightR l k a $ deleteLl rl rk ra rr)+ (checkRightR l k a $ substituteL rl rr)+ (checkRightR l k a $ deleteLr rl rk ra rr)+ $ compare k0 rk+ )+ ( \rl rk ra rr _ _ ->+ ordering+ (R l k a $ deleteBl rl rk ra rr)+ (checkRightR' l k a $ substituteBl rl rr)+ (R l k a $ deleteBr rl rk ra rr)+ $ compare k0 rk+ )+ ( \rl rk ra rr _ _ ->+ ordering+ (checkRightR l k a $ deleteRl rl rk ra rr)+ (checkRightR l k a $ substituteR rl rr)+ (checkRightR l k a $ deleteRr rl rk ra rr)+ $ compare k0 rk+ )+ deleteBl l k a r =+ map'+ (error "Map.delete: L3")+ ( \ll lk la lr _ _ ->+ ordering+ (checkLeftB (deleteLl ll lk la lr) k a r)+ (checkLeftB (substituteL ll lr) k a r)+ (checkLeftB (deleteLr ll lk la lr) k a r)+ $ compare k0 lk+ )+ ( \ll lk la lr _ _ ->+ ordering+ (B (deleteBl ll lk la lr) k a r)+ (checkLeftB' (substituteBr ll lr) k a r)+ (B (deleteBr ll lk la lr) k a r)+ $ compare k0 lk+ )+ ( \ll lk la lr _ _ ->+ ordering+ (checkLeftB (deleteRl ll lk la lr) k a r)+ (checkLeftB (substituteR ll lr) k a r)+ (checkLeftB (deleteRr ll lk la lr) k a r)+ $ compare k0 lk+ )+ l+ deleteBr l k a =+ map'+ (error "Map.delete: L4")+ ( \rl rk ra rr _ _ ->+ ordering+ (checkRightB l k a $ deleteLl rl rk ra rr)+ (checkRightB l k a $ substituteL rl rr)+ (checkRightB l k a $ deleteLr rl rk ra rr)+ $ compare k0 rk+ )+ ( \rl rk ra rr _ _ ->+ ordering+ (B l k a $ deleteBl rl rk ra rr)+ (checkRightB' l k a $ substituteBl rl rr)+ (B l k a $ deleteBr rl rk ra rr)+ $ compare k0 rk+ )+ ( \rl rk ra rr _ _ ->+ ordering+ (checkRightB l k a $ deleteRl rl rk ra rr)+ (checkRightB l k a $ substituteR rl rr)+ (checkRightB l k a $ deleteRr rl rk ra rr)+ $ compare k0 rk+ )+ deleteLl l k a r =+ map'+ (error "Map.delete: L5")+ ( \ll lk la lr _ _ ->+ ordering+ (checkLeftL (deleteLl ll lk la lr) k a r)+ (checkLeftL (substituteL ll lr) k a r)+ (checkLeftL (deleteLr ll lk la lr) k a r)+ $ compare k0 lk+ )+ ( \ll lk la lr _ _ ->+ ordering+ (L (deleteBl ll lk la lr) k a r)+ (checkLeftL' (substituteBr ll lr) k a r)+ (L (deleteBr ll lk la lr) k a r)+ $ compare k0 lk+ )+ ( \ll lk la lr _ _ ->+ ordering+ (checkLeftL (deleteRl ll lk la lr) k a r)+ (checkLeftL (substituteR ll lr) k a r)+ (checkLeftL (deleteRr ll lk la lr) k a r)+ $ compare k0 lk+ )+ l+ deleteLr l k a =+ map'+ (error "Map.delete: L6")+ ( \rl rk ra rr _ _ ->+ ordering+ (checkRightL l k a $ deleteLl rl rk ra rr)+ (checkRightL l k a $ substituteL rl rr)+ (checkRightL l k a $ deleteLr rl rk ra rr)+ $ compare k0 rk+ )+ ( \rl rk ra rr _ _ ->+ ordering+ (L l k a $ deleteBl rl rk ra rr)+ (checkRightL' l k a $ substituteBl rl rr)+ (L l k a $ deleteBr rl rk ra rr)+ $ compare k0 rk+ )+ ( \rl rk ra rr _ _ ->+ ordering+ (checkRightL l k a $ deleteRl rl rk ra rr)+ (checkRightL l k a $ substituteR rl rr)+ (checkRightL l k a $ deleteRr rl rk ra rr)+ $ compare k0 rk+ )+ rebalanceR l k a =+ map'+ (error "Map.delete: L7")+ ( \rl rk ra rr _ _ ->+ map'+ (error "Map.delete: L8")+ (\rll rlk rla rlr _ _ -> B (B l k a rll) rlk rla $ R rlr rk ra rr)+ (\rll rlk rla rlr _ _ -> B (B l k a rll) rlk rla $ B rlr rk ra rr)+ (\rll rlk rla rlr _ _ -> B (L l k a rll) rlk rla $ B rlr rk ra rr)+ rl+ )+ (\rl rk ra rr _ _ -> L (R l k a rl) rk ra rr)+ (\rl rk ra rr _ _ -> B (B l k a rl) rk ra rr)+ rebalanceL l k a r =+ map'+ (error "Map.delete: L9")+ (\ll lk la lr _ _ -> B ll lk la $ B lr k a r)+ (\ll lk la lr _ _ -> R ll lk la $ L lr k a r)+ ( \ll lk la lr _ _ ->+ map'+ (error "Map.delete: L10")+ (\lrl lrk lra lrr _ _ -> B (B ll lk la lrl) lrk lra $ R lrr k a r)+ (\lrl lrk lra lrr _ _ -> B (B ll lk la lrl) lrk lra $ B lrr k a r)+ (\lrl lrk lra lrr _ _ -> B (L ll lk la lrl) lrk lra $ B lrr k a r)+ lr+ )+ l+ checkLeftR l k a r =+ map'+ (error "Map.delete: L11")+ (\_ _ _ _ _ _ -> R l k a r)+ (\_ _ _ _ _ _ -> rebalanceR l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ l+ checkLeftB l k a r =+ map'+ (error "Map.delete: L12")+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ l+ checkLeftL l k a r =+ map'+ (error "Map.delete: L13")+ (\_ _ _ _ _ _ -> L l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ l+ checkRightR l k a r =+ map'+ (error "Map.delete: L14")+ (\_ _ _ _ _ _ -> R l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ r+ checkRightB l k a r =+ map'+ (error "Map.delete: L15")+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ r+ checkRightL l k a r =+ map'+ (error "Map.delete: L16")+ (\_ _ _ _ _ _ -> L l k a r)+ (\_ _ _ _ _ _ -> rebalanceL l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ r+ substituteR l =+ map'+ (error "Map.delete: L17")+ ( \rl rk ra rr _ _ ->+ (\(k, a, r) -> checkRightR l k a r) $+ popLeftL rl rk ra rr+ )+ ( \rl rk ra rr _ _ ->+ (\(k, a, r) -> checkRightR' l k a r) $+ popLeftB rl rk ra rr+ )+ ( \rl rk ra rr _ _ ->+ (\(k, a, r) -> checkRightR l k a r) $+ popLeftR rl rk ra rr+ )+ substituteBr l =+ map'+ E+ ( \rl rk ra rr _ _ ->+ (\(k, a, r) -> checkRightB l k a r) $+ popLeftL rl rk ra rr+ )+ ( \rl rk ra rr _ _ ->+ (\(k, a, r) -> checkRightB' l k a r) $+ popLeftB rl rk ra rr+ )+ ( \rl rk ra rr _ _ ->+ (\(k, a, r) -> checkRightB l k a r) $+ popLeftR rl rk ra rr+ )+ substituteBl l r =+ map'+ E+ ( \ll lk la lr _ _ ->+ (\(l', k, a) -> checkLeftB l' k a r) $+ popRightL ll lk la lr+ )+ ( \ll lk la lr _ _ ->+ (\(l', k, a) -> checkLeftB' l' k a r) $+ popRightB ll lk la lr+ )+ ( \ll lk la lr _ _ ->+ (\(l', k, a) -> checkLeftB l' k a r) $+ popRightR ll lk la lr+ )+ l+ substituteL l r =+ map'+ (error "Map.delete: L18")+ ( \ll lk la lr _ _ ->+ (\(l', k, a) -> checkLeftL l' k a r) $+ popRightL ll lk la lr+ )+ ( \ll lk la lr _ _ ->+ (\(l', k, a) -> checkLeftL' l' k a r) $+ popRightB ll lk la lr+ )+ ( \ll lk la lr _ _ ->+ (\(l', k, a) -> checkLeftL l' k a r) $+ popRightR ll lk la lr+ )+ l+ checkLeftR' l k a r =+ map'+ (rebalanceR l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ l+ checkLeftB' l k a r =+ map'+ (R l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ l+ checkLeftL' l k a r =+ map'+ (B l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ l+ checkRightR' l k a r =+ map'+ (B l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ r+ checkRightB' l k a r =+ map'+ (L l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ r+ checkRightL' l k a r =+ map'+ (rebalanceL l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ r+ popLeftR l k a r =+ map'+ (k, a, r)+ ( \ll lk la lr _ _ ->+ (\(k', a', l') -> (k', a', checkLeftR l' k a r)) $+ popLeftL ll lk la lr+ )+ (\ll lk la lr _ _ -> popLeftRB ll lk la lr k a r)+ ( \ll lk la lr _ _ ->+ (\(k', a', l') -> (k', a', checkLeftR l' k a r)) $+ popLeftR ll lk la lr+ )+ l+ popLeftB l k a r =+ map'+ (k, a, E)+ (\ll lk la lr _ _ -> popLeftBL ll lk la lr k a r)+ (\ll lk la lr _ _ -> popLeftBB ll lk la lr k a r)+ (\ll lk la lr _ _ -> popLeftBR ll lk la lr k a r)+ l+ popLeftL l k a r =+ map'+ (error "Map.delete: L19")+ ( \ll lk la lr _ _ ->+ (\(k', a', l') -> (k', a', checkLeftL l' k a r)) $+ popLeftL ll lk la lr+ )+ (\ll lk la lr _ _ -> popLeftLB ll lk la lr k a r)+ ( \ll lk la lr _ _ ->+ (\(k', a', l') -> (k', a', checkLeftL l' k a r)) $+ popLeftR ll lk la lr+ )+ l+ popLeftRB ll lk la lr k a r =+ map'+ (lk, la, rebalanceR E k a r)+ ( \lll llk lla llr _ _ ->+ (\(k', a', l) -> (k', a', R l k a r)) $+ popLeftBL lll llk lla llr lk la lr+ )+ ( \lll llk lla llr _ _ ->+ (\(k', a', l) -> (k', a', R l k a r)) $+ popLeftBB lll llk lla llr lk la lr+ )+ ( \lll llk lla llr _ _ ->+ (\(k', a', l) -> (k', a', R l k a r)) $+ popLeftBR lll llk lla llr lk la lr+ )+ ll+ popLeftBB ll lk la lr k a r =+ map'+ (lk, la, R E k a r)+ ( \lll llk lla llr _ _ ->+ (\(k', a', l) -> (k', a', B l k a r)) $+ popLeftBL lll llk lla llr lk la lr+ )+ ( \lll llk lla llr _ _ ->+ (\(k', a', l) -> (k', a', B l k a r)) $+ popLeftBB lll llk lla llr lk la lr+ )+ ( \lll llk lla llr _ _ ->+ (\(k', a', l) -> (k', a', B l k a r)) $+ popLeftBR lll llk lla llr lk la lr+ )+ ll+ popLeftLB ll lk la lr k a r =+ map'+ (lk, la, B E k a E)+ ( \lll llk lla llr _ _ ->+ (\(k', a', l) -> (k', a', L l k a r)) $+ popLeftBL lll llk lla llr lk la lr+ )+ ( \lll llk lla llr _ _ ->+ (\(k', a', l) -> (k', a', L l k a r)) $+ popLeftBB lll llk lla llr lk la lr+ )+ ( \lll llk lla llr _ _ ->+ (\(k', a', l) -> (k', a', L l k a r)) $+ popLeftBR lll llk lla llr lk la lr+ )+ ll+ popLeftBR ll lk la lr k a r =+ (\(k', a', l) -> (k', a', checkLeftB l k a r)) $+ popLeftR ll lk la lr+ popLeftBL ll lk la lr k a r =+ (\(k', a', l) -> (k', a', checkLeftB l k a r)) $+ popLeftL ll lk la lr+ popRightR l k a =+ map'+ (error "Map.delete: L20")+ ( \rl rk ra rr _ _ ->+ (\(r, k', a') -> (checkRightR l k a r, k', a')) $+ popRightL rl rk ra rr+ )+ (\rl rk ra rr _ _ -> popRightRB l k a rl rk ra rr)+ ( \rl rk ra rr _ _ ->+ (\(r, k', a') -> (checkRightR l k a r, k', a')) $+ popRightR rl rk ra rr+ )+ popRightB l k a =+ map'+ (E, k, a)+ (\rl rk ra rr _ _ -> popRightBL l k a rl rk ra rr)+ (\rl rk ra rr _ _ -> popRightBB l k a rl rk ra rr)+ (\rl rk ra rr _ _ -> popRightBR l k a rl rk ra rr)+ popRightL l k a =+ map'+ (l, k, a)+ ( \rl rk ra rr _ _ ->+ (\(r, k', a') -> (checkRightL l k a r, k', a')) $+ popRightL rl rk ra rr+ )+ (\rl rk ra rr _ _ -> popRightLB l k a rl rk ra rr)+ ( \rl rk ra rr _ _ ->+ (\(r, k', a') -> (checkRightL l k a r, k', a')) $+ popRightR rl rk ra rr+ )+ popRightRB l k a rl rk ra =+ map'+ (B E k a E, rk, ra)+ ( \rrl rrk rra rrr _ _ ->+ (\(r, k', a') -> (R l k a r, k', a')) $+ popRightBL rl rk ra rrl rrk rra rrr+ )+ ( \rrl rrk rra rrr _ _ ->+ (\(r, k', a') -> (R l k a r, k', a')) $+ popRightBB rl rk ra rrl rrk rra rrr+ )+ ( \rrl rrk rra rrr _ _ ->+ (\(r, k', a') -> (R l k a r, k', a')) $+ popRightBR rl rk ra rrl rrk rra rrr+ )+ popRightBB l k a rl rk ra =+ map'+ (L l k a E, rk, ra)+ ( \rrl rrk rra rrr _ _ ->+ (\(r, k', a') -> (B l k a r, k', a')) $+ popRightBL rl rk ra rrl rrk rra rrr+ )+ ( \rrl rrk rra rrr _ _ ->+ (\(r, k', a') -> (B l k a r, k', a')) $+ popRightBB rl rk ra rrl rrk rra rrr+ )+ ( \rrl rrk rra rrr _ _ ->+ (\(r, k', a') -> (B l k a r, k', a')) $+ popRightBR rl rk ra rrl rrk rra rrr+ )+ popRightLB l k a rl rk ra =+ map'+ (rebalanceL l k a E, rk, ra)+ ( \rrl rrk rra rrr _ _ ->+ (\(r, k', a') -> (L l k a r, k', a')) $+ popRightBL rl rk ra rrl rrk rra rrr+ )+ ( \rrl rrk rra rrr _ _ ->+ (\(r, k', a') -> (L l k a r, k', a')) $+ popRightBB rl rk ra rrl rrk rra rrr+ )+ ( \rrl rrk rra rrr _ _ ->+ (\(r, k', a') -> (L l k a r, k', a')) $+ popRightBR rl rk ra rrl rrk rra rrr+ )+ popRightBR l k a rl rk ra rr =+ (\(r, k', a') -> (checkRightB l k a r, k', a')) $+ popRightR rl rk ra rr+ popRightBL l k a rl rk ra rr =+ (\(r, k', a') -> (checkRightB l k a r, k', a')) $+ popRightL rl rk ra rr++-- | /O(log n)/ Insert a key and its value, combining new and old if present+insertWithKey :: (Ord k) => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a+insertWithKey f k0 a0 =+ map'+ (B E k0 a0 E)+ (\l k a r _ _ -> insertL l k a r)+ (\l k a r _ _ -> insertB l k a r)+ (\l k a r _ _ -> insertR l k a r)+ where+ insertR l k a r =+ ordering+ (insertRl l k a r)+ (R l k (f k a0 a) r)+ (insertRr l k a r)+ $ compare k0 k+ insertB l k a r =+ ordering+ (insertBl l k a r)+ (B l k (f k a0 a) r)+ (insertBr l k a r)+ $ compare k0 k+ insertL l k a r =+ ordering+ (insertLl l k a r)+ (L l k (f k a0 a) r)+ (insertLr l k a r)+ $ compare k0 k+ insertRl l k a r =+ map'+ (B (B E k0 a0 E) k a r)+ (\ll lk la lr _ _ -> R (insertL ll lk la lr) k a r)+ ( \ll lk la lr _ _ ->+ let l' = insertB ll lk la lr+ in map'+ (error "Map.insert: L0")+ (\_ _ _ _ _ _ -> B l' k a r)+ (\_ _ _ _ _ _ -> R l' k a r)+ (\_ _ _ _ _ _ -> B l' k a r)+ l'+ )+ (\ll lk la lr _ _ -> R (insertR ll lk la lr) k a r)+ l+ insertBl l k a r =+ map'+ (L (B E k0 a0 E) k a r)+ (\ll lk la lr _ _ -> B (insertL ll lk la lr) k a r)+ ( \ll lk la lr _ _ ->+ let l' = insertB ll lk la lr+ in map'+ (error "Map.insert: L1")+ (\_ _ _ _ _ _ -> L l' k a r)+ (\_ _ _ _ _ _ -> B l' k a r)+ (\_ _ _ _ _ _ -> L l' k a r)+ l'+ )+ (\ll lk la lr _ _ -> B (insertR ll lk la lr) k a r)+ l+ insertBr l k a =+ map'+ (R l k a $ B E k0 a0 E)+ (\rl rk ra rr _ _ -> B l k a $ insertL rl rk ra rr)+ ( \rl rk ra rr _ _ ->+ let r = insertB rl rk ra rr+ in map'+ (error "Map.insert: L2")+ (\_ _ _ _ _ _ -> R l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> R l k a r)+ r+ )+ (\rl rk ra rr _ _ -> B l k a $ insertR rl rk ra rr)+ insertLr l k a =+ map'+ (B l k a $ B E k0 a0 E)+ (\rl rk ra rr _ _ -> L l k a $ insertL rl rk ra rr)+ ( \rl rk ra rr _ _ ->+ let r = insertB rl rk ra rr+ in map'+ (error "Map.insert: L3")+ (\_ _ _ _ _ _ -> B l k a r)+ (\_ _ _ _ _ _ -> L l k a r)+ (\_ _ _ _ _ _ -> B l k a r)+ r+ )+ (\rl rk ra rr _ _ -> L l k a $ insertR rl rk ra rr)+ insertRr l k a =+ map'+ (error "Map.insert: L4")+ (\rl rk ra rr _ _ -> R l k a $ insertL rl rk ra rr)+ ( \rl rk ra rr _ _ ->+ ordering+ (insertRrl l k a rl rk ra rr)+ (R l k a $ B rl rk (f rk a0 ra) rr)+ (insertRrr l k a rl rk ra rr)+ $ compare k0 rk+ )+ (\rl rk ra rr _ _ -> R l k a $ insertR rl rk ra rr)+ insertLl l k a r =+ map'+ (error "Map.insert: L5")+ (\ll lk la lr _ _ -> L (insertL ll lk la lr) k a r)+ ( \ll lk la lr _ _ ->+ ordering+ (insertLll ll lk la lr k a r)+ (L (B ll lk (f lk a0 la) lr) k a r)+ (insertLlr ll lk la lr k a r)+ $ compare k0 lk+ )+ (\ll lk la lr _ _ -> L (insertR ll lk la lr) k a r)+ l+ insertRrr l k a rl rk ra =+ map'+ (B (B l k a rl) rk ra $ B E k0 a0 E)+ (\rrl rrk rra rrr _ _ -> R l k a . B rl rk ra $ insertL rrl rrk rra rrr)+ ( \rrl rrk rra rrr _ _ ->+ let rr = insertB rrl rrk rra rrr+ in map'+ (error "Map.insert: L6")+ (\_ _ _ _ _ _ -> B (B l k a rl) rk ra rr)+ (\_ _ _ _ _ _ -> R l k a $ B rl rk ra rr)+ (\_ _ _ _ _ _ -> B (B l k a rl) rk ra rr)+ rr+ )+ (\rrl rrk rra rrr _ _ -> R l k a . B rl rk ra $ insertR rrl rrk rra rrr)+ insertLll ll lk la lr k a r =+ map'+ (B (B E k0 a0 E) lk la $ B lr k a r)+ (\lll llk lla llr _ _ -> L (B (insertL lll llk lla llr) lk la lr) k a r)+ ( \lll llk lla llr _ _ ->+ let ll' = insertB lll llk lla llr+ in map'+ (error "Map.insert: L7")+ (\_ _ _ _ _ _ -> B ll' lk la $ B lr k a r)+ (\_ _ _ _ _ _ -> L (B ll' lk la lr) k a r)+ (\_ _ _ _ _ _ -> B ll' lk la $ B lr k a r)+ ll'+ )+ (\lll llk lla llr _ _ -> L (B (insertR lll llk lla llr) lk la lr) k a r)+ ll+ insertRrl l k a rl rk ra rr =+ map'+ (B (B l k a E) k0 a0 $ B E rk ra rr)+ (\rll rlk rla rlr _ _ -> R l k a $ B (insertL rll rlk rla rlr) rk ra rr)+ ( \rll rlk rla rlr _ _ ->+ let rl' = insertB rll rlk rla rlr+ in map'+ (error "Map.insert: L8")+ ( \rll' rlk' rla' rlr' _ _ ->+ B+ (B l k a rll')+ rlk'+ rla'+ (R rlr' rk ra rr)+ )+ (\_ _ _ _ _ _ -> R l k a $ B rl' rk ra rr)+ ( \rll' rlk' rla' rlr' _ _ ->+ B+ (L l k a rll')+ rlk'+ rla'+ (B rlr' rk ra rr)+ )+ rl'+ )+ (\rll rlk rla rlr _ _ -> R l k a $ B (insertR rll rlk rla rlr) rk ra rr)+ rl+ insertLlr ll lk la lr k a r =+ map'+ (B (B ll lk la E) k0 a0 $ B E k a r)+ (\lrl lrk lra lrr _ _ -> L (B ll lk la $ insertL lrl lrk lra lrr) k a r)+ ( \lrl lrk lra lrr _ _ ->+ let lr' = insertB lrl lrk lra lrr+ in map'+ (error "Map.insert: L9")+ ( \lrl' lrk' lra' lrr' _ _ ->+ B+ (B ll lk la lrl')+ lrk'+ lra'+ (R lrr' k a r)+ )+ (\_ _ _ _ _ _ -> L (B ll lk la lr') k a r)+ ( \lrl' lrk' lra' lrr' _ _ ->+ B+ (L ll lk la lrl')+ lrk'+ lra'+ (B lrr' k a r)+ )+ lr'+ )+ (\lrl lrk lra lrr _ _ -> L (B ll lk la $ insertR lrl lrk lra lrr) k a r)+ lr
+ src/Mini/Data/Recursion.hs view
@@ -0,0 +1,816 @@+{-# LANGUAGE LambdaCase #-}++-- | Primitive recursive functions on basic data structures+module Mini.Data.Recursion (+ -- * Re-exports+ bool,+ either,+ maybe,+ uncurry,++ -- * Lists+ list,+ nonEmpty,++ -- * Orderings+ ordering,++ -- * n-Tuples (3 to 64)+ uncurry3,+ uncurry4,+ uncurry5,+ uncurry6,+ uncurry7,+ uncurry8,+ uncurry9,+ uncurry10,+ uncurry11,+ uncurry12,+ uncurry13,+ uncurry14,+ uncurry15,+ uncurry16,+ uncurry17,+ uncurry18,+ uncurry19,+ uncurry20,+ uncurry21,+ uncurry22,+ uncurry23,+ uncurry24,+ uncurry25,+ uncurry26,+ uncurry27,+ uncurry28,+ uncurry29,+ uncurry30,+ uncurry31,+ uncurry32,+ uncurry33,+ uncurry34,+ uncurry35,+ uncurry36,+ uncurry37,+ uncurry38,+ uncurry39,+ uncurry40,+ uncurry41,+ uncurry42,+ uncurry43,+ uncurry44,+ uncurry45,+ uncurry46,+ uncurry47,+ uncurry48,+ uncurry49,+ uncurry50,+ uncurry51,+ uncurry52,+ uncurry53,+ uncurry54,+ uncurry55,+ uncurry56,+ uncurry57,+ uncurry58,+ uncurry59,+ uncurry60,+ uncurry61,+ uncurry62,+ uncurry63,+ uncurry64,+) where++import Data.Bool (+ Bool,+ )+import qualified Data.Bool as Bool (+ bool,+ )+import Data.Either (+ Either,+ )+import qualified Data.Either as Either (+ either,+ )+import Data.List.NonEmpty (+ NonEmpty (+ (:|)+ ),+ )+import Data.Maybe (+ Maybe,+ )+import qualified Data.Maybe as Maybe (+ maybe,+ )+import Data.Ord (+ Ordering (+ EQ,+ GT,+ LT+ ),+ )+import qualified Data.Tuple as Tuple (+ uncurry,+ )++-- Re-exports++-- | Primitive recursion on bools+bool+ :: a+ -- ^ Value yielded in case of 'Bool.False'+ -> a+ -- ^ Value yielded in case of 'Bool.True'+ -> Bool+ -- ^ Object of the case analysis+ -> a+bool = Bool.bool++-- | Primitive recursion on eithers+either+ :: (a -> c)+ -- ^ Function applied to @a@ in case of @'Either.Left' a@+ -> (b -> c)+ -- ^ Function applied to @b@ in case of @'Either.Right' b@+ -> Either a b+ -- ^ Object of the case analysis+ -> c+either = Either.either++-- | Primitive recursion on maybes+maybe+ :: b+ -- ^ Value yielded in case of 'Maybe.Nothing'+ -> (a -> b)+ -- ^ Function applied to @a@ in case of @'Maybe.Just' a@+ -> Maybe a+ -- ^ Object of the case analysis+ -> b+maybe = Maybe.maybe++-- | Primitive recursion on 2-tuples+uncurry+ :: (t1 -> t2 -> t3)+ -- ^ Function applied to the elements of the 2-tuple+ -> (t1, t2)+ -- ^ The 2-tuple+ -> t3+uncurry = Tuple.uncurry++-- Lists++-- | Primitive recursion on lists+list+ :: b+ -- ^ Value yielded in case of empty list+ -> (a -> [a] -> b -> b)+ -- ^ Function applied in case of non-empty list: head, tail, recursion+ -> [a]+ -- ^ Object of the case analysis+ -> b+list e f = \case+ a : as -> f a as (list e f as)+ [] -> e++-- | Primitive recursion on non-empty lists+nonEmpty+ :: (a -> [a] -> b)+ -- ^ Function applied to the head and tail of the non-empty list+ -> NonEmpty a+ -- ^ The non-empty list+ -> b+nonEmpty f (a :| as) = f a as++-- Orderings++-- | Primitive recursion on orderings+ordering+ :: a+ -- ^ Value yielded in case of 'LT'+ -> a+ -- ^ Value yielded in case of 'EQ'+ -> a+ -- ^ Value yielded in case of 'GT'+ -> Ordering+ -- ^ Object of the case analysis+ -> a+ordering lt eq gt = \case+ LT -> lt+ GT -> gt+ EQ -> eq++-- n-Tuples (3 to 64)++-- | Primitive recursion on 3-tuples+uncurry3+ :: (t1 -> t2 -> t3 -> t4)+ -- ^ Function applied to the elements of the 3-tuple+ -> (t1, t2, t3)+ -- ^ The 3-tuple+ -> t4+uncurry3 f (t1, t2, t3) = f t1 t2 t3++-- | Primitive recursion on 4-tuples+uncurry4+ :: (t1 -> t2 -> t3 -> t4 -> t5)+ -- ^ Function applied to the elements of the 4-tuple+ -> (t1, t2, t3, t4)+ -- ^ The 4-tuple+ -> t5+uncurry4 f (t1, t2, t3, t4) = f t1 t2 t3 t4++-- | Primitive recursion on 5-tuples+uncurry5+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6)+ -- ^ Function applied to the elements of the 5-tuple+ -> (t1, t2, t3, t4, t5)+ -- ^ The 5-tuple+ -> t6+uncurry5 f (t1, t2, t3, t4, t5) = f t1 t2 t3 t4 t5++-- | Primitive recursion on 6-tuples+uncurry6+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7)+ -- ^ Function applied to the elements of the 6-tuple+ -> (t1, t2, t3, t4, t5, t6)+ -- ^ The 6-tuple+ -> t7+uncurry6 f (t1, t2, t3, t4, t5, t6) = f t1 t2 t3 t4 t5 t6++-- | Primitive recursion on 7-tuples+uncurry7+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8)+ -- ^ Function applied to the elements of the 7-tuple+ -> (t1, t2, t3, t4, t5, t6, t7)+ -- ^ The 7-tuple+ -> t8+uncurry7 f (t1, t2, t3, t4, t5, t6, t7) = f t1 t2 t3 t4 t5 t6 t7++-- | Primitive recursion on 8-tuples+uncurry8+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9)+ -- ^ Function applied to the elements of the 8-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8)+ -- ^ The 8-tuple+ -> t9+uncurry8 f (t1, t2, t3, t4, t5, t6, t7, t8) = f t1 t2 t3 t4 t5 t6 t7 t8++-- | Primitive recursion on 9-tuples+uncurry9+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10)+ -- ^ Function applied to the elements of the 9-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9)+ -- ^ The 9-tuple+ -> t10+uncurry9 f (t1, t2, t3, t4, t5, t6, t7, t8, t9) = f t1 t2 t3 t4 t5 t6 t7 t8 t9++-- | Primitive recursion on 10-tuples+uncurry10+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11)+ -- ^ Function applied to the elements of the 10-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)+ -- ^ The 10-tuple+ -> t11+uncurry10 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10++-- | Primitive recursion on 11-tuples+uncurry11+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12)+ -- ^ Function applied to the elements of the 11-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11)+ -- ^ The 11-tuple+ -> t12+uncurry11 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11++-- | Primitive recursion on 12-tuples+uncurry12+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13)+ -- ^ Function applied to the elements of the 12-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12)+ -- ^ The 12-tuple+ -> t13+uncurry12 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12++-- | Primitive recursion on 13-tuples+uncurry13+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14)+ -- ^ Function applied to the elements of the 13-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13)+ -- ^ The 13-tuple+ -> t14+uncurry13 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13++-- | Primitive recursion on 14-tuples+uncurry14+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15)+ -- ^ Function applied to the elements of the 14-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14)+ -- ^ The 14-tuple+ -> t15+uncurry14 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14++-- | Primitive recursion on 15-tuples+uncurry15+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16)+ -- ^ Function applied to the elements of the 15-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15)+ -- ^ The 15-tuple+ -> t16+uncurry15 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15++-- | Primitive recursion on 16-tuples+uncurry16+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17)+ -- ^ Function applied to the elements of the 16-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16)+ -- ^ The 16-tuple+ -> t17+uncurry16 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16++-- | Primitive recursion on 17-tuples+uncurry17+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18)+ -- ^ Function applied to the elements of the 17-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17)+ -- ^ The 17-tuple+ -> t18+uncurry17 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17++-- | Primitive recursion on 18-tuples+uncurry18+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19)+ -- ^ Function applied to the elements of the 18-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18)+ -- ^ The 18-tuple+ -> t19+uncurry18 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18++-- | Primitive recursion on 19-tuples+uncurry19+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20)+ -- ^ Function applied to the elements of the 19-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19)+ -- ^ The 19-tuple+ -> t20+uncurry19 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19++-- | Primitive recursion on 20-tuples+uncurry20+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21)+ -- ^ Function applied to the elements of the 20-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20)+ -- ^ The 20-tuple+ -> t21+uncurry20 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20++-- | Primitive recursion on 21-tuples+uncurry21+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22)+ -- ^ Function applied to the elements of the 21-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21)+ -- ^ The 21-tuple+ -> t22+uncurry21 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21++-- | Primitive recursion on 22-tuples+uncurry22+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23)+ -- ^ Function applied to the elements of the 22-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22)+ -- ^ The 22-tuple+ -> t23+uncurry22 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22++-- | Primitive recursion on 23-tuples+uncurry23+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24)+ -- ^ Function applied to the elements of the 23-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23)+ -- ^ The 23-tuple+ -> t24+uncurry23 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23++-- | Primitive recursion on 24-tuples+uncurry24+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25)+ -- ^ Function applied to the elements of the 24-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24)+ -- ^ The 24-tuple+ -> t25+uncurry24 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24++-- | Primitive recursion on 25-tuples+uncurry25+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26)+ -- ^ Function applied to the elements of the 25-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25)+ -- ^ The 25-tuple+ -> t26+uncurry25 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25++-- | Primitive recursion on 26-tuples+uncurry26+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27)+ -- ^ Function applied to the elements of the 26-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26)+ -- ^ The 26-tuple+ -> t27+uncurry26 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26++-- | Primitive recursion on 27-tuples+uncurry27+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28)+ -- ^ Function applied to the elements of the 27-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27)+ -- ^ The 27-tuple+ -> t28+uncurry27 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27++-- | Primitive recursion on 28-tuples+uncurry28+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29)+ -- ^ Function applied to the elements of the 28-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28)+ -- ^ The 28-tuple+ -> t29+uncurry28 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28++-- | Primitive recursion on 29-tuples+uncurry29+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30)+ -- ^ Function applied to the elements of the 29-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29)+ -- ^ The 29-tuple+ -> t30+uncurry29 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29++-- | Primitive recursion on 30-tuples+uncurry30+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31)+ -- ^ Function applied to the elements of the 30-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30)+ -- ^ The 30-tuple+ -> t31+uncurry30 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30++-- | Primitive recursion on 31-tuples+uncurry31+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32)+ -- ^ Function applied to the elements of the 31-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31)+ -- ^ The 31-tuple+ -> t32+uncurry31 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31++-- | Primitive recursion on 32-tuples+uncurry32+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33)+ -- ^ Function applied to the elements of the 32-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32)+ -- ^ The 32-tuple+ -> t33+uncurry32 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32++-- | Primitive recursion on 33-tuples+uncurry33+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34)+ -- ^ Function applied to the elements of the 33-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33)+ -- ^ The 33-tuple+ -> t34+uncurry33 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33++-- | Primitive recursion on 34-tuples+uncurry34+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35)+ -- ^ Function applied to the elements of the 34-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34)+ -- ^ The 34-tuple+ -> t35+uncurry34 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34++-- | Primitive recursion on 35-tuples+uncurry35+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36)+ -- ^ Function applied to the elements of the 35-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35)+ -- ^ The 35-tuple+ -> t36+uncurry35 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35++-- | Primitive recursion on 36-tuples+uncurry36+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37)+ -- ^ Function applied to the elements of the 36-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36)+ -- ^ The 36-tuple+ -> t37+uncurry36 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36++-- | Primitive recursion on 37-tuples+uncurry37+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38)+ -- ^ Function applied to the elements of the 37-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37)+ -- ^ The 37-tuple+ -> t38+uncurry37 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37++-- | Primitive recursion on 38-tuples+uncurry38+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39)+ -- ^ Function applied to the elements of the 38-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38)+ -- ^ The 38-tuple+ -> t39+uncurry38 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38++-- | Primitive recursion on 39-tuples+uncurry39+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40)+ -- ^ Function applied to the elements of the 39-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39)+ -- ^ The 39-tuple+ -> t40+uncurry39 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39++-- | Primitive recursion on 40-tuples+uncurry40+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41)+ -- ^ Function applied to the elements of the 40-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40)+ -- ^ The 40-tuple+ -> t41+uncurry40 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40++-- | Primitive recursion on 41-tuples+uncurry41+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42)+ -- ^ Function applied to the elements of the 41-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41)+ -- ^ The 41-tuple+ -> t42+uncurry41 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41++-- | Primitive recursion on 42-tuples+uncurry42+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43)+ -- ^ Function applied to the elements of the 42-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42)+ -- ^ The 42-tuple+ -> t43+uncurry42 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42++-- | Primitive recursion on 43-tuples+uncurry43+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44)+ -- ^ Function applied to the elements of the 43-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43)+ -- ^ The 43-tuple+ -> t44+uncurry43 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43++-- | Primitive recursion on 44-tuples+uncurry44+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45)+ -- ^ Function applied to the elements of the 44-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44)+ -- ^ The 44-tuple+ -> t45+uncurry44 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44++-- | Primitive recursion on 45-tuples+uncurry45+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46)+ -- ^ Function applied to the elements of the 45-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45)+ -- ^ The 45-tuple+ -> t46+uncurry45 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45++-- | Primitive recursion on 46-tuples+uncurry46+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47)+ -- ^ Function applied to the elements of the 46-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46)+ -- ^ The 46-tuple+ -> t47+uncurry46 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46++-- | Primitive recursion on 47-tuples+uncurry47+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48)+ -- ^ Function applied to the elements of the 47-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47)+ -- ^ The 47-tuple+ -> t48+uncurry47 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47++-- | Primitive recursion on 48-tuples+uncurry48+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49)+ -- ^ Function applied to the elements of the 48-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48)+ -- ^ The 48-tuple+ -> t49+uncurry48 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48++-- | Primitive recursion on 49-tuples+uncurry49+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50)+ -- ^ Function applied to the elements of the 49-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49)+ -- ^ The 49-tuple+ -> t50+uncurry49 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49++-- | Primitive recursion on 50-tuples+uncurry50+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51)+ -- ^ Function applied to the elements of the 50-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50)+ -- ^ The 50-tuple+ -> t51+uncurry50 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50++-- | Primitive recursion on 51-tuples+uncurry51+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52)+ -- ^ Function applied to the elements of the 51-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51)+ -- ^ The 51-tuple+ -> t52+uncurry51 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51++-- | Primitive recursion on 52-tuples+uncurry52+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53)+ -- ^ Function applied to the elements of the 52-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52)+ -- ^ The 52-tuple+ -> t53+uncurry52 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52++-- | Primitive recursion on 53-tuples+uncurry53+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54)+ -- ^ Function applied to the elements of the 53-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53)+ -- ^ The 53-tuple+ -> t54+uncurry53 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53++-- | Primitive recursion on 54-tuples+uncurry54+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55)+ -- ^ Function applied to the elements of the 54-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54)+ -- ^ The 54-tuple+ -> t55+uncurry54 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54++-- | Primitive recursion on 55-tuples+uncurry55+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56)+ -- ^ Function applied to the elements of the 55-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55)+ -- ^ The 55-tuple+ -> t56+uncurry55 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55++-- | Primitive recursion on 56-tuples+uncurry56+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57)+ -- ^ Function applied to the elements of the 56-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56)+ -- ^ The 56-tuple+ -> t57+uncurry56 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56++-- | Primitive recursion on 57-tuples+uncurry57+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58)+ -- ^ Function applied to the elements of the 57-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57)+ -- ^ The 57-tuple+ -> t58+uncurry57 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57++-- | Primitive recursion on 58-tuples+uncurry58+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59)+ -- ^ Function applied to the elements of the 58-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58)+ -- ^ The 58-tuple+ -> t59+uncurry58 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58++-- | Primitive recursion on 59-tuples+uncurry59+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60)+ -- ^ Function applied to the elements of the 59-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59)+ -- ^ The 59-tuple+ -> t60+uncurry59 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59++-- | Primitive recursion on 60-tuples+uncurry60+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61)+ -- ^ Function applied to the elements of the 60-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60)+ -- ^ The 60-tuple+ -> t61+uncurry60 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60++-- | Primitive recursion on 61-tuples+uncurry61+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61 -> t62)+ -- ^ Function applied to the elements of the 61-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61)+ -- ^ The 61-tuple+ -> t62+uncurry61 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60 t61++-- | Primitive recursion on 62-tuples+uncurry62+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61 -> t62 -> t63)+ -- ^ Function applied to the elements of the 62-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62)+ -- ^ The 62-tuple+ -> t63+uncurry62 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60 t61 t62++-- | Primitive recursion on 63-tuples+uncurry63+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61 -> t62 -> t63 -> t64)+ -- ^ Function applied to the elements of the 63-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63)+ -- ^ The 63-tuple+ -> t64+uncurry63 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60 t61 t62 t63++-- | Primitive recursion on 64-tuples+uncurry64+ :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> t8 -> t9 -> t10 -> t11 -> t12 -> t13 -> t14 -> t15 -> t16 -> t17 -> t18 -> t19 -> t20 -> t21 -> t22 -> t23 -> t24 -> t25 -> t26 -> t27 -> t28 -> t29 -> t30 -> t31 -> t32 -> t33 -> t34 -> t35 -> t36 -> t37 -> t38 -> t39 -> t40 -> t41 -> t42 -> t43 -> t44 -> t45 -> t46 -> t47 -> t48 -> t49 -> t50 -> t51 -> t52 -> t53 -> t54 -> t55 -> t56 -> t57 -> t58 -> t59 -> t60 -> t61 -> t62 -> t63 -> t64 -> t65)+ -- ^ Function applied to the elements of the 64-tuple+ -> (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63, t64)+ -- ^ The 64-tuple+ -> t65+uncurry64 f (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63, t64) =+ f t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60 t61 t62 t63 t64
+ src/Mini/Data/Set.hs view
@@ -0,0 +1,1084 @@+{-# LANGUAGE LambdaCase #-}+-- incomplete patterns in 'from{Asc,Desc}List'+{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}++-- | A structure containing unique elements+module Mini.Data.Set (+ -- * Type+ Set,+ set,++ -- * Construction+ empty,+ fromAscList,+ fromDescList,+ fromDistinctAscList,+ fromDistinctDescList,+ fromList,+ singleton,++ -- * Combination+ difference,+ intersection,+ union,+ unions,++ -- * Conversion+ toAscList,+ toDescList,++ -- * Modification+ delete,+ deleteMax,+ deleteMin,+ filter,+ insert,++ -- * Partition+ partition,+ split,+ splitMax,+ splitMin,++ -- * Query+ disjoint,+ isSubsetOf,+ lookupGE,+ lookupGT,+ lookupLE,+ lookupLT,+ lookupMax,+ lookupMin,+ member,+ null,+ size,++ -- * Validation+ valid,+) where++import Control.Applicative (+ liftA2,+ (<|>),+ )+import Data.Bifunctor (+ bimap,+ first,+ second,+ )+import Data.Bool (+ bool,+ )+import Data.Function (+ on,+ )+import Mini.Data.Recursion (+ list,+ ordering,+ )+import Prelude (+ Bool (+ False,+ True+ ),+ Eq,+ Foldable,+ Int,+ Maybe (+ Just,+ Nothing+ ),+ Monoid,+ Ord,+ Semigroup,+ Show,+ all,+ any,+ compare,+ const,+ div,+ error,+ flip,+ foldl,+ foldr,+ length,+ max,+ maybe,+ mempty,+ not,+ show,+ splitAt,+ uncurry,+ until,+ ($),+ (&&),+ (*),+ (+),+ (-),+ (.),+ (<),+ (<$>),+ (<*>),+ (<>),+ (==),+ (>),+ )++-- Type++-- | A set containing elements of type /a/, internally structured as an AVL tree+data Set a+ = -- | Empty node+ E+ | -- | Left-heavy node+ L (Set a) a (Set a)+ | -- | Balanced node+ B (Set a) a (Set a)+ | -- | Right-heavy node+ R (Set a) a (Set a)++instance (Eq a) => Eq (Set a) where+ (==) = (==) `on` toAscList++instance (Ord a) => Ord (Set a) where+ compare = compare `on` toAscList++instance (Show a) => Show (Set a) where+ show = show . toAscList++instance Foldable Set where+ foldr f b = set' b go go go+ where+ go l a _ _ recr = foldr f (f a recr) l++instance (Ord a) => Semigroup (Set a) where+ (<>) = union++instance (Ord a) => Monoid (Set a) where+ mempty = empty++-- | Primitive recursion on sets (internally structured as trees)+set+ :: b+ -- ^ Value yielded in case of empty node+ -> (Set a -> a -> Set a -> b -> b -> b)+ -- ^ Function applied in case of non-empty node:+ -- left child, element, right child, left recursion, right recursion+ -- (elements are lesser to the left, greater to the right)+ -> Set a+ -- ^ Object of the case analysis+ -> b+set e f = set' e f f f++-- Primitive recursion on sets+set'+ :: b+ -- ^ Value yielded in case of empty node+ -> (Set a -> a -> Set a -> b -> b -> b)+ -- ^ Function applied in case of left-heavy node:+ -- left child, element, right child, left recursion, right recursion+ -- (elements are lesser to the left, greater to the right)+ -> (Set a -> a -> Set a -> b -> b -> b)+ -- ^ Function applied in case of balanced node:+ -- left child, element, right child, left recursion, right recursion+ -- (elements are lesser to the left, greater to the right)+ -> (Set a -> a -> Set a -> b -> b -> b)+ -- ^ Function applied in case of right-heavy node:+ -- left child, element, right child, left recursion, right recursion+ -- (elements are lesser to the left, greater to the right)+ -> Set a+ -- ^ Object of the case analysis+ -> b+set' e f g h = \case+ L l a r -> f l a r (set' e f g h l) (set' e f g h r)+ R l a r -> h l a r (set' e f g h l) (set' e f g h r)+ B l a r -> g l a r (set' e f g h l) (set' e f g h r)+ E -> e++-- Construction++-- | /O(1)/ The empty set+empty :: Set a+empty = E++-- | /O(n)/ Make a set from a sorted list of elements+fromAscList :: (Eq a) => [a] -> Set a+fromAscList = fromDistinctAscList . essence++-- | /O(n)/ Make a set from a sorted list of elements+fromDescList :: (Eq a) => [a] -> Set a+fromDescList = fromDistinctDescList . essence++-- | /O(n)/ Make a set from a sorted list of distinct elements+fromDistinctAscList :: [a] -> Set a+fromDistinctAscList = go <*> power+ where+ go as n = list E go' as+ where+ go' a = const . list (B E a E) go''+ where+ go'' _ _ _ =+ let len = length as+ n' = n `div` 2+ c = bool B L $ len == n+ (l, a' : r) = splitAt (len `div` 2) as+ in c (go l n') a' (go r n')++-- | /O(n)/ Make a set from a sorted list of distinct elements+fromDistinctDescList :: [a] -> Set a+fromDistinctDescList = go <*> power+ where+ go as n = list E go' as+ where+ go' a = const . list (B E a E) go''+ where+ go'' _ _ _ =+ let len = length as+ n' = n `div` 2+ c = bool B R $ len == n+ (l, a' : r) = splitAt (len `div` 2) as+ in c (go r n') a' (go l n')++-- | /O(n log n)/ Make a set from a list of elements+fromList :: (Ord a) => [a] -> Set a+fromList = foldl (flip insert) empty++-- | /O(1)/ Make a set with a single element+singleton :: a -> Set a+singleton a = B E a E++-- Combination++-- | /O(m log n)/ Subtract a set by another+difference :: (Ord a) => Set a -> Set a -> Set a+difference t1 t2 = set' empty go go go t1+ where+ go _ _ _ _ _ = foldr delete t1 t2++-- | /O(m log n)/ Intersect a set with another+intersection :: (Ord a) => Set a -> Set a -> Set a+intersection t1 t2 = set' empty go go go t2+ where+ go _ _ _ _ _ =+ fromDistinctAscList $+ foldr+ (\a b -> bool b (a : b) $ a `member` t2)+ []+ t1++-- | /O(m log n)/ Unite a set with another+union :: (Ord a) => Set a -> Set a -> Set a+union t1 t2 = set' t2 go go go t1+ where+ go _ _ _ _ _ = foldr insert t1 t2++-- | Unite a collection of sets+unions :: (Foldable t, Ord a) => t (Set a) -> Set a+unions = foldr union empty++-- Conversion++-- | /O(n)/ Turn a set into a list of elements in ascending order+toAscList :: Set a -> [a]+toAscList = foldr (:) []++-- | /O(n)/ Turn a set into a list of elements in descending order+toDescList :: Set a -> [a]+toDescList = foldl (flip (:)) []++-- Modification++-- | /O(log n)/ Delete an element from a set+delete :: (Ord a) => a -> Set a -> Set a+delete a t = bool t (delete' a t) $ a `member` t++-- | /O(log n)/ Delete the maximum element from a set+deleteMax :: (Ord a) => Set a -> Set a+deleteMax t = maybe t (`delete'` t) $ lookupMax t++-- | /O(log n)/ Delete the minimum element from a set+deleteMin :: (Ord a) => Set a -> Set a+deleteMin t = maybe t (`delete'` t) $ lookupMin t++-- | /O(n)/ Keep the elements satisfying a predicate+filter :: (a -> Bool) -> Set a -> Set a+filter p = fromDistinctAscList . foldr (\a b -> bool b (a : b) $ p a) []++-- | /O(log n)/ Insert an element into a set+insert :: (Ord a) => a -> Set a -> Set a+insert a t = bool (insert' a t) t $ a `member` t++-- Partition++-- | /O(n)/ Partition a set with a predicate into @(true, false)@ subsets+partition :: (a -> Bool) -> Set a -> (Set a, Set a)+partition p =+ bimap fromDistinctAscList fromDistinctAscList+ . foldr+ (\a -> bool second first (p a) (a :))+ ([], [])++-- | /O(n)/ Split a set by an element into @(lt, eq, gt)@ subsets+split :: (Ord a) => a -> Set a -> (Set a, Bool, Set a)+split a0 =+ (\(lt, a, gt) -> (fromDistinctAscList lt, a, fromDistinctAscList gt))+ . foldr+ ( \a (lt, a', gt) ->+ ordering+ (a : lt, a', gt)+ (lt, True, gt)+ (lt, a', a : gt)+ $ compare a a0+ )+ ([], False, [])++-- | /O(log n)/ Split a set by its maximum element+splitMax :: (Ord a) => Set a -> Maybe (a, Set a)+splitMax t = ((,) <*> flip delete' t) <$> lookupMax t++-- | /O(log n)/ Split a set by its minimum element+splitMin :: (Ord a) => Set a -> Maybe (a, Set a)+splitMin t = ((,) <*> flip delete' t) <$> lookupMin t++-- Query++-- | /O(m log n)/ Check whether two sets have no elements in common+disjoint :: (Ord a) => Set a -> Set a -> Bool+disjoint t1 t2 = set' True go go go t1+ where+ go _ _ _ _ _ = not $ any (`member` t1) t2++-- | /O(n log m)/ Check whether the elements of a set exist in the other+isSubsetOf :: (Ord a) => Set a -> Set a -> Bool+isSubsetOf t1 t2 = set' (null t1) go go go t2+ where+ go _ _ _ _ _ = all (`member` t2) t1++-- | /O(log n)/ Fetch the least element greater than or equal to the given one+lookupGE :: (Ord a) => a -> Set a -> Maybe a+lookupGE a0 = set' Nothing go go go+ where+ go _ a _ recl recr =+ ordering+ recr+ (Just a)+ (recl <|> Just a)+ $ compare a a0++-- | /O(log n)/ Fetch the least element strictly greater than the given one+lookupGT :: (Ord a) => a -> Set a -> Maybe a+lookupGT a0 = set' Nothing go go go+ where+ go _ a _ recl recr =+ ordering+ recr+ recr+ (recl <|> Just a)+ $ compare a a0++-- | /O(log n)/ Fetch the greatest element less than or equal to the given one+lookupLE :: (Ord a) => a -> Set a -> Maybe a+lookupLE a0 = set' Nothing go go go+ where+ go _ a _ recl recr =+ ordering+ (recr <|> Just a)+ (Just a)+ recl+ $ compare a a0++-- | /O(log n)/ Fetch the greatest element strictly less than the given one+lookupLT :: (Ord a) => a -> Set a -> Maybe a+lookupLT a0 = set' Nothing go go go+ where+ go _ a _ recl recr =+ ordering+ (recr <|> Just a)+ recl+ recl+ $ compare a a0++-- | /O(log n)/ Fetch the maximum element+lookupMax :: Set a -> Maybe a+lookupMax = set' Nothing go go go+ where+ go _ a r _ recr = set' (Just a) go' go' go' r+ where+ go' _ _ _ _ _ = recr++-- | /O(log n)/ Fetch the minimum element+lookupMin :: Set a -> Maybe a+lookupMin = set' Nothing go go go+ where+ go l a _ recl _ = set' (Just a) go' go' go' l+ where+ go' _ _ _ _ _ = recl++-- | /O(log n)/ Check whether an element is in a set+member :: (Ord a) => a -> Set a -> Bool+member a0 = set' False go go go+ where+ go _ a _ recl recr =+ ordering+ recl+ True+ recr+ $ compare a0 a++-- | /O(1)/ Check whether a set is empty+null :: Set a -> Bool+null = set' True go go go where go _ _ _ _ _ = False++-- | /O(n)/ Get the size of a set+size :: Set a -> Int+size = set' 0 go go go where go _ _ _ recl recr = 1 + recl + recr++-- Validation++-- | /O(n^2)/ Check whether a set is internally height-balanced and ordered+valid :: (Ord a) => Set a -> Bool+valid = liftA2 (&&) balanced ordered+ where+ balanced =+ set'+ True+ (\l _ r recl recr -> levels l - levels r == 1 && recl && recr)+ (\l _ r recl recr -> levels l - levels r == 0 && recl && recr)+ (\l _ r recl recr -> levels r - levels l == 1 && recl && recr)+ levels = set' 0 go go go+ where+ go _ _ _ recl recr = 1 + max recl recr :: Int+ ordered = set' True go go go+ where+ go l a r recl recr =+ set' True lt lt lt l+ && set' True gt gt gt r+ where+ lt _ la _ _ _ = la < a && recl && recr+ gt _ ra _ _ _ = ra > a && recl && recr++-- Helpers++-- O(n) 'nub' for sorted lists+essence :: (Eq a) => [a] -> [a]+essence = list [] go+ where+ go a1 as rec = list [a1] go' as+ where+ go' a2 _ _ = bool (a1 : rec) rec $ a1 == a2++-- The greatest power of 2 <= the length of a non-empty collection+power :: (Foldable t) => t a -> Int+power as = until (> length as) (* 2) 2 `div` 2++{-+ - Let this comment serve as your warning. Return from whence you came and your+ - sanity will be spared. You have been admonished.+ -}++-- O(log n) Delete an element from a set without checking for membership+delete' :: (Ord a) => a -> Set a -> Set a+delete' a0 =+ set'+ (error "Set.delete: L0")+ ( \l a r _ _ ->+ ordering+ (deleteLl l a r)+ (substituteL l r)+ (deleteLr l a r)+ $ compare a0 a+ )+ ( \l a r _ _ ->+ ordering+ (deleteBl l a r)+ (substituteBr l r)+ (deleteBr l a r)+ $ compare a0 a+ )+ ( \l a r _ _ ->+ ordering+ (deleteRl l a r)+ (substituteR l r)+ (deleteRr l a r)+ $ compare a0 a+ )+ where+ deleteRl l a r =+ set'+ (error "Set.delete: L1")+ ( \ll la lr _ _ ->+ ordering+ (checkLeftR (deleteLl ll la lr) a r)+ (checkLeftR (substituteL ll lr) a r)+ (checkLeftR (deleteLr ll la lr) a r)+ $ compare a0 la+ )+ ( \ll la lr _ _ ->+ ordering+ (R (deleteBl ll la lr) a r)+ (checkLeftR' (substituteBr ll lr) a r)+ (R (deleteBr ll la lr) a r)+ $ compare a0 la+ )+ ( \ll la lr _ _ ->+ ordering+ (checkLeftR (deleteRl ll la lr) a r)+ (checkLeftR (substituteR ll lr) a r)+ (checkLeftR (deleteRr ll la lr) a r)+ $ compare a0 la+ )+ l+ deleteRr l a =+ set'+ (error "Set.delete: L2")+ ( \rl ra rr _ _ ->+ ordering+ (checkRightR l a $ deleteLl rl ra rr)+ (checkRightR l a $ substituteL rl rr)+ (checkRightR l a $ deleteLr rl ra rr)+ $ compare a0 ra+ )+ ( \rl ra rr _ _ ->+ ordering+ (R l a $ deleteBl rl ra rr)+ (checkRightR' l a $ substituteBl rl rr)+ (R l a $ deleteBr rl ra rr)+ $ compare a0 ra+ )+ ( \rl ra rr _ _ ->+ ordering+ (checkRightR l a $ deleteRl rl ra rr)+ (checkRightR l a $ substituteR rl rr)+ (checkRightR l a $ deleteRr rl ra rr)+ $ compare a0 ra+ )+ deleteBl l a r =+ set'+ (error "Set.delete: L3")+ ( \ll la lr _ _ ->+ ordering+ (checkLeftB (deleteLl ll la lr) a r)+ (checkLeftB (substituteL ll lr) a r)+ (checkLeftB (deleteLr ll la lr) a r)+ $ compare a0 la+ )+ ( \ll la lr _ _ ->+ ordering+ (B (deleteBl ll la lr) a r)+ (checkLeftB' (substituteBr ll lr) a r)+ (B (deleteBr ll la lr) a r)+ $ compare a0 la+ )+ ( \ll la lr _ _ ->+ ordering+ (checkLeftB (deleteRl ll la lr) a r)+ (checkLeftB (substituteR ll lr) a r)+ (checkLeftB (deleteRr ll la lr) a r)+ $ compare a0 la+ )+ l+ deleteBr l a =+ set'+ (error "Set.delete: L4")+ ( \rl ra rr _ _ ->+ ordering+ (checkRightB l a $ deleteLl rl ra rr)+ (checkRightB l a $ substituteL rl rr)+ (checkRightB l a $ deleteLr rl ra rr)+ $ compare a0 ra+ )+ ( \rl ra rr _ _ ->+ ordering+ (B l a $ deleteBl rl ra rr)+ (checkRightB' l a $ substituteBl rl rr)+ (B l a $ deleteBr rl ra rr)+ $ compare a0 ra+ )+ ( \rl ra rr _ _ ->+ ordering+ (checkRightB l a $ deleteRl rl ra rr)+ (checkRightB l a $ substituteR rl rr)+ (checkRightB l a $ deleteRr rl ra rr)+ $ compare a0 ra+ )+ deleteLl l a r =+ set'+ (error "Set.delete: L5")+ ( \ll la lr _ _ ->+ ordering+ (checkLeftL (deleteLl ll la lr) a r)+ (checkLeftL (substituteL ll lr) a r)+ (checkLeftL (deleteLr ll la lr) a r)+ $ compare a0 la+ )+ ( \ll la lr _ _ ->+ ordering+ (L (deleteBl ll la lr) a r)+ (checkLeftL' (substituteBr ll lr) a r)+ (L (deleteBr ll la lr) a r)+ $ compare a0 la+ )+ ( \ll la lr _ _ ->+ ordering+ (checkLeftL (deleteRl ll la lr) a r)+ (checkLeftL (substituteR ll lr) a r)+ (checkLeftL (deleteRr ll la lr) a r)+ $ compare a0 la+ )+ l+ deleteLr l a =+ set'+ (error "Set.delete: L6")+ ( \rl ra rr _ _ ->+ ordering+ (checkRightL l a $ deleteLl rl ra rr)+ (checkRightL l a $ substituteL rl rr)+ (checkRightL l a $ deleteLr rl ra rr)+ $ compare a0 ra+ )+ ( \rl ra rr _ _ ->+ ordering+ (L l a $ deleteBl rl ra rr)+ (checkRightL' l a $ substituteBl rl rr)+ (L l a $ deleteBr rl ra rr)+ $ compare a0 ra+ )+ ( \rl ra rr _ _ ->+ ordering+ (checkRightL l a $ deleteRl rl ra rr)+ (checkRightL l a $ substituteR rl rr)+ (checkRightL l a $ deleteRr rl ra rr)+ $ compare a0 ra+ )+ rebalanceR l a =+ set'+ (error "Set.delete: L7")+ ( \rl ra rr _ _ ->+ set'+ (error "Set.delete: L8")+ (\rll rla rlr _ _ -> B (B l a rll) rla $ R rlr ra rr)+ (\rll rla rlr _ _ -> B (B l a rll) rla $ B rlr ra rr)+ (\rll rla rlr _ _ -> B (L l a rll) rla $ B rlr ra rr)+ rl+ )+ (\rl ra rr _ _ -> L (R l a rl) ra rr)+ (\rl ra rr _ _ -> B (B l a rl) ra rr)+ rebalanceL l a r =+ set'+ (error "Set.delete: L9")+ (\ll la lr _ _ -> B ll la $ B lr a r)+ (\ll la lr _ _ -> R ll la $ L lr a r)+ ( \ll la lr _ _ ->+ set'+ (error "Set.delete: L10")+ (\lrl lra lrr _ _ -> B (B ll la lrl) lra $ R lrr a r)+ (\lrl lra lrr _ _ -> B (B ll la lrl) lra $ B lrr a r)+ (\lrl lra lrr _ _ -> B (L ll la lrl) lra $ B lrr a r)+ lr+ )+ l+ checkLeftR l a r =+ set'+ (error "Set.delete: L11")+ (\_ _ _ _ _ -> R l a r)+ (\_ _ _ _ _ -> rebalanceR l a r)+ (\_ _ _ _ _ -> R l a r)+ l+ checkLeftB l a r =+ set'+ (error "Set.delete: L12")+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> R l a r)+ (\_ _ _ _ _ -> B l a r)+ l+ checkLeftL l a r =+ set'+ (error "Set.delete: L13")+ (\_ _ _ _ _ -> L l a r)+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> L l a r)+ l+ checkRightR l a r =+ set'+ (error "Set.delete: L14")+ (\_ _ _ _ _ -> R l a r)+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> R l a r)+ r+ checkRightB l a r =+ set'+ (error "Set.delete: L15")+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> L l a r)+ (\_ _ _ _ _ -> B l a r)+ r+ checkRightL l a r =+ set'+ (error "Set.delete: L16")+ (\_ _ _ _ _ -> L l a r)+ (\_ _ _ _ _ -> rebalanceL l a r)+ (\_ _ _ _ _ -> L l a r)+ r+ substituteR l =+ set'+ (error "Set.delete: L17")+ (\rl ra rr _ _ -> uncurry (checkRightR l) $ popLeftL rl ra rr)+ (\rl ra rr _ _ -> uncurry (checkRightR' l) $ popLeftB rl ra rr)+ (\rl ra rr _ _ -> uncurry (checkRightR l) $ popLeftR rl ra rr)+ substituteBr l =+ set'+ E+ (\rl ra rr _ _ -> uncurry (checkRightB l) $ popLeftL rl ra rr)+ (\rl ra rr _ _ -> uncurry (checkRightB' l) $ popLeftB rl ra rr)+ (\rl ra rr _ _ -> uncurry (checkRightB l) $ popLeftR rl ra rr)+ substituteBl l r =+ set'+ E+ (\ll la lr _ _ -> (\(l', a) -> checkLeftB l' a r) $ popRightL ll la lr)+ (\ll la lr _ _ -> (\(l', a) -> checkLeftB' l' a r) $ popRightB ll la lr)+ (\ll la lr _ _ -> (\(l', a) -> checkLeftB l' a r) $ popRightR ll la lr)+ l+ substituteL l r =+ set'+ (error "Set.delete: L18")+ (\ll la lr _ _ -> (\(l', a) -> checkLeftL l' a r) $ popRightL ll la lr)+ (\ll la lr _ _ -> (\(l', a) -> checkLeftL' l' a r) $ popRightB ll la lr)+ (\ll la lr _ _ -> (\(l', a) -> checkLeftL l' a r) $ popRightR ll la lr)+ l+ checkLeftR' l a r =+ set'+ (rebalanceR l a r)+ (\_ _ _ _ _ -> R l a r)+ (\_ _ _ _ _ -> R l a r)+ (\_ _ _ _ _ -> R l a r)+ l+ checkLeftB' l a r =+ set'+ (R l a r)+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> B l a r)+ l+ checkLeftL' l a r =+ set'+ (B l a r)+ (\_ _ _ _ _ -> L l a r)+ (\_ _ _ _ _ -> L l a r)+ (\_ _ _ _ _ -> L l a r)+ l+ checkRightR' l a r =+ set'+ (B l a r)+ (\_ _ _ _ _ -> R l a r)+ (\_ _ _ _ _ -> R l a r)+ (\_ _ _ _ _ -> R l a r)+ r+ checkRightB' l a r =+ set'+ (L l a r)+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> B l a r)+ r+ checkRightL' l a r =+ set'+ (rebalanceL l a r)+ (\_ _ _ _ _ -> L l a r)+ (\_ _ _ _ _ -> L l a r)+ (\_ _ _ _ _ -> L l a r)+ r+ popLeftR l a r =+ set'+ (a, r)+ ( \ll la lr _ _ ->+ (\(a', l') -> (a', checkLeftR l' a r)) $+ popLeftL ll la lr+ )+ (\ll la lr _ _ -> popLeftRB ll la lr a r)+ ( \ll la lr _ _ ->+ (\(a', l') -> (a', checkLeftR l' a r)) $+ popLeftR ll la lr+ )+ l+ popLeftB l a r =+ set'+ (a, E)+ (\ll la lr _ _ -> popLeftBL ll la lr a r)+ (\ll la lr _ _ -> popLeftBB ll la lr a r)+ (\ll la lr _ _ -> popLeftBR ll la lr a r)+ l+ popLeftL l a r =+ set'+ (error "Set.delete: L19")+ ( \ll la lr _ _ ->+ (\(a', l') -> (a', checkLeftL l' a r)) $+ popLeftL ll la lr+ )+ (\ll la lr _ _ -> popLeftLB ll la lr a r)+ ( \ll la lr _ _ ->+ (\(a', l') -> (a', checkLeftL l' a r)) $+ popLeftR ll la lr+ )+ l+ popLeftRB ll la lr a r =+ set'+ (la, rebalanceR E a r)+ ( \lll lla llr _ _ ->+ (\(a', l) -> (a', R l a r)) $+ popLeftBL lll lla llr la lr+ )+ ( \lll lla llr _ _ ->+ (\(a', l) -> (a', R l a r)) $+ popLeftBB lll lla llr la lr+ )+ ( \lll lla llr _ _ ->+ (\(a', l) -> (a', R l a r)) $+ popLeftBR lll lla llr la lr+ )+ ll+ popLeftBB ll la lr a r =+ set'+ (la, R E a r)+ ( \lll lla llr _ _ ->+ (\(a', l) -> (a', B l a r)) $+ popLeftBL lll lla llr la lr+ )+ ( \lll lla llr _ _ ->+ (\(a', l) -> (a', B l a r)) $+ popLeftBB lll lla llr la lr+ )+ ( \lll lla llr _ _ ->+ (\(a', l) -> (a', B l a r)) $+ popLeftBR lll lla llr la lr+ )+ ll+ popLeftLB ll la lr a r =+ set'+ (la, B E a E)+ ( \lll lla llr _ _ ->+ (\(a', l) -> (a', L l a r)) $+ popLeftBL lll lla llr la lr+ )+ ( \lll lla llr _ _ ->+ (\(a', l) -> (a', L l a r)) $+ popLeftBB lll lla llr la lr+ )+ ( \lll lla llr _ _ ->+ (\(a', l) -> (a', L l a r)) $+ popLeftBR lll lla llr la lr+ )+ ll+ popLeftBR ll la lr a r =+ (\(a', l) -> (a', checkLeftB l a r)) $+ popLeftR ll la lr+ popLeftBL ll la lr a r =+ (\(a', l) -> (a', checkLeftB l a r)) $+ popLeftL ll la lr+ popRightR l a =+ set'+ (error "Set.delete: L20")+ (\rl ra rr _ _ -> first (checkRightR l a) $ popRightL rl ra rr)+ (\rl ra rr _ _ -> popRightRB l a rl ra rr)+ (\rl ra rr _ _ -> first (checkRightR l a) $ popRightR rl ra rr)+ popRightB l a =+ set'+ (E, a)+ (\rl ra rr _ _ -> popRightBL l a rl ra rr)+ (\rl ra rr _ _ -> popRightBB l a rl ra rr)+ (\rl ra rr _ _ -> popRightBR l a rl ra rr)+ popRightL l a =+ set'+ (l, a)+ (\rl ra rr _ _ -> first (checkRightL l a) $ popRightL rl ra rr)+ (\rl ra rr _ _ -> popRightLB l a rl ra rr)+ (\rl ra rr _ _ -> first (checkRightL l a) $ popRightR rl ra rr)+ popRightRB l a rl ra =+ set'+ (B E a E, ra)+ (\rrl rra rrr _ _ -> first (R l a) $ popRightBL rl ra rrl rra rrr)+ (\rrl rra rrr _ _ -> first (R l a) $ popRightBB rl ra rrl rra rrr)+ (\rrl rra rrr _ _ -> first (R l a) $ popRightBR rl ra rrl rra rrr)+ popRightBB l a rl ra =+ set'+ (L l a E, ra)+ (\rrl rra rrr _ _ -> first (B l a) $ popRightBL rl ra rrl rra rrr)+ (\rrl rra rrr _ _ -> first (B l a) $ popRightBB rl ra rrl rra rrr)+ (\rrl rra rrr _ _ -> first (B l a) $ popRightBR rl ra rrl rra rrr)+ popRightLB l a rl ra =+ set'+ (rebalanceL l a E, ra)+ (\rrl rra rrr _ _ -> first (L l a) $ popRightBL rl ra rrl rra rrr)+ (\rrl rra rrr _ _ -> first (L l a) $ popRightBB rl ra rrl rra rrr)+ (\rrl rra rrr _ _ -> first (L l a) $ popRightBR rl ra rrl rra rrr)+ popRightBR l a rl ra rr = first (checkRightB l a) $ popRightR rl ra rr+ popRightBL l a rl ra rr = first (checkRightB l a) $ popRightL rl ra rr++-- O(log n) Insert an element into a set without checking for membership+insert' :: (Ord a) => a -> Set a -> Set a+insert' a0 =+ set'+ (B E a0 E)+ (\l a r _ _ -> insertL l a r)+ (\l a r _ _ -> insertB l a r)+ (\l a r _ _ -> insertR l a r)+ where+ insertR l a r =+ ordering+ (insertRl l a r)+ (R l a0 r)+ (insertRr l a r)+ $ compare a0 a+ insertB l a r =+ ordering+ (insertBl l a r)+ (B l a0 r)+ (insertBr l a r)+ $ compare a0 a+ insertL l a r =+ ordering+ (insertLl l a r)+ (L l a0 r)+ (insertLr l a r)+ $ compare a0 a+ insertRl l a r =+ set'+ (B (B E a0 E) a r)+ (\ll la lr _ _ -> R (insertL ll la lr) a r)+ ( \ll la lr _ _ ->+ let l' = insertB ll la lr+ in set'+ (error "Set.insert: L0")+ (\_ _ _ _ _ -> B l' a r)+ (\_ _ _ _ _ -> R l' a r)+ (\_ _ _ _ _ -> B l' a r)+ l'+ )+ (\ll la lr _ _ -> R (insertR ll la lr) a r)+ l+ insertBl l a r =+ set'+ (L (B E a0 E) a r)+ (\ll la lr _ _ -> B (insertL ll la lr) a r)+ ( \ll la lr _ _ ->+ let l' = insertB ll la lr+ in set'+ (error "Set.insert: L1")+ (\_ _ _ _ _ -> L l' a r)+ (\_ _ _ _ _ -> B l' a r)+ (\_ _ _ _ _ -> L l' a r)+ l'+ )+ (\ll la lr _ _ -> B (insertR ll la lr) a r)+ l+ insertBr l a =+ set'+ (R l a $ B E a0 E)+ (\rl ra rr _ _ -> B l a $ insertL rl ra rr)+ ( \rl ra rr _ _ ->+ let r = insertB rl ra rr+ in set'+ (error "Set.insert: L2")+ (\_ _ _ _ _ -> R l a r)+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> R l a r)+ r+ )+ (\rl ra rr _ _ -> B l a $ insertR rl ra rr)+ insertLr l a =+ set'+ (B l a $ B E a0 E)+ (\rl ra rr _ _ -> L l a $ insertL rl ra rr)+ ( \rl ra rr _ _ ->+ let r = insertB rl ra rr+ in set'+ (error "Set.insert: L3")+ (\_ _ _ _ _ -> B l a r)+ (\_ _ _ _ _ -> L l a r)+ (\_ _ _ _ _ -> B l a r)+ r+ )+ (\rl ra rr _ _ -> L l a $ insertR rl ra rr)+ insertRr l a =+ set'+ (error "Set.insert: L4")+ (\rl ra rr _ _ -> R l a $ insertL rl ra rr)+ ( \rl ra rr _ _ ->+ ordering+ (insertRrl l a rl ra rr)+ (R l a $ B rl a0 rr)+ (insertRrr l a rl ra rr)+ $ compare a0 ra+ )+ (\rl ra rr _ _ -> R l a $ insertR rl ra rr)+ insertLl l a r =+ set'+ (error "Set.insert: L5")+ (\ll la lr _ _ -> L (insertL ll la lr) a r)+ ( \ll la lr _ _ ->+ ordering+ (insertLll ll la lr a r)+ (L (B ll a0 lr) a r)+ (insertLlr ll la lr a r)+ $ compare a0 la+ )+ (\ll la lr _ _ -> L (insertR ll la lr) a r)+ l+ insertRrr l a rl ra =+ set'+ (B (B l a rl) ra $ B E a0 E)+ (\rrl rra rrr _ _ -> R l a . B rl ra $ insertL rrl rra rrr)+ ( \rrl rra rrr _ _ ->+ let rr = insertB rrl rra rrr+ in set'+ (error "Set.insert: L6")+ (\_ _ _ _ _ -> B (B l a rl) ra rr)+ (\_ _ _ _ _ -> R l a $ B rl ra rr)+ (\_ _ _ _ _ -> B (B l a rl) ra rr)+ rr+ )+ (\rrl rra rrr _ _ -> R l a . B rl ra $ insertR rrl rra rrr)+ insertLll ll la lr a r =+ set'+ (B (B E a0 E) la $ B lr a r)+ (\lll lla llr _ _ -> L (B (insertL lll lla llr) la lr) a r)+ ( \lll lla llr _ _ ->+ let ll' = insertB lll lla llr+ in set'+ (error "Set.insert: L7")+ (\_ _ _ _ _ -> B ll' la $ B lr a r)+ (\_ _ _ _ _ -> L (B ll' la lr) a r)+ (\_ _ _ _ _ -> B ll' la $ B lr a r)+ ll'+ )+ (\lll lla llr _ _ -> L (B (insertR lll lla llr) la lr) a r)+ ll+ insertRrl l a rl ra rr =+ set'+ (B (B l a E) a0 $ B E ra rr)+ (\rll rla rlr _ _ -> R l a $ B (insertL rll rla rlr) ra rr)+ ( \rll rla rlr _ _ ->+ let rl' = insertB rll rla rlr+ in set'+ (error "Set.insert: L8")+ (\rll' rla' rlr' _ _ -> B (B l a rll') rla' $ R rlr' ra rr)+ (\_ _ _ _ _ -> R l a $ B rl' ra rr)+ (\rll' rla' rlr' _ _ -> B (L l a rll') rla' $ B rlr' ra rr)+ rl'+ )+ (\rll rla rlr _ _ -> R l a $ B (insertR rll rla rlr) ra rr)+ rl+ insertLlr ll la lr a r =+ set'+ (B (B ll la E) a0 $ B E a r)+ (\lrl lra lrr _ _ -> L (B ll la $ insertL lrl lra lrr) a r)+ ( \lrl lra lrr _ _ ->+ let lr' = insertB lrl lra lrr+ in set'+ (error "Set.insert: L9")+ (\lrl' lra' lrr' _ _ -> B (B ll la lrl') lra' $ R lrr' a r)+ (\_ _ _ _ _ -> L (B ll la lr') a r)+ (\lrl' lra' lrr' _ _ -> B (L ll la lrl') lra' $ B lrr' a r)+ lr'+ )+ (\lrl lra lrr _ _ -> L (B ll la $ insertR lrl lra lrr) a r)+ lr
+ src/Mini/Hash/Class.hs view
@@ -0,0 +1,100 @@+-- | The class of hashable types+module Mini.Hash.Class (+ -- * Class+ Hashable (+ toBytes+ ),+) where++import Data.Bits (+ FiniteBits,+ finiteBitSize,+ shiftR,+ )+import Data.Int (+ Int,+ Int16,+ Int32,+ Int64,+ Int8,+ )+import Data.Word (+ Word,+ Word16,+ Word32,+ Word64,+ Word8,+ )+import Prelude (+ Bool,+ Char,+ Enum,+ Integral,+ concatMap,+ div,+ fmap,+ fromEnum,+ fromIntegral,+ iterate,+ pure,+ take,+ ($),+ (.),+ )++-- Class++-- | Instances should use little-endian byte order+class Hashable a where+ -- | Convert a hashable type to a sequence of bytes+ toBytes :: a -> [Word8]++instance Hashable Bool where+ toBytes = enumToBytes++instance Hashable Char where+ toBytes = enumToBytes++instance Hashable Int where+ toBytes = finiteBitsIntegralToBytes++instance Hashable Int8 where+ toBytes = finiteBitsIntegralToBytes++instance Hashable Int16 where+ toBytes = finiteBitsIntegralToBytes++instance Hashable Int32 where+ toBytes = finiteBitsIntegralToBytes++instance Hashable Int64 where+ toBytes = finiteBitsIntegralToBytes++instance Hashable Word where+ toBytes = finiteBitsIntegralToBytes++instance Hashable Word8 where+ toBytes = pure++instance Hashable Word16 where+ toBytes = finiteBitsIntegralToBytes++instance Hashable Word32 where+ toBytes = finiteBitsIntegralToBytes++instance Hashable Word64 where+ toBytes = finiteBitsIntegralToBytes++instance (Hashable a) => Hashable [a] where+ toBytes = concatMap toBytes++-- Helpers++enumToBytes :: (Enum a) => a -> [Word8]+enumToBytes = pure . fromIntegral . fromEnum++finiteBitsIntegralToBytes :: (FiniteBits a, Integral a) => a -> [Word8]+finiteBitsIntegralToBytes w =+ take (finiteBitSize w `div` 8)+ . fmap fromIntegral+ $ iterate (`shiftR` 8) w
+ src/Mini/Hash/Murmur32.hs view
@@ -0,0 +1,136 @@+-- | An implementation of MurmurHash3_x86_32 supporting incremental addition+module Mini.Hash.Murmur32 (+ -- * Type+ Hash32,++ -- * Construction+ seed,++ -- * Operations+ add,+ digest,+) where++import Data.Bits (+ rotateL,+ shiftL,+ shiftR,+ xor,+ )+import Data.Function (+ on,+ )+import Data.Word (+ Word32,+ Word8,+ )+import Mini.Data.Recursion (+ bool,+ uncurry3,+ )+import Mini.Hash.Class (+ Hashable,+ toBytes,+ )+import Numeric (+ showHex,+ )+import Prelude (+ Eq,+ Ord,+ Show,+ compare,+ foldr,+ fromIntegral,+ null,+ showsPrec,+ ($),+ (*),+ (+),+ (.),+ (<>),+ (==),+ )++-- Type++-- | Abstract representation of a 32-bit hash value+data Hash32 = Hash32 Word32 Word32 [Word8]++instance Eq Hash32 where+ (==) = (==) `on` digest++instance Ord Hash32 where+ compare = compare `on` digest++instance Show Hash32 where+ showsPrec _ = showHex . digest++-- Construction++-- | Make a hash from a seed+seed :: Word32 -> Hash32+seed s = Hash32 s 0 []++-- Operations++-- | Add a hashable type to a hash+add :: (Hashable a) => a -> Hash32 -> Hash32+add a = addBytes $ toBytes a++-- | Get the digest of a hash+digest :: Hash32 -> Word32+digest (Hash32 h1 len t) =+ let (k0, tlen) =+ foldr+ (\a (b, n) -> (fromIntegral a `xor` (b `shiftL` 8), n + 1))+ (0, 0)+ t+ len' = len + tlen+ k1 = k0 * 0xcc9e2d51+ k2 = k1 `rotateL` 15+ k3 = k2 * 0x1b873593+ h2 = h1 `xor` k3+ in mix+ . bool+ (h2 `xor` len')+ (h1 `xor` len)+ $ null t++-- Helpers++addBytes :: [Word8] -> Hash32 -> Hash32+addBytes new (Hash32 h0 len0 old) = uncurry3 Hash32 $ go h0 len0 (old <> new)+ where+ go h len (a : b : c : d : rest) =+ let d' = fromIntegral d `shiftL` 24+ c' = fromIntegral c `shiftL` 16+ b' = fromIntegral b `shiftL` 8+ a' = fromIntegral a+ w = a' `xor` b' `xor` c' `xor` d'+ h' = murmur w h+ len' = len + 4+ in go h' len' rest+ go h len bs = (h, len, bs)++murmur :: Word32 -> Word32 -> Word32+murmur k1 h1 =+ let c1 = 0xcc9e2d51+ c2 = 0x1b873593+ c3 = 0xe6546b64+ k2 = k1 * c1+ k3 = k2 `rotateL` 15+ k4 = k3 * c2+ h2 = h1 `xor` k4+ h3 = h2 `rotateL` 13+ h4 = h3 * 5 + c3+ in h4++mix :: Word32 -> Word32+mix h1 =+ let h2 = h1 `xor` (h1 `shiftR` 16)+ h3 = h2 * 0x85ebca6b+ h4 = h3 `xor` (h3 `shiftR` 13)+ h5 = h4 * 0xc2b2ae35+ h6 = h5 `xor` (h5 `shiftR` 16)+ in h6
+ src/Mini/Optics/Lens.hs view
@@ -0,0 +1,60 @@+{-# LANGUAGE RankNTypes #-}++-- | Compose polymorphic record updates with /van Laarhoven/ lenses+module Mini.Optics.Lens (+ -- * Type+ Lens,++ -- * Construction+ lens,++ -- * Operations+ over,+ set,+ view,+) where++import Control.Applicative (+ Const (+ Const+ ),+ getConst,+ )+import Data.Functor.Identity (+ Identity (+ Identity+ ),+ runIdentity,+ )+import Prelude (+ Functor,+ const,+ ($),+ (.),+ (<$>),+ )++-- Type++-- | A reference updating structures from /s/ to /t/ and fields from /a/ to /b/+type Lens s t a b = forall f. (Functor f) => (a -> f b) -> (s -> f t)++-- Construction++-- | Make a lens from a getter and a setter+lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b+lens sa sbt ab s = sbt s <$> ab (sa s)++-- Operations++-- | Update the field referenced by a lens with an operation on a structure+over :: Lens s t a b -> (a -> b) -> s -> t+over o ab = runIdentity . o (Identity . ab)++-- | Overwrite the field referenced by a lens with a value on a structure+set :: Lens s t a b -> b -> s -> t+set o b = runIdentity . o (const $ Identity b)++-- | Fetch the field referenced by a lens from a structure+view :: Lens s t a b -> s -> a+view o = getConst . o Const
+ src/Mini/Random/Class.hs view
@@ -0,0 +1,149 @@+-- | A pure interface for pseudorandom value generation+module Mini.Random.Class (+ -- * Classes+ Generator (+ nextWord32,+ nextWord64+ ),+ Random (+ random+ ),++ -- * Operations+ randoms,+) where++import Data.Bifunctor (+ first,+ )+import Data.Bits (+ shiftL,+ shiftR,+ (.&.),+ (.|.),+ )+import Data.Int (+ Int16,+ Int32,+ Int64,+ Int8,+ )+import Data.List (+ unfoldr,+ )+import Data.Word (+ Word,+ Word16,+ Word32,+ Word64,+ Word8,+ )+import Mini.Hash.Murmur32 (+ Hash32,+ add,+ digest,+ )+import Prelude (+ Bool,+ Char,+ Double,+ Float,+ Int,+ Integer,+ Maybe (+ Just+ ),+ fromIntegral,+ odd,+ toEnum,+ (.),+ (/),+ )++-- Classes++-- | The class of pseudorandom number generators+class Generator g where+ nextWord32 :: g -> (Word32, g)+ nextWord32 = first fromIntegral . nextWord64+ nextWord64 :: g -> (Word64, g)++instance Generator Hash32 where+ nextWord32 h = let d = digest h in (d, add d h)+ nextWord64 h =+ let (lo, g) = nextWord32 h+ (hi, g') = nextWord32 g+ lo' = fromIntegral lo+ hi' = fromIntegral hi `shiftL` 32+ in (lo' .|. hi', g')++-- | The class of types for which pseudorandom values can be generated+class Random a where+ random :: (Generator g) => g -> (a, g)++instance Random Bool where+ random = first odd . nextWord32++-- | Limited to 7-bit values (ASCII)+instance Random Char where+ random = first (toEnum . fromIntegral . (.&. 0x7F)) . nextWord32++instance Random Int8 where+ random = first fromIntegral . nextWord32++instance Random Int16 where+ random = first fromIntegral . nextWord32++instance Random Int32 where+ random = first fromIntegral . nextWord32++instance Random Int64 where+ random = first fromIntegral . nextWord64++-- | Limited to 64-bit values+instance Random Int where+ random = first (fromIntegral . (fromIntegral :: Word64 -> Int64)) . nextWord64++-- | Limited to 64-bit values+instance Random Integer where+ random = first (fromIntegral . (fromIntegral :: Word64 -> Int64)) . nextWord64++instance Random Word8 where+ random = first fromIntegral . nextWord32++instance Random Word16 where+ random = first fromIntegral . nextWord32++instance Random Word32 where+ random = nextWord32++instance Random Word64 where+ random = nextWord64++-- | Limited to 64-bit values+instance Random Word where+ random = first fromIntegral . nextWord64++-- | Limited to values in the semi-open interval [0, 1)+instance Random Float where+ random = first go . nextWord32+ where+ go w =+ let w24 = w `shiftR` 8+ b24 = 1 `shiftL` 24 :: Word32+ in fromIntegral w24 / fromIntegral b24++-- | Limited to values in the semi-open interval [0, 1)+instance Random Double where+ random = first go . nextWord64+ where+ go w =+ let w53 = w `shiftR` 11+ b53 = 1 `shiftL` 53 :: Word64+ in fromIntegral w53 / fromIntegral b53++-- Operations++-- | Generate an infinite list of pseudorandom values+randoms :: (Random a, Generator g) => g -> [a]+randoms = unfoldr (Just . random)
+ src/Mini/Transformers/Class.hs view
@@ -0,0 +1,23 @@+-- | The class of monad transformers+module Mini.Transformers.Class (+ -- * Class+ MonadTrans (+ lift+ ),+) where++import Prelude (+ Monad,+ )++-- Class++{- | Instances should satisfy the following laws:++> lift . pure = pure++> lift (m >>= f) = lift m >>= (lift . f)+-}+class MonadTrans t where+ -- | Lift a computation from the inner monad to the transformer monad+ lift :: (Monad m) => m a -> t m a
+ src/Mini/Transformers/EitherT.hs view
@@ -0,0 +1,104 @@+-- | Extend a monad with the ability to terminate a computation with a value+module Mini.Transformers.EitherT (+ -- * Type+ EitherT (+ EitherT+ ),+ runEitherT,++ -- * Operations+ anticipate,+ left,+) where++import Control.Applicative (+ Alternative,+ empty,+ (<|>),+ )+import Control.Monad (+ ap,+ liftM,+ (>=>),+ )+import Control.Monad.IO.Class (+ MonadIO,+ liftIO,+ )+import Mini.Transformers.Class (+ MonadTrans,+ lift,+ )+import Prelude (+ Applicative,+ Either (+ Left,+ Right+ ),+ Functor,+ Monad,+ MonadFail,+ Monoid,+ either,+ fail,+ fmap,+ mappend,+ mempty,+ pure,+ ($),+ (.),+ (<$>),+ (<*>),+ (>>=),+ )++-- Type++-- | A terminable transformer with termination /e/, inner monad /m/, return /a/+newtype EitherT e m a = EitherT+ { runEitherT :: m (Either e a)+ -- ^ Unwrap a transformer computation+ }++instance (Monad m) => Functor (EitherT e m) where+ fmap = liftM++instance (Monad m) => Applicative (EitherT e m) where+ pure = EitherT . pure . Right+ (<*>) = ap++instance (Monad m, Monoid e) => Alternative (EitherT e m) where+ empty = left mempty+ m <|> n =+ EitherT $+ runEitherT m+ >>= either+ (\e -> either (Left . mappend e) Right <$> runEitherT n)+ (pure . Right)++instance (Monad m) => Monad (EitherT e m) where+ m >>= k =+ EitherT $+ runEitherT m+ >>= either+ (pure . Left)+ (runEitherT . k)++instance MonadTrans (EitherT e) where+ lift = EitherT . fmap Right++instance (MonadFail m) => MonadFail (EitherT e m) where+ fail = EitherT . fail++instance (MonadIO m) => MonadIO (EitherT e m) where+ liftIO = lift . liftIO++-- Operations++-- | Run a computation and get its result+anticipate :: (Monad m) => EitherT e m a -> EitherT e m (Either e a)+anticipate = lift . runEitherT . (Right <$>) >=> either (pure . Left) pure++-- | Terminate the computation with a value+left :: (Applicative m) => e -> EitherT e m a+left = EitherT . pure . Left
+ src/Mini/Transformers/MaybeT.hs view
@@ -0,0 +1,102 @@+-- | Extend a monad with the ability to terminate a computation without a value+module Mini.Transformers.MaybeT (+ -- * Type+ MaybeT (+ MaybeT+ ),+ runMaybeT,++ -- * Operations+ anticipate,+ nothing,+) where++import Control.Applicative (+ Alternative,+ empty,+ (<|>),+ )+import Control.Monad (+ ap,+ liftM,+ (>=>),+ )+import Control.Monad.IO.Class (+ MonadIO,+ liftIO,+ )+import Mini.Transformers.Class (+ MonadTrans,+ lift,+ )+import Prelude (+ Applicative,+ Functor,+ Maybe (+ Just,+ Nothing+ ),+ Monad,+ MonadFail,+ const,+ fail,+ fmap,+ maybe,+ pure,+ ($),+ (.),+ (<$>),+ (<*>),+ (>>=),+ )++-- Type++-- | A terminable transformer with inner monad /m/, return /a/+newtype MaybeT m a = MaybeT+ { runMaybeT :: m (Maybe a)+ -- ^ Unwrap a transformer computation+ }++instance (Monad m) => Functor (MaybeT m) where+ fmap = liftM++instance (Monad m) => Applicative (MaybeT m) where+ pure = MaybeT . pure . Just+ (<*>) = ap++instance (Monad m) => Alternative (MaybeT m) where+ empty = nothing+ m <|> n =+ MaybeT $+ runMaybeT m+ >>= maybe+ (runMaybeT n)+ (pure . Just)++instance (Monad m) => Monad (MaybeT m) where+ m >>= k =+ MaybeT $+ runMaybeT m+ >>= maybe+ (pure Nothing)+ (runMaybeT . k)++instance MonadTrans MaybeT where+ lift = MaybeT . fmap Just++instance (Monad m) => MonadFail (MaybeT m) where+ fail = const nothing++instance (MonadIO m) => MonadIO (MaybeT m) where+ liftIO = lift . liftIO++-- Operations++-- | Run a computation and get its result+anticipate :: (Monad m) => MaybeT m a -> MaybeT m (Maybe a)+anticipate = lift . runMaybeT . (Just <$>) >=> maybe (pure Nothing) pure++-- | Terminate the computation without a value+nothing :: (Applicative m) => MaybeT m a+nothing = MaybeT $ pure Nothing
+ src/Mini/Transformers/ParserT.hs view
@@ -0,0 +1,296 @@+{-# LANGUAGE TupleSections #-}++-- | Extend a monad with the ability to parse symbol sequences+module Mini.Transformers.ParserT (+ -- * Type+ ParserT (+ ParserT+ ),+ runParserT,++ -- * Parsers+ eof,+ item,+ look,+ noneOf,+ oneOf,+ peek,+ sat,+ string,+ symbol,++ -- * Combinators+ accept,+ atLeast,+ atMost,+ between,+ chainl1,+ chainr1,+ findAll,+ findAll1,+ findFirst,+ findLast,+ option,+ range,+ reject,+ sepBy,+ sepBy1,+ till,+ till1,+) where++import Control.Applicative (+ Alternative,+ empty,+ many,+ some,+ (<|>),+ )+import Control.Monad (+ ap,+ liftM,+ replicateM,+ (>=>),+ )+import Control.Monad.IO.Class (+ MonadIO,+ liftIO,+ )+import Data.Bool (+ bool,+ )+import Mini.Data.Recursion (+ list,+ )+import Mini.Transformers.Class (+ MonadTrans,+ lift,+ )+import Prelude (+ Applicative,+ Bool (+ True+ ),+ Eq,+ Foldable,+ Functor,+ Int,+ Maybe (+ Just,+ Nothing+ ),+ Monad,+ MonadFail,+ Monoid,+ Semigroup,+ Traversable,+ const,+ elem,+ fail,+ flip,+ fmap,+ fst,+ maybe,+ mempty,+ notElem,+ pure,+ traverse,+ ($),+ (*>),+ (-),+ (.),+ (<$),+ (<$>),+ (<*),+ (<*>),+ (<>),+ (==),+ (>),+ (>>=),+ )++-- Type++-- | A transformer parsing symbols /s/, inner monad /m/, return /a/+newtype ParserT s m a = ParserT+ { runParserT :: [s] -> m (Maybe (a, [s]))+ -- ^ Unwrap a transformer computation with a sequence of symbols to parse+ }++instance (Monad m) => Functor (ParserT s m) where+ fmap = liftM++instance (Monad m) => Applicative (ParserT s m) where+ pure a = ParserT $ pure . Just . (a,)+ (<*>) = ap++instance (Monad m) => Alternative (ParserT s m) where+ empty = ParserT . const $ pure Nothing+ m <|> n = ParserT $ \ss -> (<|>) <$> runParserT m ss <*> runParserT n ss++instance (Monad m) => Monad (ParserT s m) where+ m >>= k =+ ParserT $+ runParserT m+ >=> maybe+ (pure Nothing)+ (\(a, ss') -> runParserT (k a) ss')++instance MonadTrans (ParserT s) where+ lift m = ParserT $ \ss -> Just . (,ss) <$> m++instance (Monad m, Semigroup a) => Semigroup (ParserT s m a) where+ m <> n = (<>) <$> m <*> n++instance (Monad m, Monoid a) => Monoid (ParserT s m a) where+ mempty = pure mempty++instance (Monad m) => MonadFail (ParserT s m) where+ fail = const empty++instance (MonadIO m) => MonadIO (ParserT s m) where+ liftIO = lift . liftIO++-- Parsers++-- | Parse successfully only at end of input+eof :: (Monad m) => ParserT s m ()+eof = reject item++-- | Parse any symbol+item :: (Applicative m) => ParserT s m s+item = sat $ const True++-- | Parse the rest of the input without consuming it+look :: (Applicative m) => ParserT s m [s]+look = ParserT $ \ss -> pure $ Just (ss, ss)++-- | Parse the next symbol if excluded from a collection+noneOf :: (Applicative m, Foldable t, Eq s) => t s -> ParserT s m s+noneOf = sat . flip notElem++-- | Parse the next symbol if included in a collection+oneOf :: (Applicative m, Foldable t, Eq s) => t s -> ParserT s m s+oneOf = sat . flip elem++-- | Parse the next symbol without consuming it+peek :: (Monad m) => ParserT s m s+peek = accept item++-- | Parse the next symbol if it satisfies a predicate+sat :: (Applicative m) => (s -> Bool) -> ParserT s m s+sat p =+ ParserT $+ pure+ . list+ Nothing+ ( \s ss _ ->+ bool+ Nothing+ (Just (s, ss))+ $ p s+ )++-- | Parse a sequence of symbols+string :: (Monad m, Traversable t, Eq s) => t s -> ParserT s m (t s)+string = traverse symbol++-- | Parse a specific symbol+symbol :: (Applicative m, Eq s) => s -> ParserT s m s+symbol = sat . (==)++-- Combinators++-- | Parse @p@, without consuming input, iff @p@ succeeds via @accept p@+accept :: (Monad m) => ParserT s m a -> ParserT s m a+accept p = ParserT $ \ss -> fmap ((,ss) . fst) <$> runParserT p ss++-- | Parse @n@ or more occurrences of @p@ via @atLeast n p@+atLeast :: (Monad m) => Int -> ParserT s m a -> ParserT s m [a]+atLeast n p = replicateM n p <> many p++-- | Parse up to @n@ occurrences of @p@ via @atMost n p@+atMost :: (Monad m) => Int -> ParserT s m a -> ParserT s m [a]+atMost n p =+ bool+ (pure [])+ (option [] $ (:) <$> p <*> atMost (n - 1) p)+ $ n > 0++-- | Parse @p@ enclosed by @a@ and @b@ via @between a b p@+between+ :: (Monad m)+ => ParserT s m open+ -> ParserT s m close+ -> ParserT s m a+ -> ParserT s m a+between open close p = open *> p <* close++-- | Parse one or more @p@ left-associatively chained by @f@ via @chainl1 p f@+chainl1+ :: (Monad m)+ => ParserT s m a+ -> ParserT s m (a -> a -> a)+ -> ParserT s m a+chainl1 p f = p >>= go+ where+ go a = option a $ f <*> pure a <*> p >>= go++-- | Parse one or more @p@ right-associatively chained by @f@ via @chainr1 p f@+chainr1+ :: (Monad m)+ => ParserT s m a+ -> ParserT s m (a -> a -> a)+ -> ParserT s m a+chainr1 p f = go+ where+ go = p >>= rest+ rest a = option a $ f <*> pure a <*> go >>= rest++-- | Find and parse zero or more occurrences of @p@ via @findAll p@+findAll :: (Monad m) => ParserT s m a -> ParserT s m [a]+findAll = many . findFirst++-- | Find and parse one or more occurrences of @p@ via @findAll1 p@+findAll1 :: (Monad m) => ParserT s m a -> ParserT s m [a]+findAll1 = some . findFirst++-- | Find and parse the first occurrence of @p@ via @findFirst p@+findFirst :: (Monad m) => ParserT s m a -> ParserT s m a+findFirst p = p <|> (item *> findFirst p)++-- | Find and parse the last occurrence of @p@ via @findLast p@+findLast :: (Monad m) => ParserT s m a -> ParserT s m a+findLast p = findFirst p >>= flip option (findLast p)++-- | Parse @p@ returning @a@ in case of failure via @option a p@+option :: (Monad m) => a -> ParserT s m a -> ParserT s m a+option a p = p <|> pure a++-- | Parse between @lo@ and @hi@ occurrences of @p@ via @range lo hi p@+range :: (Monad m) => Int -> Int -> ParserT s m a -> ParserT s m [a]+range lo hi p = replicateM lo p <> atMost (hi - lo) p++-- | Parse @p@, without consuming input, iff @p@ fails via @reject p@+reject :: (Monad m) => ParserT s m a -> ParserT s m ()+reject p = ParserT $ \ss ->+ runParserT p ss+ >>= maybe+ (pure $ Just ((), ss))+ (const $ pure Nothing)++-- | Parse zero or more @p@ separated by @q@ via @p \`sepBy\` q@+sepBy :: (Monad m) => ParserT s m a -> ParserT s m b -> ParserT s m [a]+sepBy p = option [] . sepBy1 p++-- | Parse one or more @p@ separated by @q@ via @p \`sepBy1\` q@+sepBy1 :: (Monad m) => ParserT s m a -> ParserT s m b -> ParserT s m [a]+sepBy1 p sep = (:) <$> p <*> many (sep *> p)++-- | Parse zero or more @p@ until @q@ succeeds via @p \`till\` q@+till :: (Monad m) => ParserT s m a -> ParserT s m b -> ParserT s m [a]+till p end = ([] <$ end) <|> till1 p end++-- | Parse one or more @p@ until @q@ succeeds via @p \`till1\` q@+till1 :: (Monad m) => ParserT s m a -> ParserT s m b -> ParserT s m [a]+till1 p end = (:) <$> p <*> till p end
+ src/Mini/Transformers/ReaderT.hs view
@@ -0,0 +1,85 @@+-- | Extend a monad with a read-only environment+module Mini.Transformers.ReaderT (+ -- * Type+ ReaderT (+ ReaderT+ ),+ runReaderT,++ -- * Operations+ ask,+ local,+) where++import Control.Applicative (+ Alternative,+ empty,+ (<|>),+ )+import Control.Monad (+ ap,+ liftM,+ )+import Control.Monad.IO.Class (+ MonadIO,+ liftIO,+ )+import Mini.Transformers.Class (+ MonadTrans,+ lift,+ )+import Prelude (+ Applicative,+ Functor,+ Monad,+ MonadFail,+ const,+ fail,+ fmap,+ pure,+ ($),+ (.),+ (<*>),+ (>>=),+ )++-- Type++-- | A transformer with read-only /r/, inner monad /m/, return /a/+newtype ReaderT r m a = ReaderT+ { runReaderT :: r -> m a+ -- ^ Unwrap a transformer computation with an initial read-only value+ }++instance (Monad m) => Functor (ReaderT r m) where+ fmap = liftM++instance (Monad m) => Applicative (ReaderT r m) where+ pure = lift . pure+ (<*>) = ap++instance (Monad m, Alternative m) => Alternative (ReaderT r m) where+ empty = lift empty+ m <|> n = ReaderT $ \r -> runReaderT m r <|> runReaderT n r++instance (Monad m) => Monad (ReaderT r m) where+ m >>= k = ReaderT $ \r -> runReaderT m r >>= (`runReaderT` r) . k++instance MonadTrans (ReaderT r) where+ lift = ReaderT . const++instance (MonadFail m) => MonadFail (ReaderT r m) where+ fail = lift . fail++instance (MonadIO m) => MonadIO (ReaderT r m) where+ liftIO = lift . liftIO++-- Operations++-- | Fetch the read-only environment+ask :: (Monad m) => ReaderT r m r+ask = ReaderT pure++-- | Run a computation in a modified environment+local :: (r -> r') -> ReaderT r' m a -> ReaderT r m a+local f m = ReaderT $ runReaderT m . f
+ src/Mini/Transformers/StateT.hs view
@@ -0,0 +1,94 @@+{-# LANGUAGE TupleSections #-}++-- | Extend a monad with a modifiable environment+module Mini.Transformers.StateT (+ -- * Type+ StateT (+ StateT+ ),+ runStateT,++ -- * Operations+ get,+ modify,+ put,+) where++import Control.Applicative (+ Alternative,+ empty,+ (<|>),+ )+import Control.Monad (+ ap,+ liftM,+ (>=>),+ )+import Control.Monad.IO.Class (+ MonadIO,+ liftIO,+ )+import Mini.Transformers.Class (+ MonadTrans,+ lift,+ )+import Prelude (+ Applicative,+ Functor,+ Monad,+ MonadFail,+ const,+ fail,+ fmap,+ pure,+ ($),+ (.),+ (<$>),+ (<*>),+ (>>=),+ )++-- Type++-- | A transformer with state /s/, inner monad /m/, return /a/+newtype StateT s m a = StateT+ { runStateT :: s -> m (a, s)+ -- ^ Unwrap a transformer computation with an initial state+ }++instance (Monad m) => Functor (StateT s m) where+ fmap = liftM++instance (Monad m) => Applicative (StateT s m) where+ pure a = StateT $ pure . (a,)+ (<*>) = ap++instance (Monad m, Alternative m) => Alternative (StateT s m) where+ empty = StateT $ const empty+ m <|> n = StateT $ \s -> runStateT m s <|> runStateT n s++instance (Monad m) => Monad (StateT s m) where+ m >>= k = StateT $ runStateT m >=> (\(a, s) -> runStateT (k a) s)++instance MonadTrans (StateT s) where+ lift m = StateT $ \s -> (,s) <$> m++instance (MonadFail m) => MonadFail (StateT s m) where+ fail = StateT . const . fail++instance (MonadIO m) => MonadIO (StateT s m) where+ liftIO = lift . liftIO++-- Operations++-- | Fetch the current state+get :: (Monad m) => StateT s m s+get = StateT $ \s -> pure (s, s)++-- | Update the current state with an operation+modify :: (Monad m) => (s -> s) -> StateT s m ()+modify f = StateT $ pure . ((),) . f++-- | Overwrite the current state with a value+put :: (Monad m) => s -> StateT s m ()+put = StateT . const . pure . ((),)
+ src/Mini/Transformers/WriterT.hs view
@@ -0,0 +1,87 @@+{-# LANGUAGE TupleSections #-}++-- | Extend a monad with an accumulative write-only environment+module Mini.Transformers.WriterT (+ -- * Type+ WriterT (+ WriterT+ ),+ runWriterT,++ -- * Operations+ tell,+) where++import Control.Applicative (+ Alternative,+ empty,+ (<|>),+ )+import Control.Monad (+ ap,+ liftM,+ )+import Control.Monad.IO.Class (+ MonadIO,+ liftIO,+ )+import Mini.Transformers.Class (+ MonadTrans,+ lift,+ )+import Prelude (+ Applicative,+ Functor,+ Monad,+ MonadFail,+ Monoid,+ fail,+ fmap,+ mempty,+ pure,+ ($),+ (.),+ (<*>),+ (<>),+ (>>=),+ )++-- Type++-- | A transformer with monoidal write-only /w/, inner monad /m/, return /a/+newtype WriterT w m a = WriterT+ { runWriterT :: m (a, w)+ -- ^ Unwrap a transformer computation+ }++instance (Monad m, Monoid w) => Functor (WriterT w m) where+ fmap = liftM++instance (Monad m, Monoid w) => Applicative (WriterT w m) where+ pure = WriterT . pure . (,mempty)+ (<*>) = ap++instance (Monad m, Alternative m, Monoid w) => Alternative (WriterT w m) where+ empty = WriterT empty+ m <|> n = WriterT $ runWriterT m <|> runWriterT n++instance (Monad m, Monoid w) => Monad (WriterT w m) where+ m >>= k = WriterT $ do+ (a, w) <- runWriterT m+ (b, w') <- runWriterT (k a)+ pure (b, w <> w')++instance (Monoid w) => MonadTrans (WriterT w) where+ lift = WriterT . fmap (,mempty)++instance (MonadFail m, Monoid w) => MonadFail (WriterT w m) where+ fail = WriterT . fail++instance (MonadIO m, Monoid w) => MonadIO (WriterT w m) where+ liftIO = lift . liftIO++-- Operations++-- | Append a value to the write-only environment+tell :: (Monad m) => w -> WriterT w m ()+tell = WriterT . pure . ((),)