-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Prelude replacement -- -- Features -- --
-- import Data.Monoid -- import TextShow -- -- data Example = Example Int Int -- instance TextShow Example where -- showb (Example i1 i2) = showb i1 <> showbSpace <> showb i2 ---- -- If you do not want to create TextShow instances manually, you -- can alternatively use the TextShow.TH module to automatically -- generate default TextShow instances using Template Haskell, or -- the TextShow.Generic module to quickly define TextShow -- instances using genericShowbPrec. -- -- Since: 2 class TextShow a -- | Convert a value to a Builder with the given predence. -- -- Since: 2 showbPrec :: TextShow a => Int -> a -> Builder -- | Converts a value to a strict Text. If you hand-define this, it -- should satisfy: -- --
-- showb = showbPrec 0 ---- -- Since: 2 showb :: TextShow a => a -> Builder -- | Converts a list of values to a Builder. By default, this is -- defined as 'showbList = showbListWith showb, -- but it can be overridden to allow for specialized displaying of lists -- (e.g., lists of Chars). -- -- Since: 2 showbList :: TextShow a => [a] -> Builder -- | Converts a value to a strict Text with the given precedence. -- This can be overridden for efficiency, but it should satisfy: -- --
-- showtPrec p = toStrict . showtlPrec p ---- -- Since: 3 showtPrec :: TextShow a => Int -> a -> Text -- | Converts a value to a strict Text. This can be overridden for -- efficiency, but it should satisfy: -- --
-- showt = showtPrec 0 -- showt = toStrict . showtl ---- -- The first equation is the default definition of showt. -- -- Since: 3 showt :: TextShow a => a -> Text -- | Converts a list of values to a strict Text. This can be -- overridden for efficiency, but it should satisfy: -- --
-- showtList = toStrict . showtlList ---- -- Since: 3 showtList :: TextShow a => [a] -> Text -- | Converts a value to a lazy Text with the given precedence. This -- can be overridden for efficiency, but it should satisfy: -- --
-- showtlPrec p = toLazyText . showbPrec p ---- -- Since: 3 showtlPrec :: TextShow a => Int -> a -> Text -- | Converts a value to a lazy Text. This can be overridden for -- efficiency, but it should satisfy: -- --
-- showtl = showtlPrec 0 -- showtl = toLazyText . showb ---- -- The first equation is the default definition of showtl. -- -- Since: 3 showtl :: TextShow a => a -> Text -- | Converts a list of values to a lazy Text. This can be -- overridden for efficiency, but it should satisfy: -- --
-- showtlList = toLazyText . showbList ---- -- Since: 3 showtlList :: TextShow a => [a] -> Text show :: TextShow a => a -> Text gShowPrec :: (Generic a, GTextShowB Zero (Rep a)) => Int -> a -> Builder print :: (TextShow a, MonadIO m) => a -> m () module Precursor.Numeric.Num -- | A class which represents things that can be converted from integer -- literals class Num a where fromInteger = fromInteger fromInteger :: Num a => Integer -> a fromInteger :: (Num a, Num a) => Integer -> a -- | Double-precision floating point numbers. It is desirable that this -- type be at least equal in range and precision to the IEEE -- double-precision type. data Double :: * -- | Single-precision floating point numbers. It is desirable that this -- type be at least equal in range and precision to the IEEE -- single-precision type. data Float :: * -- | A fixed-precision integer type with at least the range [-2^29 .. -- 2^29-1]. The exact range for a given implementation can be -- determined by using minBound and maxBound from the -- Bounded class. data Int :: * -- | Invariant: Jn# and Jp# are used iff value doesn't fit in -- S# -- -- Useful properties resulting from the invariants: -- -- data Integer :: * instance Precursor.Numeric.Num.Num GHC.Integer.Type.Integer instance Precursor.Numeric.Num.Num GHC.Types.Int instance Precursor.Numeric.Num.Num GHC.Int.Int8 instance Precursor.Numeric.Num.Num GHC.Int.Int16 instance Precursor.Numeric.Num.Num GHC.Int.Int32 instance Precursor.Numeric.Num.Num GHC.Int.Int64 instance Precursor.Numeric.Num.Num GHC.Types.Double instance Precursor.Numeric.Num.Num GHC.Types.Float module Precursor.Data.Tuple -- | Extract the first component of a pair. fst :: (a, b) -> a -- | Extract the second component of a pair. snd :: (a, b) -> b -- | curry converts an uncurried function to a curried function. curry :: ((a, b) -> c) -> a -> b -> c -- | uncurry converts a curried function to a function on pairs. uncurry :: (a -> b -> c) -> (a, b) -> c -- | Swap the components of a pair. swap :: (a, b) -> (b, a) module Precursor.Data.Maybe -- | The Maybe type encapsulates an optional value. A value of type -- Maybe a either contains a value of type a -- (represented as Just a), or it is empty (represented -- as Nothing). Using Maybe is a good way to deal with -- errors or exceptional cases without resorting to drastic measures such -- as error. -- -- The Maybe type is also a monad. It is a simple kind of error -- monad, where all errors are represented by Nothing. A richer -- error monad can be built using the Either type. data Maybe a :: * -> * Nothing :: Maybe a Just :: a -> Maybe a -- | The maybe function takes a default value, a function, and a -- Maybe value. If the Maybe value is Nothing, the -- function returns the default value. Otherwise, it applies the function -- to the value inside the Just and returns the result. -- --
-- >>> maybe False odd (Just 3) -- True ---- --
-- >>> maybe False odd Nothing -- False ---- -- Read an integer from a string using readMaybe. If we succeed, -- return twice the integer; that is, apply (*2) to it. If -- instead we fail to parse an integer, return 0 by default: -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> maybe 0 (*2) (readMaybe "5") -- 10 -- -- >>> maybe 0 (*2) (readMaybe "") -- 0 ---- -- Apply show to a Maybe Int. If we have Just -- n, we want to show the underlying Int n. But if -- we have Nothing, we return the empty string instead of (for -- example) "Nothing": -- --
-- >>> maybe "" show (Just 5) -- "5" -- -- >>> maybe "" show Nothing -- "" --maybe :: b -> (a -> b) -> Maybe a -> b -- | The fromMaybe function takes a default value and and -- Maybe value. If the Maybe is Nothing, it returns -- the default values; otherwise, it returns the value contained in the -- Maybe. -- --
-- >>> fromMaybe "" (Just "Hello, World!") -- "Hello, World!" ---- --
-- >>> fromMaybe "" Nothing -- "" ---- -- Read an integer from a string using readMaybe. If we fail to -- parse an integer, we want to return 0 by default: -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> fromMaybe 0 (readMaybe "5") -- 5 -- -- >>> fromMaybe 0 (readMaybe "") -- 0 --fromMaybe :: a -> Maybe a -> a -- | An efficient implementation of ordered maps from keys to values -- (dictionaries). -- -- API of this module is strict in both the keys and the values. If you -- need value-lazy maps, use Data.Map.Lazy instead. The Map -- type is shared between the lazy and strict modules, meaning that the -- same Map value can be passed to functions in both modules -- (although that is rarely needed). -- -- These modules are intended to be imported qualified, to avoid name -- clashes with Prelude functions, e.g. -- --
-- import qualified Data.Map.Strict as Map ---- -- The implementation of Map is based on size balanced -- binary trees (or trees of bounded balance) as described by: -- --
-- import Prelude hiding (lookup)
-- import Data.Map
--
-- employeeDept = fromList([("John","Sales"), ("Bob","IT")])
-- deptCountry = fromList([("IT","USA"), ("Sales","France")])
-- countryCurrency = fromList([("USA", "Dollar"), ("France", "Euro")])
--
-- employeeCurrency :: String -> Maybe String
-- employeeCurrency name = do
-- dept <- lookup name employeeDept
-- country <- lookup dept deptCountry
-- lookup country countryCurrency
--
-- main = do
-- putStrLn $ "John's currency: " ++ (show (employeeCurrency "John"))
-- putStrLn $ "Pete's currency: " ++ (show (employeeCurrency "Pete"))
--
--
-- The output of this program:
--
-- -- John's currency: Just "Euro" -- Pete's currency: Nothing --lookup :: Ord k => k -> Map k a -> Maybe a -- | O(log n). Insert a new key and value in the map. If the key is -- already present in the map, the associated value is replaced with the -- supplied value. insert is equivalent to insertWith -- const. -- --
-- insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')] -- insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')] -- insert 5 'x' empty == singleton 5 'x' --insert :: Ord k => k -> a -> Map k a -> Map k a -- | O(log n). Delete a key and its value from the map. When the key -- is not a member of the map, the original map is returned. -- --
-- delete 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" -- delete 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] -- delete 5 empty == empty --delete :: Ord k => k -> Map k a -> Map k a module Precursor.Data.Either -- | The Either type represents values with two possibilities: a -- value of type Either a b is either Left -- a or Right b. -- -- The Either type is sometimes used to represent a value which is -- either correct or an error; by convention, the Left constructor -- is used to hold an error value and the Right constructor is -- used to hold a correct value (mnemonic: "right" also means "correct"). -- --
-- >>> let s = Left "foo" :: Either String Int -- -- >>> s -- Left "foo" -- -- >>> let n = Right 3 :: Either String Int -- -- >>> n -- Right 3 -- -- >>> :type s -- s :: Either String Int -- -- >>> :type n -- n :: Either String Int ---- -- The fmap from our Functor instance will ignore -- Left values, but will apply the supplied function to values -- contained in a Right: -- --
-- >>> let s = Left "foo" :: Either String Int -- -- >>> let n = Right 3 :: Either String Int -- -- >>> fmap (*2) s -- Left "foo" -- -- >>> fmap (*2) n -- Right 6 ---- -- The Monad instance for Either allows us to chain -- together multiple actions which may fail, and fail overall if any of -- the individual steps failed. First we'll write a function that can -- either parse an Int from a Char, or fail. -- --
-- >>> import Data.Char ( digitToInt, isDigit )
--
-- >>> :{
-- let parseEither :: Char -> Either String Int
-- parseEither c
-- | isDigit c = Right (digitToInt c)
-- | otherwise = Left "parse error"
--
-- >>> :}
--
--
-- The following should work, since both '1' and '2'
-- can be parsed as Ints.
--
--
-- >>> :{
-- let parseMultiple :: Either String Int
-- parseMultiple = do
-- x <- parseEither '1'
-- y <- parseEither '2'
-- return (x + y)
--
-- >>> :}
--
--
-- -- >>> parseMultiple -- Right 3 ---- -- But the following should fail overall, since the first operation where -- we attempt to parse 'm' as an Int will fail: -- --
-- >>> :{
-- let parseMultiple :: Either String Int
-- parseMultiple = do
-- x <- parseEither 'm'
-- y <- parseEither '2'
-- return (x + y)
--
-- >>> :}
--
--
-- -- >>> parseMultiple -- Left "parse error" --data Either a b :: * -> * -> * Left :: a -> Either a b Right :: b -> Either a b -- | Extracts from a list of Either all the Left elements. -- All the Left elements are extracted in order. -- --
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ] -- -- >>> lefts list -- ["foo","bar","baz"] --lefts :: [Either a b] -> [a] -- | Extracts from a list of Either all the Right elements. -- All the Right elements are extracted in order. -- --
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ] -- -- >>> rights list -- [3,7] --rights :: [Either a b] -> [b] -- | Partitions a list of Either into two lists. All the Left -- elements are extracted, in order, to the first component of the -- output. Similarly the Right elements are extracted to the -- second component of the output. -- --
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ] -- -- >>> partitionEithers list -- (["foo","bar","baz"],[3,7]) ---- -- The pair returned by partitionEithers x should be the -- same pair as (lefts x, rights x): -- --
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ] -- -- >>> partitionEithers list == (lefts list, rights list) -- True --partitionEithers :: [Either a b] -> ([a], [b]) module Precursor.Data.Bool data Bool :: * False :: Bool True :: Bool -- | Boolean "and" (&&) :: Bool -> Bool -> Bool infixr 3 && -- | Boolean "or" (||) :: Bool -> Bool -> Bool infixr 2 || -- | Boolean "not" not :: Bool -> Bool -- | otherwise is defined as the value True. It helps to make -- guards more readable. eg. -- --
-- f x | x < 0 = ... -- | otherwise = ... --otherwise :: Bool -- | Fold over a Bool. -- --
-- >>> bool 1 0 True -- 1 -- -- >>> bool 1 0 False -- 0 --bool :: a -> a -> Bool -> a -- | Used for desugaring if expressions. -- --
-- >>> ifThenElse True 1 0 -- 1 -- -- >>> ifThenElse False 1 0 -- 0 --ifThenElse :: Bool -> a -> a -> a -- | Lazy state monads. -- -- This module is inspired by the paper Functional Programming with -- Overloading and Higher-Order Polymorphism, Mark P Jones -- (http://web.cecs.pdx.edu/~mpj/) Advanced School of Functional -- Programming, 1995. module Precursor.Control.State -- | Minimal definition is either both of get and put or -- just state class Monad m => MonadState s (m :: * -> *) | m -> s -- | Return the state from the internals of the monad. get :: MonadState s m => m s -- | Replace the state inside the monad. put :: MonadState s m => s -> m () -- | Embed a simple state action into the monad. state :: MonadState s m => (s -> (a, s)) -> m a -- | Monadic state transformer. -- -- Maps an old state to a new state inside a state monad. The old state -- is thrown away. -- --
-- Main> :t modify ((+1) :: Int -> Int) -- modify (...) :: (MonadState Int a) => a () ---- -- This says that modify (+1) acts over any Monad that is a -- member of the MonadState class, with an Int state. modify :: MonadState s m => (s -> s) -> m () -- | A variant of modify in which the computation is strict in the -- new state. modify' :: MonadState s m => (s -> s) -> m () -- | Gets specific component of the state, using a projection function -- supplied. gets :: MonadState s m => (s -> a) -> m a -- | A state monad parameterized by the type s of the state to -- carry. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as -- the initial state of the second. type State s = StateT s Identity -- | Unwrap a state monad computation as a function. (The inverse of -- state.) runState :: State s a -> s -> (a, s) -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- -- evalState :: State s a -> s -> a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- -- execState :: State s a -> s -> s -- | A state transformer monad parameterized by: -- --
evalStateT m s = liftM fst -- (runStateT m s)
execStateT m s = liftM snd -- (runStateT m s)
arr id = id
arr (f >>> g) = arr f >>> -- arr g
first (arr f) = arr (first -- f)
first (f >>> g) = first f >>> -- first g
first f >>> arr fst = -- arr fst >>> f
first f >>> arr (id *** g) = -- arr (id *** g) >>> first f
first (first f) >>> arr -- assoc = arr assoc >>> first -- f
-- assoc ((a,b),c) = (a,(b,c)) ---- -- The other combinators have sensible default definitions, which may be -- overridden for efficiency. class Category * a => Arrow (a :: * -> * -> *) -- | Lift a function to an arrow. arr :: Arrow a => (b -> c) -> a b c -- | Split the input between the two argument arrows and combine their -- output. Note that this is in general not a functor. -- -- The default definition may be overridden with a more efficient version -- if desired. (***) :: Arrow a => a b c -> a b' c' -> a (b, b') (c, c') -- | Fanout: send the input to both argument arrows and combine their -- output. -- -- The default definition may be overridden with a more efficient version -- if desired. (&&&) :: Arrow a => a b c -> a b c' -> a b (c, c') -- | Lift a function to an arrow. arr :: Arrow a => forall b c. (b -> c) -> a b c -- | Split the input between the two argument arrows and combine their -- output. Note that this is in general not a functor. -- -- The default definition may be overridden with a more efficient version -- if desired. (***) :: Arrow a => forall b c b' c'. a b c -> a b' c' -> a (b, b') (c, c') -- | Fanout: send the input to both argument arrows and combine their -- output. -- -- The default definition may be overridden with a more efficient version -- if desired. (&&&) :: Arrow a => forall b c c'. a b c -> a b c' -> a b (c, c') -- | Kleisli arrows of a monad. newtype Kleisli (m :: * -> *) a b :: (* -> *) -> * -> * -> * Kleisli :: (a -> m b) -> Kleisli a b [runKleisli] :: Kleisli a b -> a -> m b -- | The identity arrow, which plays the role of return in arrow -- notation. returnA :: Arrow a => a b b -- | Precomposition with a pure function. (^>>) :: Arrow a => (b -> c) -> a c d -> a b d infixr 1 ^>> -- | Postcomposition with a pure function. (>>^) :: Arrow a => a b c -> (c -> d) -> a b d infixr 1 >>^ -- | Precomposition with a pure function (right-to-left variant). (<<^) :: Arrow a => a c d -> (b -> c) -> a b d infixr 1 <<^ -- | Postcomposition with a pure function (right-to-left variant). (^<<) :: Arrow a => (c -> d) -> a b c -> a b d infixr 1 ^<< class Arrow a => ArrowZero (a :: * -> * -> *) zeroArrow :: ArrowZero a => a b c zeroArrow :: ArrowZero a => forall b c. a b c -- | A monoid on arrows. class ArrowZero a => ArrowPlus (a :: * -> * -> *) -- | An associative operation with identity zeroArrow. (<+>) :: ArrowPlus a => a b c -> a b c -> a b c -- | An associative operation with identity zeroArrow. (<+>) :: ArrowPlus a => forall b c. a b c -> a b c -> a b c -- | Choice, for arrows that support it. This class underlies the -- if and case constructs in arrow notation. -- -- Instances should satisfy the following laws: -- --
left (arr f) = arr (left -- f)
left (f >>> g) = left f >>> -- left g
f >>> arr Left = arr -- Left >>> left f
left f >>> arr (id +++ g) = -- arr (id +++ g) >>> left f
left (left f) >>> arr -- assocsum = arr assocsum >>> -- left f
-- assocsum (Left (Left x)) = Left x -- assocsum (Left (Right y)) = Right (Left y) -- assocsum (Right z) = Right (Right z) ---- -- The other combinators have sensible default definitions, which may be -- overridden for efficiency. class Arrow a => ArrowChoice (a :: * -> * -> *) -- | Feed marked inputs through the argument arrow, passing the rest -- through unchanged to the output. left :: ArrowChoice a => a b c -> a (Either b d) (Either c d) -- | A mirror image of left. -- -- The default definition may be overridden with a more efficient version -- if desired. right :: ArrowChoice a => a b c -> a (Either d b) (Either d c) -- | Split the input between the two argument arrows, retagging and merging -- their outputs. Note that this is in general not a functor. -- -- The default definition may be overridden with a more efficient version -- if desired. (+++) :: ArrowChoice a => a b c -> a b' c' -> a (Either b b') (Either c c') -- | Fanin: Split the input between the two argument arrows and merge their -- outputs. -- -- The default definition may be overridden with a more efficient version -- if desired. (|||) :: ArrowChoice a => a b d -> a c d -> a (Either b c) d -- | Feed marked inputs through the argument arrow, passing the rest -- through unchanged to the output. left :: ArrowChoice a => forall b c d. a b c -> a (Either b d) (Either c d) -- | A mirror image of left. -- -- The default definition may be overridden with a more efficient version -- if desired. right :: ArrowChoice a => forall b c d. a b c -> a (Either d b) (Either d c) -- | Split the input between the two argument arrows, retagging and merging -- their outputs. Note that this is in general not a functor. -- -- The default definition may be overridden with a more efficient version -- if desired. (+++) :: ArrowChoice a => forall b c b' c'. a b c -> a b' c' -> a (Either b b') (Either c c') -- | Fanin: Split the input between the two argument arrows and merge their -- outputs. -- -- The default definition may be overridden with a more efficient version -- if desired. (|||) :: ArrowChoice a => forall b d c. a b d -> a c d -> a (Either b c) d -- | Some arrows allow application of arrow inputs to other inputs. -- Instances should satisfy the following laws: -- --
first (arr (\x -> arr (\y -> -- (x,y)))) >>> app = id
first (arr (g >>>)) >>> -- app = second g >>> app
first (arr (>>> h)) >>> -- app = app >>> h
-- assoc ((a,b),c) = (a,(b,c)) -- unassoc (a,(b,c)) = ((a,b),c) --class Arrow a => ArrowLoop (a :: * -> * -> *) loop :: ArrowLoop a => a (b, d) (c, d) -> a b c loop :: ArrowLoop a => forall b d c. a (b, d) (c, d) -> a b c module Precursor.Control.Functor -- | The Functor class is used for types that can be mapped over. -- Instances of Functor should satisfy the following laws: -- --
-- fmap id == id -- fmap (f . g) == fmap f . fmap g ---- -- The instances of Functor for lists, Maybe and IO -- satisfy these laws. class Functor (f :: * -> *) fmap :: Functor f => (a -> b) -> f a -> f b -- | Replace all locations in the input with the same value. The default -- definition is fmap . const, but this may be -- overridden with a more efficient version. (<$) :: Functor f => a -> f b -> f a -- | Flipped version of <$. -- --
-- >>> Nothing $> "foo" -- Nothing -- -- >>> Just 90210 $> "foo" -- Just "foo" ---- -- Replace the contents of an Either Int -- Int with a constant String, resulting in an -- Either Int String: -- --
-- >>> Left 8675309 $> "foo" -- Left 8675309 -- -- >>> Right 8675309 $> "foo" -- Right "foo" ---- -- Replace each element of a list with a constant String: -- --
-- >>> [1,2,3] $> "foo" -- ["foo","foo","foo"] ---- -- Replace the second element of a pair with a constant String: -- --
-- >>> (1,2) $> "foo" -- (1,"foo") --($>) :: Functor f => f a -> b -> f b infixl 4 $> -- | An infix synonym for fmap. -- -- The name of this operator is an allusion to $. Note the -- similarities between their types: -- --
-- ($) :: (a -> b) -> a -> b -- (<$>) :: Functor f => (a -> b) -> f a -> f b ---- -- Whereas $ is function application, <$> is -- function application lifted over a Functor. -- --
-- >>> show <$> Nothing -- Nothing -- -- >>> show <$> Just 3 -- Just "3" ---- -- Convert from an Either Int Int to -- an Either Int String using -- show: -- --
-- >>> show <$> Left 17 -- Left 17 -- -- >>> show <$> Right 17 -- Right "17" ---- -- Double each element of a list: -- --
-- >>> (*2) <$> [1,2,3] -- [2,4,6] ---- -- Apply even to the second element of a pair: -- --
-- >>> even <$> (2,2) -- (2,True) --(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 <$> -- | void value discards or ignores the result of -- evaluation, such as the return value of an IO action. -- --
-- >>> void Nothing -- Nothing -- -- >>> void (Just 3) -- Just () ---- -- Replace the contents of an Either Int -- Int with unit, resulting in an Either -- Int '()': -- --
-- >>> void (Left 8675309) -- Left 8675309 -- -- >>> void (Right 8675309) -- Right () ---- -- Replace every element of a list with unit: -- --
-- >>> void [1,2,3] -- [(),(),()] ---- -- Replace the second element of a pair with unit: -- --
-- >>> void (1,2) -- (1,()) ---- -- Discard the result of an IO action: -- --
-- >>> mapM print [1,2] -- 1 -- 2 -- [(),()] -- -- >>> void $ mapM print [1,2] -- 1 -- 2 --void :: Functor f => f a -> f () -- | A flipped version of fmap. (<&>) :: Functor f => f a -> (a -> b) -> f b infixl 1 <&> -- | Arrow-like operator. Useful for chaining with the <<< -- and <=< combinators. (<-<) :: Functor f => (b -> c) -> (a -> f b) -> a -> f c infixl 1 <-< -- | Arrow-like operator. Useful for chaining with the >>> -- and >=> combinators. (>->) :: Functor f => (a -> f b) -> (b -> c) -> a -> f c infixr 1 >-> module Precursor.Control.Monad -- | The Monad class defines the basic operations over a -- monad, a concept from a branch of mathematics known as -- category theory. From the perspective of a Haskell programmer, -- however, it is best to think of a monad as an abstract datatype -- of actions. Haskell's do expressions provide a convenient -- syntax for writing monadic expressions. -- -- Instances of Monad should satisfy the following laws: -- -- -- -- Furthermore, the Monad and Applicative operations should -- relate as follows: -- -- -- -- The above laws imply: -- -- -- -- and that pure and (<*>) satisfy the applicative -- functor laws. -- -- The instances of Monad for lists, Maybe and IO -- defined in the Prelude satisfy these laws. class Applicative m => Monad (m :: * -> *) -- | Sequentially compose two actions, passing any value produced by the -- first as an argument to the second. (>>=) :: Monad m => m a -> (a -> m b) -> m b -- | Sequentially compose two actions, discarding any value produced by the -- first, like sequencing operators (such as the semicolon) in imperative -- languages. (>>) :: Monad m => m a -> m b -> m b -- | Inject a value into the monadic type. return :: Monad m => a -> m a -- | Fail with a message. This operation is not part of the mathematical -- definition of a monad, but is invoked on pattern-match failure in a -- do expression. -- -- As part of the MonadFail proposal (MFP), this function is moved to its -- own class MonadFail (see Control.Monad.Fail for more -- details). The definition here will be removed in a future release. fail :: Monad m => String -> m a -- | Sequentially compose two actions, passing any value produced by the -- first as an argument to the second. (>>=) :: Monad m => forall a b. m a -> (a -> m b) -> m b -- | Same as >>=, but with the arguments interchanged. (=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 =<< -- | Left-to-right Kleisli composition of monads. (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 >=> -- | Right-to-left Kleisli composition of monads. -- (>=>), with the arguments flipped. -- -- Note how this operator resembles function composition -- (.): -- --
-- (.) :: (b -> c) -> (a -> b) -> a -> c -- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c --(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c infixr 1 <=< -- | The join function is the conventional monad join operator. It -- is used to remove one level of monadic structure, projecting its bound -- argument into the outer level. join :: Monad m => m (m a) -> m a -- | The foldlM function is analogous to foldl, except that -- its result is encapsulated in a monad. -- --
-- foldlM f a1 [x1, x2, ..., xm] ---- -- == -- --
-- do -- a2 <- f a1 x1 -- a3 <- f a2 x2 -- ... -- f am xm --foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b -- | Like foldlM, but discards the result. foldlM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () -- | Monadic fold over the elements of a structure, associating to the -- right, i.e. from right to left. foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b -- | Like foldrM, but discards the result. foldrM_ :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m () -- | Strict version of <$>. (<$!>) :: Monad m => (a -> b) -> m a -> m b infixl 4 <$!> -- | Sequentially compose two actions, discarding any value produced by the -- first, like sequencing operators (such as the semicolon) in imperative -- languages. (>>) :: Monad m => forall a b. m a -> m b -> m b -- | Fail with a message. This operation is not part of the mathematical -- definition of a monad, but is invoked on pattern-match failure in a -- do expression. -- -- As part of the MonadFail proposal (MFP), this function is moved to its -- own class MonadFail (see Control.Monad.Fail for more -- details). The definition here will be removed in a future release. fail :: Monad m => forall a. String -> m a -- | Inject a value into the monadic type. return :: Monad m => forall a. a -> m a module Precursor.Control.Bifunctor -- | Formally, the class Bifunctor represents a bifunctor from -- Hask -> Hask. -- -- Intuitively it is a bifunctor where both the first and second -- arguments are covariant. -- -- You can define a Bifunctor by either defining bimap or -- by defining both first and second. -- -- If you supply bimap, you should ensure that: -- --
-- bimap id id ≡ id ---- -- If you supply first and second, ensure: -- --
-- first id ≡ id -- second id ≡ id ---- -- If you supply both, you should also ensure: -- --
-- bimap f g ≡ first f . second g ---- -- These ensure by parametricity: -- --
-- bimap (f . g) (h . i) ≡ bimap f h . bimap g i -- first (f . g) ≡ first f . first g -- second (f . g) ≡ second f . second g --class Bifunctor (p :: * -> * -> *) -- | Map over both arguments at the same time. -- --
-- bimap f g ≡ first f . second g --bimap :: Bifunctor p => (a -> b) -> (c -> d) -> p a c -> p b d -- | Map covariantly over the first argument. -- --
-- first f ≡ bimap f id --first :: Bifunctor p => (a -> b) -> p a c -> p b c -- | Map covariantly over the second argument. -- --
-- second ≡ bimap id --second :: Bifunctor p => (b -> c) -> p a b -> p a c -- | Map over both arguments at the same time. -- --
-- bimap f g ≡ first f . second g --bimap :: Bifunctor p => forall a b c d. (a -> b) -> (c -> d) -> p a c -> p b d -- | Map covariantly over the first argument. -- --
-- first f ≡ bimap f id --first :: Bifunctor p => forall a b c. (a -> b) -> p a c -> p b c -- | Map covariantly over the second argument. -- --
-- second ≡ bimap id --second :: Bifunctor p => forall b c a. (b -> c) -> p a b -> p a c module Precursor.Control.Applicative -- | A functor with application, providing operations to -- --
pure id <*> -- v = v
pure (.) <*> u -- <*> v <*> w = u <*> (v -- <*> w)
pure f <*> -- pure x = pure (f x)
u <*> pure y = -- pure ($ y) <*> u
-- f <$> ZipList xs1 <*> ... <*> ZipList xsn = ZipList (zipWithn f xs1 ... xsn) --newtype ZipList a :: * -> * ZipList :: [a] -> ZipList a [getZipList] :: ZipList a -> [a] -- | Lift a binary function to actions. liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c -- | A variant of <*> with the arguments reversed. (<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 <**> -- | forever act repeats the action infinitely. forever :: Applicative f => f a -> f b -- | Conditional execution of Applicative expressions. For example, -- --
-- when debug (putStrLn "Debugging") ---- -- will output the string Debugging if the Boolean value -- debug is True, and otherwise do nothing. when :: Applicative f => Bool -> f () -> f () -- | The reverse of when. unless :: Applicative f => Bool -> f () -> f () -- | replicateA n act performs the action n times, -- gathering the results. replicateA :: (Applicative f) => Int -> f a -> f [a] -- | Like replicateA, but discards the result. replicateA_ :: (Applicative f) => Int -> f a -> f () -- | This generalizes the list-based filter function. filterA :: Applicative f => (a -> f Bool) -> [a] -> f [a] module Precursor.Text.Text fromString :: IsString a => String -> a class IsText a where fromText = fromText' . toStrict fromText' = fromText . fromStrict readBytes = readBytes' . toStrict readBytes' = readBytes . fromStrict fromText :: IsText a => Text -> a fromText' :: IsText a => StrictText -> a readBytes' :: IsText a => StrictByteString -> Either UnicodeException a readBytes :: IsText a => ByteString -> Either UnicodeException a class IsText a => IsBytes a where fromBytes = fromBytes' . toStrict fromBytes' = fromBytes . fromStrict fromBytes :: IsBytes a => ByteString -> a fromBytes' :: IsBytes a => StrictByteString -> a data Text :: * -- | A space-efficient representation of a Word8 vector, supporting -- many efficient operations. -- -- A lazy ByteString contains 8-bit bytes, or by using the -- operations from Data.ByteString.Lazy.Char8 it can be -- interpreted as containing 8-bit characters. data ByteString :: * type StrictText = Text type StrictByteString = ByteString -- | O(1) Convert a character into a Text. Subject to fusion. -- Performs replacement on invalid scalar values. singleton :: Char -> Text -- | O(c) Convert a list of strict Texts into a lazy -- Text. fromChunks :: [Text] -> Text -- | O(n) Convert a lazy Text into a list of strict -- Texts. toChunks :: Text -> [Text] -- | O(n) Convert a string to folded case. Subject to fusion. -- -- This function is mainly useful for performing caseless (or case -- insensitive) string comparisons. -- -- A string x is a caseless match for a string y if and -- only if: -- --
-- toCaseFold x == toCaseFold y ---- -- The result string may be longer than the input string, and may differ -- from applying toLower to the input string. For instance, the -- Armenian small ligature men now (U+FB13) is case folded to the bigram -- men now (U+0574 U+0576), while the micro sign (U+00B5) is case folded -- to the Greek small letter letter mu (U+03BC) instead of itself. toCaseFold :: Text -> Text -- | O(n) Convert a string to lower case, using simple case -- conversion. Subject to fusion. -- -- The result string may be longer than the input string. For instance, -- the Latin capital letter I with dot above (U+0130) maps to the -- sequence Latin small letter i (U+0069) followed by combining dot above -- (U+0307). toLower :: Text -> Text -- | O(n) Convert a string to upper case, using simple case -- conversion. Subject to fusion. -- -- The result string may be longer than the input string. For instance, -- the German eszett (U+00DF) maps to the two-letter sequence SS. toUpper :: Text -> Text -- | O(n) Convert a string to title case, using simple case -- conversion. Subject to fusion. -- -- The first letter of the input is converted to title case, as is every -- subsequent letter that immediately follows a non-letter. Every letter -- that immediately follows another letter is converted to lower case. -- -- The result string may be longer than the input string. For example, -- the Latin small ligature fl (U+FB02) is converted to the sequence Latin -- capital letter F (U+0046) followed by Latin small letter l (U+006C). -- -- Note: this function does not take language or culture specific -- rules into account. For instance, in English, different style guides -- disagree on whether the book name "The Hill of the Red Fox" is -- correctly title cased—but this function will capitalize every -- word. toTitle :: Text -> Text -- | O(n) Breaks a Text up into a list of Texts at -- newline Chars. The resulting strings do not contain newlines. lines :: Text -> [Text] -- | O(n) Breaks a Text up into a list of words, delimited by -- Chars representing white space. words :: Text -> [Text] -- | O(n) Joins lines, after appending a terminating newline to -- each. unlines :: [Text] -> Text -- | O(n) Joins words using single space characters. unwords :: [Text] -> Text -- | O(n) The isPrefixOf function takes two Texts and -- returns True iff the first is a prefix of the second. Subject -- to fusion. isPrefixOf :: Text -> Text -> Bool -- | O(n) The isSuffixOf function takes two Texts and -- returns True iff the first is a suffix of the second. isSuffixOf :: Text -> Text -> Bool -- | O(n+m) The isInfixOf function takes two Texts and -- returns True iff the first is contained, wholly and intact, -- anywhere within the second. -- -- This function is strict in its first argument, and lazy in its second. -- -- In (unlikely) bad cases, this function's time complexity degrades -- towards O(n*m). isInfixOf :: Text -> Text -> Bool instance Precursor.Text.Text.IsText Data.Text.Internal.Lazy.Text instance Precursor.Text.Text.IsText Data.Text.Internal.Text instance Precursor.Text.Text.IsText Data.ByteString.Lazy.Internal.ByteString instance Precursor.Text.Text.IsText Data.ByteString.Internal.ByteString instance Precursor.Text.Text.IsBytes Data.ByteString.Lazy.Internal.ByteString instance Precursor.Text.Text.IsBytes Data.ByteString.Internal.ByteString module Precursor.Coerce -- | Coercible is a two-parameter class that has instances for -- types a and b if the compiler can infer that they -- have the same representation. This class does not have regular -- instances; instead they are created on-the-fly during type-checking. -- Trying to manually declare an instance of Coercible is an -- error. -- -- Nevertheless one can pretend that the following three kinds of -- instances exist. First, as a trivial base-case: -- --
-- instance a a ---- -- Furthermore, for every type constructor there is an instance that -- allows to coerce under the type constructor. For example, let -- D be a prototypical type constructor (data or -- newtype) with three type arguments, which have roles -- nominal, representational resp. phantom. -- Then there is an instance of the form -- --
-- instance Coercible b b' => Coercible (D a b c) (D a b' c') ---- -- Note that the nominal type arguments are equal, the -- representational type arguments can differ, but need to have -- a Coercible instance themself, and the phantom type -- arguments can be changed arbitrarily. -- -- The third kind of instance exists for every newtype NT = MkNT -- T and comes in two variants, namely -- --
-- instance Coercible a T => Coercible a NT ---- --
-- instance Coercible T b => Coercible NT b ---- -- This instance is only usable if the constructor MkNT is in -- scope. -- -- If, as a library author of a type constructor like Set a, you -- want to prevent a user of your module to write coerce :: Set T -- -> Set NT, you need to set the role of Set's type -- parameter to nominal, by writing -- --
-- type role Set nominal ---- -- For more details about this feature, please refer to Safe -- Coercions by Joachim Breitner, Richard A. Eisenberg, Simon Peyton -- Jones and Stephanie Weirich. class (~R#) k k a b => Coercible k (a :: k) (b :: k) -- | The function coerce allows you to safely convert between -- values of types that have the same representation with no run-time -- overhead. In the simplest case you can use it instead of a newtype -- constructor, to go from the newtype's concrete type to the abstract -- type. But it also works in more complicated settings, e.g. converting -- a list of newtypes to a list of concrete types. coerce :: Coercible * a b => a -> b -- | It may be better to use (#.) instead of -- (.) to avoid potential efficiency problems relating to -- #7542. The problem, in a nutshell: -- -- If N is a newtype constructor, then N x will always -- have the same representation as x (something similar applies -- for a newtype deconstructor). However, if f is a function, -- --
-- N . f = x -> N (f x) ---- -- This looks almost the same as f, but the eta expansion lifts -- it--the lhs could be _|_, but the rhs never is. This can lead -- to very inefficient code. Thus we steal a technique from Shachaf and -- Edward Kmett and adapt it to the current (rather clean) setting. -- Instead of using N . f, we use N .# -- f, which is just -- --
-- coerce f `asTypeOf' (N . f) ---- -- That is, we just *pretend* that f has the right type, and -- thanks to the safety of coerce, the type checker guarantees -- that nothing really goes wrong. We still have to be a bit careful, -- though: remember that #. completely ignores the *value* of its -- left operand. (#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a -> c) infixr 9 #. module Precursor.Algebra.Semiring -- | A Semiring is like the the combination of two Monoids. -- The first is called +; it has the identity element zero, -- and it is commutative. The second is called *; it has identity -- element one, and it must distribute over +. -- --
(a + b) + c = a + (b + -- c)
zero + a = a + zero = -- a
(a * b) * c = a * (b * -- c)
one * a = a * one = a
-- (a <> b) <> c = a <> (b <> c) ---- -- If a is also a Monoid we further require -- --
-- (<>) = mappend --(<>) :: Semigroup a => a -> a -> a -- | Reduce a non-empty list with <> -- -- The default definition should be sufficient, but this can be -- overridden for efficiency. sconcat :: Semigroup a => NonEmpty a -> a -- | An associative operation. -- --
-- (a <> b) <> c = a <> (b <> c) ---- -- If a is also a Monoid we further require -- --
-- (<>) = mappend --(<>) :: Semigroup a => a -> a -> a -- | Reduce a non-empty list with <> -- -- The default definition should be sufficient, but this can be -- overridden for efficiency. sconcat :: Semigroup a => NonEmpty a -> a -- | This is a valid definition of stimes for a Monoid. -- -- Unlike the default definition of stimes, it is defined for 0 -- and so it should be preferred where possible. stimesMonoid :: (Integral b, Monoid a) => b -> a -> a -- | This is a valid definition of stimes for an idempotent -- Semigroup. -- -- When x <> x = x, this definition should be preferred, -- because it works in O(1) rather than O(log n). stimesIdempotent :: Integral b => b -> a -> a -- | This is a valid definition of stimes for an idempotent -- Monoid. -- -- When mappend x x = x, this definition should be preferred, -- because it works in O(1) rather than O(log n) stimesIdempotentMonoid :: (Integral b, Monoid a) => b -> a -> a -- | Repeat a value n times. -- --
-- mtimesDefault n a = a <> a <> ... <> a -- using <> (n-1) times ---- -- Implemented using stimes and mempty. -- -- This is a suitable definition for an mtimes member of -- Monoid. mtimesDefault :: (Integral b, Monoid a) => b -> a -> a -- | Use Option (First a) to get the behavior of -- First from Data.Monoid. newtype First a :: * -> * First :: a -> First a [getFirst] :: First a -> a -- | Use Option (Last a) to get the behavior of -- Last from Data.Monoid newtype Last a :: * -> * Last :: a -> Last a [getLast] :: Last a -> a newtype Min a :: * -> * Min :: a -> Min a [getMin] :: Min a -> a newtype Max a :: * -> * Max :: a -> Max a [getMax] :: Max a -> a -- | Provide a Semigroup for an arbitrary Monoid. newtype WrappedMonoid m :: * -> * WrapMonoid :: m -> WrappedMonoid m [unwrapMonoid] :: WrappedMonoid m -> m module Precursor.Algebra.Ring -- | A Ring is a Semiring with an additive inverse, such -- that: -- -- class Semiring a => Ring a where (-) = (-) -- | A binary operation such that: -- -- (-) :: Ring a => a -> a -> a -- | A binary operation such that: -- -- (-) :: (Ring a, Num a) => a -> a -> a instance Precursor.Algebra.Ring.Ring GHC.Types.Int instance Precursor.Algebra.Ring.Ring GHC.Int.Int8 instance Precursor.Algebra.Ring.Ring GHC.Int.Int16 instance Precursor.Algebra.Ring.Ring GHC.Int.Int32 instance Precursor.Algebra.Ring.Ring GHC.Int.Int64 instance Precursor.Algebra.Ring.Ring GHC.Integer.Type.Integer instance Precursor.Algebra.Ring.Ring GHC.Types.Float instance Precursor.Algebra.Ring.Ring GHC.Types.Double module Precursor.Algebra.Ord -- | The Ord class is used for totally ordered datatypes. -- -- Instances of Ord can be derived for any user-defined datatype -- whose constituent types are in Ord. The declared order of the -- constructors in the data declaration determines the ordering in -- derived Ord instances. The Ordering datatype allows a -- single comparison to determine the precise ordering of two objects. -- -- Minimal complete definition: either compare or <=. -- Using compare can be more efficient for complex types. class Eq a => Ord a compare :: Ord a => a -> a -> Ordering (<) :: Ord a => a -> a -> Bool (<=) :: Ord a => a -> a -> Bool (>) :: Ord a => a -> a -> Bool (>=) :: Ord a => a -> a -> Bool max :: Ord a => a -> a -> a min :: Ord a => a -> a -> a compare :: Ord a => a -> a -> Ordering (<=) :: Ord a => a -> a -> Bool (>=) :: Ord a => a -> a -> Bool (<) :: Ord a => a -> a -> Bool (>) :: Ord a => a -> a -> Bool data Ordering :: * LT :: Ordering EQ :: Ordering GT :: Ordering -- | The Down type allows you to reverse sort order conveniently. A -- value of type Down a contains a value of type -- a (represented as Down a). If a has -- an Ord instance associated with it then comparing two -- values thus wrapped will give you the opposite of their normal sort -- order. This is particularly useful when sorting in generalised list -- comprehensions, as in: then sortWith by Down x -- -- Provides Show and Read instances (since: -- 4.7.0.0). newtype Down a :: * -> * Down :: a -> Down a -- |
-- comparing p x y = compare (p x) (p y) ---- -- Useful combinator for use in conjunction with the xxxBy -- family of functions from Data.List, for example: -- --
-- ... sortBy (comparing fst) ... --comparing :: Ord a => (b -> a) -> b -> b -> Ordering max :: Ord a => a -> a -> a min :: Ord a => a -> a -> a -- | An efficient implementation of sets. -- -- These modules are intended to be imported qualified, to avoid name -- clashes with Prelude functions, e.g. -- --
-- import Data.Set (Set) -- import qualified Data.Set as Set ---- -- The implementation of Set is based on size balanced -- binary trees (or trees of bounded balance) as described by: -- --
mappend mempty x = x
mappend x mempty = x
mappend x (mappend y z) = mappend (mappend x y) z
mconcat = foldr mappend mempty
-- >>> map (const 42) [0..3] -- [42,42,42,42] --const :: a -> b -> a -- | fix f is the least fixed point of the function -- f, i.e. the least defined x such that f x = -- x. fix :: (a -> a) -> a -- | flip f takes its (first) two arguments in the reverse -- order of f. flip :: (a -> b -> c) -> b -> a -> c -- | (*) `on` f = \x y -> f x * f y. -- -- Typical usage: sortBy (compare `on` -- fst). -- -- Algebraic properties: -- --
((*) `on` f) `on` g = (*) `on` (f . g)
flip on f . flip on g = flip on (g . -- f)
-- f $ g $ h x = f (g (h x)) ---- -- It is also useful in higher-order situations, such as map -- ($ 0) xs, or zipWith ($) fs xs. ($) :: (a -> b) -> a -> b infixr 0 $ -- | & is a reverse application operator. This provides -- notational convenience. Its precedence is one higher than that of the -- forward application operator $, which allows & to be -- nested in $. (&) :: a -> (a -> b) -> b infixl 1 & -- |
-- >>> applyN (2+) 2 0 -- 4 --applyN :: (a -> a) -> Int -> a -> a -- | Apply a function until it no longer changes its input. -- --
-- converge tail xs === [] --converge :: Eq a => (a -> a) -> a -> a -- | "Blackbird" operator. For example: -- --
-- aggregate f xs = sum (map f xs) ---- --
-- aggregate = sum .: map --(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d infixr 8 .: module Precursor.Data.List -- | Decompose a list into its head and tail. If the list is empty, returns -- Nothing. If the list is non-empty, returns Just (x, -- xs), where x is the head of the list and xs its -- tail. uncons :: [a] -> Maybe (a, [a]) -- | Return all the elements of a list except the last one. If the given -- list is empty, returns an empty list. -- --
-- >>> init [1,2,3] -- [1,2] -- -- >>> init [] -- [] --init :: [a] -> [a] -- | Extract the elements after the head of a list. If the given list is -- empty, returns an empty list. -- --
-- >>> tail [1,2,3] -- [2,3] -- -- >>> tail [] -- [] --tail :: [a] -> [a] -- | reverse xs returns the elements of xs in -- reverse order. xs must be finite. reverse :: [a] -> [a] -- | The intersperse function takes an element and a list and -- `intersperses' that element between the elements of the list. For -- example, -- --
-- intersperse ',' "abcde" == "a,b,c,d,e" --intersperse :: a -> [a] -> [a] -- | intercalate xs xss is equivalent to (concat -- (intersperse xs xss)). It inserts the list xs in -- between the lists in xss and concatenates the result. intercalate :: [a] -> [[a]] -> [a] -- | The transpose function transposes the rows and columns of its -- argument. For example, -- --
-- transpose [[1,2,3],[4,5,6]] == [[1,4],[2,5],[3,6]] ---- -- If some of the rows are shorter than the following rows, their -- elements are skipped: -- --
-- transpose [[10,11],[20],[],[30,31,32]] == [[10,20,30],[11,31],[32]] --transpose :: [[a]] -> [[a]] -- | The subsequences function returns the list of all subsequences -- of the argument. -- --
-- subsequences "abc" == ["","a","b","ab","c","ac","bc","abc"] --subsequences :: [a] -> [[a]] -- | The permutations function returns the list of all permutations -- of the argument. -- --
-- permutations "abc" == ["abc","bac","cba","bca","cab","acb"] --permutations :: [a] -> [[a]] -- | O(n*log n). The nub function removes duplicate elements -- from a list. In particular, it keeps only the first occurrence of each -- element. (The name nub means `essence'.) -- --
-- >>> nub [1,2,3,2,3,4,1,2,5,2,3] -- [1,2,3,4,5] -- -- >>> take 5 (nub [1..]) -- [1,2,3,4,5] -- -- >>> take 5 (nub [10,9..]) -- [10,9,8,7,6] --nub :: Ord a => [a] -> [a] -- | The fromList function constructs the structure l from -- the given list of Item l fromList :: IsList l => [Item l] -> l -- | scanl is similar to foldl, but returns a list of -- successive reduced values from the left: -- --
-- scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...] ---- -- Note that -- --
-- last (scanl f z xs) == foldl f z xs. --scanl :: (b -> a -> b) -> b -> [a] -> [b] -- | A strictly accumulating version of scanl scanl' :: (b -> a -> b) -> b -> [a] -> [b] -- | scanl1 is a variant of scanl that has no starting value -- argument: -- --
-- scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...] --scanl1 :: (a -> a -> a) -> [a] -> [a] -- | scanr is the right-to-left dual of scanl. Note that -- --
-- head (scanr f z xs) == foldr f z xs. --scanr :: (a -> b -> b) -> b -> [a] -> [b] -- | scanr1 is a variant of scanr that has no starting value -- argument. scanr1 :: (a -> a -> a) -> [a] -> [a] -- | iterate f x returns an infinite list of repeated -- applications of f to x: -- --
-- iterate f x == [x, f x, f (f x), ...] --iterate :: (a -> a) -> a -> [a] -- | repeat x is an infinite list, with x the -- value of every element. repeat :: a -> [a] -- | replicate n x is a list of length n with -- x the value of every element. It is an instance of the more -- general genericReplicate, in which n may be of any -- integral type. replicate :: Int -> a -> [a] -- | cycle ties a finite list into a circular one, or equivalently, -- the infinite repetition of the original list. It is the identity on -- infinite lists. cycle :: [a] -> [a] -- | The unfoldr function is a `dual' to foldr: while -- foldr reduces a list to a summary value, unfoldr builds -- a list from a seed value. The function takes the element and returns -- Nothing if it is done producing the list or returns Just -- (a,b), in which case, a is a prepended to the list -- and b is used as the next element in a recursive call. For -- example, -- --
-- iterate f == unfoldr (\x -> Just (x, f x)) ---- -- In some cases, unfoldr can undo a foldr operation: -- --
-- unfoldr f' (foldr f z xs) == xs ---- -- if the following holds: -- --
-- f' (f x y) = Just (x,y) -- f' z = Nothing ---- -- A simple use of unfoldr: -- --
-- unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10 -- [10,9,8,7,6,5,4,3,2,1] --unfoldr :: (b -> Maybe (a, b)) -> b -> [a] -- | unfoldl is the dual of foldl, similar to unfoldr. -- It can be quite useful as a kind of lightweight state-thing: -- --
-- >>> let toDigs b = unfoldl (ensure (>0) >-> flip divMod b) -- -- >>> toDigs 10 123 -- [1,2,3] -- -- >>> toDigs 2 5 -- [1,0,1] --unfoldl :: (b -> Maybe (b, a)) -> b -> [a] -- | take n, applied to a list xs, returns the -- prefix of xs of length n, or xs itself if -- n > length xs: -- --
-- take 5 "Hello World!" == "Hello" -- take 3 [1,2,3,4,5] == [1,2,3] -- take 3 [1,2] == [1,2] -- take 3 [] == [] -- take (-1) [1,2] == [] -- take 0 [1,2] == [] ---- -- It is an instance of the more general genericTake, in which -- n may be of any integral type. take :: Int -> [a] -> [a] -- | drop n xs returns the suffix of xs after the -- first n elements, or [] if n > length -- xs: -- --
-- drop 6 "Hello World!" == "World!" -- drop 3 [1,2,3,4,5] == [4,5] -- drop 3 [1,2] == [] -- drop 3 [] == [] -- drop (-1) [1,2] == [1,2] -- drop 0 [1,2] == [1,2] ---- -- It is an instance of the more general genericDrop, in which -- n may be of any integral type. drop :: Int -> [a] -> [a] -- | splitAt n xs returns a tuple where first element is -- xs prefix of length n and second element is the -- remainder of the list: -- --
-- splitAt 6 "Hello World!" == ("Hello ","World!")
-- splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5])
-- splitAt 1 [1,2,3] == ([1],[2,3])
-- splitAt 3 [1,2,3] == ([1,2,3],[])
-- splitAt 4 [1,2,3] == ([1,2,3],[])
-- splitAt 0 [1,2,3] == ([],[1,2,3])
-- splitAt (-1) [1,2,3] == ([],[1,2,3])
--
--
-- It is equivalent to (take n xs, drop n xs) when
-- n is not _|_ (splitAt _|_ xs = _|_).
-- splitAt is an instance of the more general
-- genericSplitAt, in which n may be of any integral
-- type.
splitAt :: Int -> [a] -> ([a], [a])
-- | takeWhile, applied to a predicate p and a list
-- xs, returns the longest prefix (possibly empty) of
-- xs of elements that satisfy p:
--
-- -- takeWhile (< 3) [1,2,3,4,1,2,3,4] == [1,2] -- takeWhile (< 9) [1,2,3] == [1,2,3] -- takeWhile (< 0) [1,2,3] == [] --takeWhile :: (a -> Bool) -> [a] -> [a] -- | dropWhile p xs returns the suffix remaining after -- takeWhile p xs: -- --
-- dropWhile (< 3) [1,2,3,4,5,1,2,3] == [3,4,5,1,2,3] -- dropWhile (< 9) [1,2,3] == [] -- dropWhile (< 0) [1,2,3] == [1,2,3] --dropWhile :: (a -> Bool) -> [a] -> [a] -- | The group function takes a list and returns a list of lists -- such that the concatenation of the result is equal to the argument. -- Moreover, each sublist in the result contains only equal elements. For -- example, -- --
-- group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"] ---- -- It is a special case of groupBy, which allows the programmer to -- supply their own equality test. group :: Eq a => [a] -> [[a]] -- | The inits function returns all initial segments of the -- argument, shortest first. For example, -- --
-- inits "abc" == ["","a","ab","abc"] ---- -- Note that inits has the following strictness property: -- inits (xs ++ _|_) = inits xs ++ _|_ -- -- In particular, inits _|_ = [] : _|_ inits :: [a] -> [[a]] -- | The tails function returns all final segments of the argument, -- longest first. For example, -- --
-- tails "abc" == ["abc", "bc", "c",""] ---- -- Note that tails has the following strictness property: -- tails _|_ = _|_ : _|_ tails :: [a] -> [[a]] -- | filter, applied to a predicate and a list, returns the list of -- those elements that satisfy the predicate; i.e., -- --
-- filter p xs = [ x | x <- xs, p x] --filter :: (a -> Bool) -> [a] -> [a] -- | The partition function takes a predicate a list and returns the -- pair of lists of elements which do and do not satisfy the predicate, -- respectively; i.e., -- --
-- partition p xs == (filter p xs, filter (not . p) xs) --partition :: (a -> Bool) -> [a] -> ([a], [a]) -- | zip takes two lists and returns a list of corresponding pairs. -- If one input list is short, excess elements of the longer list are -- discarded. -- -- zip is right-lazy: -- --
-- zip [] _|_ = [] --zip :: [a] -> [b] -> [(a, b)] -- | zipWith generalises zip by zipping with the function -- given as the first argument, instead of a tupling function. For -- example, zipWith (+) is applied to two lists to -- produce the list of corresponding sums. -- -- zipWith is right-lazy: -- --
-- zipWith f [] _|_ = [] --zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] -- | unzip transforms a list of pairs into a list of first -- components and a list of second components. unzip :: [(a, b)] -> ([a], [b]) -- | zip3 takes three lists and returns a list of triples, analogous -- to zip. zip3 :: [a] -> [b] -> [c] -> [(a, b, c)] -- | The zipWith3 function takes a function which combines three -- elements, as well as three lists and returns a list of their -- point-wise combination, analogous to zipWith. zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d] -- | The unzip3 function takes a list of triples and returns three -- lists, analogous to unzip. unzip3 :: [(a, b, c)] -> ([a], [b], [c]) -- | The sort function implements a stable sorting algorithm. It is -- a special case of sortBy, which allows the programmer to supply -- their own comparison function. sort :: Ord a => [a] -> [a] -- | Sort a list by comparing the results of a key function applied to each -- element. sortOn f is equivalent to sortBy (comparing -- f), but has the performance advantage of only evaluating -- f once for each element in the input list. This is called the -- decorate-sort-undecorate paradigm, or Schwartzian transform. sortOn :: Ord b => (a -> b) -> [a] -> [a] -- | The groupBy function is the non-overloaded version of -- group. groupBy :: (a -> a -> Bool) -> [a] -> [[a]] -- | The sortBy function is the non-overloaded version of -- sort. sortBy :: (a -> a -> Ordering) -> [a] -> [a] module Precursor.System.IO -- | A value of type IO a is a computation which, when -- performed, does some I/O before returning a value of type a. -- -- There is really only one way to "perform" an I/O action: bind it to -- Main.main in your program. When your program is run, the I/O -- will be performed. It isn't possible to perform I/O from an arbitrary -- function, unless that function is itself in the IO monad and -- called at some point, directly or indirectly, from Main.main. -- -- IO is a monad, so IO actions can be combined using -- either the do-notation or the >> and >>= -- operations from the Monad class. data IO a :: * -> * -- | Monads in which IO computations may be embedded. Any monad -- built by applying a sequence of monad transformers to the IO -- monad will be an instance of this class. -- -- Instances should satisfy the following laws, which state that -- liftIO is a transformer of monads: -- -- class Monad m => MonadIO (m :: * -> *) -- | Lift a computation from the IO monad. liftIO :: MonadIO m => IO a -> m a -- | Lift a computation from the IO monad. liftIO :: MonadIO m => forall a. IO a -> m a -- | File and directory names are values of type String, whose -- precise meaning is operating system dependent. Files can be opened, -- yielding a handle which can then be used to operate on the contents of -- that file. type FilePath = String -- | Read a file and return its contents as a string. The file is read -- lazily, as with getContents. readFile :: MonadIO m => FilePath -> m Text -- | Write a string to a file. The file is truncated to zero length before -- writing begins. writeFile :: MonadIO m => FilePath -> Text -> m () -- | Write a string the end of a file. appendFile :: MonadIO m => FilePath -> Text -> m () -- | The interact function takes a function of type Text -> -- Text as its argument. The entire input from the standard input -- device is passed (lazily) to this function as its argument, and the -- resulting string is output on the standard output device. interact :: MonadIO m => (Text -> Text) -> m () -- | Lazily read all user input on stdin as a single string. getContents :: MonadIO m => m Text -- | Read a single line of user input from stdin. getLine :: MonadIO m => m Text -- | Write a string to stdout. putStr :: MonadIO m => Text -> m () -- | Write a string to stdout, followed by a newline. putStrLn :: MonadIO m => Text -> m () module Precursor.Debug -- | A special case of error. It is expected that compilers will -- recognize this and insert error messages which are more appropriate to -- the context in which undefined appears. undefined :: HasCallStack => a -- | Used for tracing a message along with a pure value. For debugging -- purposes only. -- | Warning: trace remains in code trace :: Text -> b -> b -- | Prints a value to stdout when it's evaluated. For debugging purposes -- only. -- | Warning: traceShow remains in code traceShow :: TextShow a => a -> a -- | Used to fill in holes in code for later implementation. -- | Warning: notImplemented remains in code notImplemented :: a module Precursor.Structure.Foldable -- | Data structures that can be folded. -- -- For example, given a data type -- --
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) ---- -- a suitable instance would be -- --
-- instance Foldable Tree where -- foldMap f Empty = mempty -- foldMap f (Leaf x) = f x -- foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r ---- -- This is suitable even for abstract types, as the monoid is assumed to -- satisfy the monoid laws. Alternatively, one could define -- foldr: -- --
-- instance Foldable Tree where -- foldr f z Empty = z -- foldr f z (Leaf x) = f x z -- foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l ---- -- Foldable instances are expected to satisfy the following -- laws: -- --
-- foldr f z t = appEndo (foldMap (Endo . f) t ) z ---- --
-- foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z ---- --
-- fold = foldMap id ---- -- sum, product, maximum, and minimum -- should all be essentially equivalent to foldMap forms, such -- as -- --
-- sum = getSum . foldMap Sum ---- -- but may be less defined. -- -- If the type is also a Functor instance, it should satisfy -- --
-- foldMap f = fold . fmap f ---- -- which implies that -- --
-- foldMap f . fmap g = foldMap (f . g) --class Foldable (t :: * -> *) -- | Combine the elements of a structure using a monoid. fold :: (Foldable t, Monoid m) => t m -> m -- | Map each element of the structure to a monoid, and combine the -- results. foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m -- | Right-associative fold of a structure. -- -- In the case of lists, foldr, when applied to a binary operator, -- a starting value (typically the right-identity of the operator), and a -- list, reduces the list using the binary operator, from right to left: -- --
-- foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...) ---- -- Note that, since the head of the resulting expression is produced by -- an application of the operator to the first element of the list, -- foldr can produce a terminating expression from an infinite -- list. -- -- For a general Foldable structure this should be semantically -- identical to, -- --
-- foldr f z = foldr f z . toList --foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b -- | Right-associative fold of a structure, but with strict application of -- the operator. foldr' :: Foldable t => (a -> b -> b) -> b -> t a -> b -- | List of elements of a structure, from left to right. toList :: Foldable t => t a -> [a] -- | Test whether the structure is empty. The default implementation is -- optimized for structures that are similar to cons-lists, because there -- is no general way to do better. null :: Foldable t => t a -> Bool -- | Returns the size/length of a finite structure as an Int. The -- default implementation is optimized for structures that are similar to -- cons-lists, because there is no general way to do better. length :: Foldable t => t a -> Int -- | Does the element occur in the structure? elem :: (Foldable t, Eq a) => a -> t a -> Bool -- | Combine the elements of a structure using a monoid. fold :: Foldable t => forall m. Monoid m => t m -> m -- | Map each element of the structure to a monoid, and combine the -- results. foldMap :: Foldable t => forall m a. Monoid m => (a -> m) -> t a -> m -- | Right-associative fold of a structure. -- -- In the case of lists, foldr, when applied to a binary operator, -- a starting value (typically the right-identity of the operator), and a -- list, reduces the list using the binary operator, from right to left: -- --
-- foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...) ---- -- Note that, since the head of the resulting expression is produced by -- an application of the operator to the first element of the list, -- foldr can produce a terminating expression from an infinite -- list. -- -- For a general Foldable structure this should be semantically -- identical to, -- --
-- foldr f z = foldr f z . toList --foldr :: Foldable t => forall a b. (a -> b -> b) -> b -> t a -> b -- | Right-associative fold of a structure, but with strict application of -- the operator. foldr' :: Foldable t => forall a b. (a -> b -> b) -> b -> t a -> b -- | Left-associative fold of a structure. -- -- In the case of lists, foldl, when applied to a binary operator, -- a starting value (typically the left-identity of the operator), and a -- list, reduces the list using the binary operator, from left to right: -- --
-- foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn ---- -- Note that to produce the outermost application of the operator the -- entire input list must be traversed. This means that foldl will -- diverge if given an infinite list. -- -- This version is strict, in contrast to Prelude's foldl. -- -- This ensures that each step of the fold is forced to weak head normal -- form before being applied, avoiding the collection of thunks that -- would otherwise occur. This is often what you want to strictly reduce -- a finite list to a single, monolithic result (e.g. length). -- -- For a lazy version, use foldlLazy. -- -- For a general Foldable structure this should be semantically -- identical to, -- --
-- foldl f z = foldl f z . toList --foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b -- | Left-associative fold of a structure but with lazy application of the -- operator. -- -- Note that if you want an efficient left-fold, you probably want to use -- foldl instead of foldlLazy. The reason for this is that -- latter does not force the "inner" results (e.g. z f -- x1 in the above example) before applying them to the operator -- (e.g. to (f x2)). This results in a thunk chain -- O(n) elements long, which then must be evaluated from the -- outside-in. -- -- For a general Foldable structure this should be semantically -- identical to, -- --
-- foldlLazy f z = foldl f z . toList --foldlLazy :: Foldable t => (b -> a -> b) -> b -> t a -> b -- | A variant of foldl that has no base case, and returns -- Nothing for empty structures. -- --
-- foldl1 f = foldl1 f . toList --foldl1 :: Foldable t => (a -> a -> a) -> t a -> Maybe a -- | A variant of foldr that has no base case, and returns -- Nothing for empty structures. -- --
-- foldr1 f = foldr1 f . toList --foldr1 :: Foldable t => (a -> a -> a) -> t a -> Maybe a -- | List of elements of a structure, from left to right. toList :: Foldable t => forall a. t a -> [a] -- | Test whether the structure is empty. The default implementation is -- optimized for structures that are similar to cons-lists, because there -- is no general way to do better. null :: Foldable t => forall a. t a -> Bool -- | Returns the size/length of a finite structure as an Int. The -- default implementation is optimized for structures that are similar to -- cons-lists, because there is no general way to do better. length :: Foldable t => forall a. t a -> Int -- | Does the element occur in the structure? elem :: Foldable t => forall a. Eq a => a -> t a -> Bool -- | The least element of a structure. Returns Nothing on empty -- structures. -- --
-- >>> minimum [1,2,3] -- Just 1 -- -- >>> minimum [] -- Nothing --minimum :: (Ord a, Foldable t) => t a -> Maybe a -- | The largest element of a structure. Returns Nothing on empty -- structures. -- --
-- >>> maximum [1,2,3] -- Just 3 -- -- >>> maximum [] -- Nothing --maximum :: (Ord a, Foldable t) => t a -> Maybe a -- | The sum function computes the sum of the numbers of a -- structure. -- --
-- sum (xs :: [Integer]) === foldl (+) 0 xs --sum :: (Semiring a, Foldable t) => t a -> a -- | The product function computes the product of the numbers of a -- structure. -- --
-- product (xs :: [Integer]) === foldl (*) 1 xs --product :: (Semiring a, Foldable t) => t a -> a -- | The first element of a structure, or Nothing if it's empty. -- --
-- >>> head [1,2,3] -- Just 1 -- -- >>> head [] -- Nothing ---- --
-- head xs === last (reverse xs) --head :: Foldable t => t a -> Maybe a -- | The last element of a structure, or Nothing if it's empty. -- --
-- >>> last [1,2,3] -- Just 3 -- -- >>> last [] -- Nothing ---- --
-- last xs === head (reverse xs) --last :: Foldable t => t a -> Maybe a -- | Index (subscript) operator, starting from 0. Returns Nothing -- for out-of-range indices. -- --
-- >>> [1,2,3] !! 0 -- Just 1 -- -- >>> [1,2,3] !! (-1) -- Nothing -- -- >>> [1,2,3] !! 3 -- Nothing --(!!) :: Foldable f => f a -> Int -> Maybe a infixl 9 !! -- | The concatenation of all the elements of a container of lists. concat :: Foldable t => t [a] -> [a] -- | Map a function over all the elements of a container and concatenate -- the resulting lists. concatMap :: Foldable t => (a -> [b]) -> t a -> [b] -- | and returns the conjunction of a container of Bools. For the -- result to be True, the container must be finite; False, -- however, results from a False value finitely far from the left -- end. and :: Foldable t => t Bool -> Bool -- | or returns the disjunction of a container of Bools. For the -- result to be False, the container must be finite; True, -- however, results from a True value finitely far from the left -- end. or :: Foldable t => t Bool -> Bool -- | Determines whether any element of the structure satisfies the -- predicate. any :: Foldable t => (a -> Bool) -> t a -> Bool -- | Determines whether all elements of the structure satisfy the -- predicate. all :: Foldable t => (a -> Bool) -> t a -> Bool -- | The largest element of a structure with respect to the given -- comparison function. Returns Nothing on an empty input. -- --
-- maximum (xs :: [Int]) === maximumBy compare xs --maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a -- | The least element of a structure with respect to the given comparison -- function. Returns Nothing on an empty input. -- --
-- minimum (xs :: [Int]) === minimumBy compare xs --minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a -- | Fold over two Foldables at once. -- --
-- zip xs ys === foldr2 (\x y zs -> (x,y) : zs) [] xs ys --foldr2 :: (Foldable f, Foldable g) => (a -> b -> c -> c) -> c -> f a -> g b -> c -- | Fold over three Foldables at once. -- --
-- zip3 ws xs ys === foldr3 (\w x y zs -> (w,x,y) : zs) [] ws xs ys --foldr3 :: (Foldable f, Foldable g, Foldable h) => (a -> b -> c -> d -> d) -> d -> f a -> g b -> h c -> d -- | notElem is the negation of elem. notElem :: (Foldable t, Eq a) => a -> t a -> Bool infix 4 `notElem` -- | The find function takes a predicate and a structure and returns -- the leftmost element of the structure matching the predicate, or -- Nothing if there is no such element. find :: Foldable t => (a -> Bool) -> t a -> Maybe a instance GHC.Classes.Ord a => GHC.Base.Monoid (Precursor.Structure.Foldable.Max a) instance GHC.Classes.Ord a => GHC.Base.Monoid (Precursor.Structure.Foldable.Min a) module Precursor.Control.Alternative -- | A monoid on applicative functors. -- -- If defined, some and many should be the least solutions -- of the equations: -- -- class Applicative f => Alternative (f :: * -> *) -- | The identity of <|> empty :: Alternative f => f a -- | An associative binary operation (<|>) :: Alternative f => f a -> f a -> f a -- | One or more. some :: Alternative f => f a -> f [a] -- | Zero or more. many :: Alternative f => f a -> f [a] -- | An associative binary operation (<|>) :: Alternative f => forall a. f a -> f a -> f a -- | The identity of <|> empty :: Alternative f => forall a. f a -- | One or more. some :: Alternative f => forall a. f a -> f [a] -- | Zero or more. many :: Alternative f => forall a. f a -> f [a] -- | One or none. optional :: Alternative f => f a -> f (Maybe a) -- | A generalized version of filter, which works on anything -- which is both a Monad and Alternative. -- --
-- \(Blind p) xs -> filter p xs === afilter p xs --afilter :: (Monad m, Alternative m) => (a -> Bool) -> m a -> m a -- | The sum of a collection of actions, generalizing concat. asum :: (Foldable t, Alternative f) => t (f a) -> f a -- | guard b is pure () if b is -- True, and empty if b is False. guard :: Alternative f => Bool -> f () -- | ensure allows you to attach a condition to something ensure :: (Alternative f) => (a -> Bool) -> a -> f a -- | eitherA is especially useful for parsers. eitherA :: Alternative f => f a -> f b -> f (Either a b) -- | Convert any Foldable to an Alternative toAlt :: (Alternative f, Foldable t) => t a -> f a -- | Map a function over a monad, and concat the results. This is a -- generalized form of the function mapMaybe. mapAlt :: (Monad m, Alternative m, Foldable f) => (a -> f b) -> m a -> m b module Precursor.Structure.Traversable -- | Functors representing data structures that can be traversed from left -- to right. -- -- A definition of traverse must satisfy the following laws: -- --
-- t :: (Applicative f, Applicative g) => f a -> g a ---- -- preserving the Applicative operations, i.e. -- -- -- -- and the identity functor Identity and composition of functors -- Compose are defined as -- --
-- newtype Identity a = Identity a -- -- instance Functor Identity where -- fmap f (Identity x) = Identity (f x) -- -- instance Applicative Identity where -- pure x = Identity x -- Identity f <*> Identity x = Identity (f x) -- -- newtype Compose f g a = Compose (f (g a)) -- -- instance (Functor f, Functor g) => Functor (Compose f g) where -- fmap f (Compose x) = Compose (fmap (fmap f) x) -- -- instance (Applicative f, Applicative g) => Applicative (Compose f g) where -- pure x = Compose (pure (pure x)) -- Compose f <*> Compose x = Compose ((<*>) <$> f <*> x) ---- -- (The naturality law is implied by parametricity.) -- -- Instances are similar to Functor, e.g. given a data type -- --
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) ---- -- a suitable instance would be -- --
-- instance Traversable Tree where -- traverse f Empty = pure Empty -- traverse f (Leaf x) = Leaf <$> f x -- traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r ---- -- This is suitable even for abstract types, as the laws for -- <*> imply a form of associativity. -- -- The superclass instances should satisfy the following: -- --
-- >>> for_ [1..4] print -- 1 -- 2 -- 3 -- 4 --for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () -- | The mapAccumL function behaves like a combination of -- fmap and foldl; it applies a function to each element -- of a structure, passing an accumulating parameter from left to right, -- and returning a final value of this accumulator together with the new -- structure. mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) -- | The mapAccumR function behaves like a combination of -- fmap and foldr; it applies a function to each element -- of a structure, passing an accumulating parameter from right to left, -- and returning a final value of this accumulator together with the new -- structure. mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) -- | Zip two structures together, preserving the shape of the left. -- --
-- zipInto const (xs :: [Int]) (ys :: [Int]) === xs --zipInto :: (Traversable t, Foldable f) => (a -> Maybe b -> c) -> t a -> f b -> t c instance GHC.Base.Functor (Precursor.Structure.Traversable.State s) instance GHC.Base.Applicative (Precursor.Structure.Traversable.State s) module Precursor.Algebra.Enum -- | Class Enum defines operations on sequentially ordered types. -- -- The enumFrom... methods are used in Haskell's translation of -- arithmetic sequences. -- -- Instances of Enum may be derived for any enumeration type -- (types whose constructors have no fields). The nullary constructors -- are assumed to be numbered left-to-right by fromEnum from -- 0 through n-1. See Chapter 10 of the Haskell -- Report for more details. -- -- For any type that is an instance of class Bounded as well as -- Enum, the following should hold: -- --
-- enumFrom x = enumFromTo x maxBound -- enumFromThen x y = enumFromThenTo x y bound -- where -- bound | fromEnum y >= fromEnum x = maxBound -- | otherwise = minBound --class Enum a -- | the successor of a value. For numeric types, succ adds 1. succ :: Enum a => a -> a -- | the predecessor of a value. For numeric types, pred subtracts -- 1. pred :: Enum a => a -> a -- | Convert from an Int. toEnum :: Enum a => Int -> a -- | Convert to an Int. It is implementation-dependent what -- fromEnum returns when applied to a value that is too large to -- fit in an Int. fromEnum :: Enum a => a -> Int -- | Used in Haskell's translation of [n..]. enumFrom :: Enum a => a -> [a] -- | Used in Haskell's translation of [n,n'..]. enumFromThen :: Enum a => a -> a -> [a] -- | Used in Haskell's translation of [n..m]. enumFromTo :: Enum a => a -> a -> [a] -- | Used in Haskell's translation of [n,n'..m]. enumFromThenTo :: Enum a => a -> a -> a -> [a] -- | the successor of a value. For numeric types, succ adds 1. succ :: Enum a => a -> a -- | the predecessor of a value. For numeric types, pred subtracts -- 1. pred :: Enum a => a -> a -- | Convert from an Int. toEnum :: Enum a => Int -> a -- | Convert to an Int. It is implementation-dependent what -- fromEnum returns when applied to a value that is too large to -- fit in an Int. fromEnum :: Enum a => a -> Int -- | Used in Haskell's translation of [n..]. enumFrom :: Enum a => a -> [a] -- | Used in Haskell's translation of [n,n'..]. enumFromThen :: Enum a => a -> a -> [a] -- | Used in Haskell's translation of [n..m]. enumFromTo :: Enum a => a -> a -> [a] -- | Used in Haskell's translation of [n,n'..m]. enumFromThenTo :: Enum a => a -> a -> a -> [a] -- | The Bounded class is used to name the upper and lower limits of -- a type. Ord is not a superclass of Bounded since types -- that are not totally ordered may also have upper and lower bounds. -- -- The Bounded class may be derived for any enumeration type; -- minBound is the first constructor listed in the data -- declaration and maxBound is the last. Bounded may also -- be derived for single-constructor datatypes whose constituent types -- are in Bounded. class Bounded a minBound :: Bounded a => a maxBound :: Bounded a => a -- | Features -- --