-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Access IPFS locally and remotely -- -- Interact with the IPFS network by shelling out to a local IPFS node or -- communicating via the HTTP interface of a remote IPFS node. @package ipfs @version 1.0.0 -- | Application configuration and top-level RIO helpers module Network.IPFS.Config -- | Get a value from the reader config -- --
-- >>> data Field = Field Text
--
-- >>> data Cfg = Cfg Field
--
-- >>>
--
-- >>> instance Has Field Cfg where hasLens = \f (Cfg field) -> Cfg <$> f field
--
-- >>>
--
-- >>> :{
--
-- >>> runRIO (Cfg $ Field "hello world") do
--
-- >>> Field txt <- get
--
-- >>> return txt
--
-- >>> :}
-- "hello world"
--
get :: (MonadReader cfg m, Has a cfg) => m a
module Network.IPFS.Ignored.Types
type Ignored = [Pattern]
module Network.IPFS.Internal.Constraint
type MonadRIO cfg m = (MonadIO m, MonadReader cfg m)
module Network.IPFS.Internal.Orphanage.Utf8Builder
instance System.Log.FastLogger.LogStr.ToLogStr RIO.Prelude.Display.Utf8Builder
-- | UTF8 text helpers
module Network.IPFS.Internal.UTF8
class Textable a
encode :: Textable a => a -> Either UnicodeException Text
stripN :: Natural -> Text -> Text
textToLazyBS :: Text -> ByteString
textShow :: Show a => a -> Text
instance Network.IPFS.Internal.UTF8.Textable Data.ByteString.Internal.ByteString
instance Network.IPFS.Internal.UTF8.Textable Data.ByteString.Lazy.Internal.ByteString
module Network.IPFS.Peer.Types
newtype Peer
Peer :: Text -> Peer
[$sel:peer:Peer] :: Peer -> Text
instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.Peer.Types.Peer
instance Data.String.IsString Network.IPFS.Peer.Types.Peer
instance RIO.Prelude.Display.Display Network.IPFS.Peer.Types.Peer
instance GHC.Show.Show Network.IPFS.Peer.Types.Peer
instance GHC.Classes.Eq Network.IPFS.Peer.Types.Peer
instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.Peer.Types.Peer
instance Data.Swagger.Internal.Schema.ToSchema Network.IPFS.Peer.Types.Peer
instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.PlainText Network.IPFS.Peer.Types.Peer
instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.OctetStream Network.IPFS.Peer.Types.Peer
-- | A custom Prelude-like module for this project
module Network.IPFS.Prelude
-- | Perform a safe head of a Fold or Traversal or
-- retrieve Just the result from a Getter or Lens.
--
-- When using a Traversal as a partial Lens, or a
-- Fold as a partial Getter this can be a convenient way to
-- extract the optional value.
--
-- Note: if you get stack overflows due to this, you may want to use
-- firstOf instead, which can deal more gracefully with heavily
-- left-biased trees. This is because ^? works by using the
-- First monoid, which can occasionally cause space leaks.
--
-- -- >>> Left 4 ^?_Left -- Just 4 ---- --
-- >>> Right 4 ^?_Left -- Nothing ---- --
-- >>> "world" ^? ix 3 -- Just 'l' ---- --
-- >>> "world" ^? ix 20 -- Nothing ---- -- This operator works as an infix version of preview. -- --
-- (^?) ≡ flip preview ---- -- It may be helpful to think of ^? as having one of the following -- more specialized types: -- --
-- (^?) :: s -> Getter s a -> Maybe a -- (^?) :: s -> Fold s a -> Maybe a -- (^?) :: s -> Lens' s a -> Maybe a -- (^?) :: s -> Iso' s a -> Maybe a -- (^?) :: s -> Traversal' s a -> Maybe a --(^?) :: () => s -> Getting (First a) s a -> Maybe a infixl 8 ^? -- | Set the target of a Lens, Traversal or Setter to -- Just a value. -- --
-- l ?~ t ≡ set l (Just t) ---- --
-- >>> Nothing & id ?~ a -- Just a ---- --
-- >>> Map.empty & at 3 ?~ x -- fromList [(3,x)] ---- -- ?~ can be used type-changily: -- --
-- >>> ('a', ('b', 'c')) & _2.both ?~ 'x'
-- ('a',(Just 'x',Just 'x'))
--
--
-- -- (?~) :: Setter s t a (Maybe b) -> b -> s -> t -- (?~) :: Iso s t a (Maybe b) -> b -> s -> t -- (?~) :: Lens s t a (Maybe b) -> b -> s -> t -- (?~) :: Traversal s t a (Maybe b) -> b -> s -> t --(?~) :: () => ASetter s t a (Maybe b) -> b -> s -> t infixr 4 ?~ -- | Replace the target of a Lens or all of the targets of a -- Setter or Traversal with a constant value. -- -- This is an infix version of set, provided for consistency with -- (.=). -- --
-- f <$ a ≡ mapped .~ f $ a ---- --
-- >>> (a,b,c,d) & _4 .~ e -- (a,b,c,e) ---- --
-- >>> (42,"world") & _1 .~ "hello"
-- ("hello","world")
--
--
-- -- >>> (a,b) & both .~ c -- (c,c) ---- --
-- (.~) :: Setter s t a b -> b -> s -> t -- (.~) :: Iso s t a b -> b -> s -> t -- (.~) :: Lens s t a b -> b -> s -> t -- (.~) :: Traversal s t a b -> b -> s -> t --(.~) :: () => ASetter s t a b -> b -> s -> t infixr 4 .~ -- | Modifies the target of a Lens or all of the targets of a -- Setter or Traversal with a user supplied function. -- -- This is an infix version of over. -- --
-- fmap f ≡ mapped %~ f -- fmapDefault f ≡ traverse %~ f ---- --
-- >>> (a,b,c) & _3 %~ f -- (a,b,f c) ---- --
-- >>> (a,b) & both %~ f -- (f a,f b) ---- --
-- >>> _2 %~ length $ (1,"hello") -- (1,5) ---- --
-- >>> traverse %~ f $ [a,b,c] -- [f a,f b,f c] ---- --
-- >>> traverse %~ even $ [1,2,3] -- [False,True,False] ---- --
-- >>> traverse.traverse %~ length $ [["hello","world"],["!!!"]] -- [[5,5],[3]] ---- --
-- (%~) :: Setter s t a b -> (a -> b) -> s -> t -- (%~) :: Iso s t a b -> (a -> b) -> s -> t -- (%~) :: Lens s t a b -> (a -> b) -> s -> t -- (%~) :: Traversal s t a b -> (a -> b) -> s -> t --(%~) :: () => ASetter s t a b -> (a -> b) -> s -> t infixr 4 %~ -- | Types that can be converted to a LogStr. Instances for types -- from the text library use a UTF-8 encoding. Instances for -- numerical types use a decimal encoding. class ToLogStr msg toLogStr :: ToLogStr msg => msg -> LogStr logWithoutLoc :: (MonadLogger m, ToLogStr msg) => LogSource -> LogLevel -> msg -> m () data LogLevel LevelDebug :: LogLevel LevelInfo :: LogLevel LevelWarn :: LogLevel LevelError :: LogLevel LevelOther :: Text -> LogLevel -- | A Monad which has the ability to log messages in some manner. class Monad m => MonadLogger (m :: Type -> Type) monadLoggerLog :: (MonadLogger m, ToLogStr msg) => Loc -> LogSource -> LogLevel -> msg -> m () -- | Append two lists, i.e., -- --
-- [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn] -- [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...] ---- -- If the first list is not finite, the result is the first list. (++) :: () => [a] -> [a] -> [a] infixr 5 ++ -- | The value of seq a b is bottom if a is bottom, and -- otherwise equal to b. In other words, it evaluates the first -- argument a to weak head normal form (WHNF). seq is -- usually introduced to improve performance by avoiding unneeded -- laziness. -- -- A note on evaluation order: the expression seq a b does -- not guarantee that a will be evaluated before -- b. The only guarantee given by seq is that the both -- a and b will be evaluated before seq -- returns a value. In particular, this means that b may be -- evaluated before a. If you need to guarantee a specific order -- of evaluation, you must use the function pseq from the -- "parallel" package. seq :: () => a -> b -> b -- | 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] -- | zip takes two lists and returns a list of corresponding pairs. -- --
-- zip [1, 2] ['a', 'b'] = [(1, 'a'), (2, 'b')] ---- -- If one input list is short, excess elements of the longer list are -- discarded: -- --
-- zip [1] ['a', 'b'] = [(1, 'a')] -- zip [1, 2] ['a'] = [(1, 'a')] ---- -- zip is right-lazy: -- --
-- zip [] _|_ = [] -- zip _|_ [] = _|_ --zip :: () => [a] -> [b] -> [(a, b)] -- | Extract the first component of a pair. fst :: () => (a, b) -> a -- | Extract the second component of a pair. snd :: () => (a, b) -> b -- | otherwise is defined as the value True. It helps to make -- guards more readable. eg. -- --
-- f x | x < 0 = ... -- | otherwise = ... --otherwise :: Bool -- | If the first argument evaluates to True, then the result is the -- second argument. Otherwise an AssertionFailed exception is -- raised, containing a String with the source file and line -- number of the call to assert. -- -- Assertions can normally be turned on or off with a compiler flag (for -- GHC, assertions are normally on unless optimisation is turned on with -- -O or the -fignore-asserts option is given). When -- assertions are turned off, the first argument to assert is -- ignored, and the second argument is returned as the result. assert :: () => Bool -> a -> a -- | map f xs is the list obtained by applying f -- to each element of xs, i.e., -- --
-- map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn] -- map f [x1, x2, ...] == [f x1, f x2, ...] --map :: () => (a -> b) -> [a] -> [b] -- | general coercion from integral types fromIntegral :: (Integral a, Num b) => a -> b -- | general coercion to fractional types realToFrac :: (Real a, Fractional b) => a -> b -- | Conditional failure of Alternative computations. Defined by -- --
-- guard True = pure () -- guard False = empty ---- --
-- >>> safeDiv 4 0 -- Nothing -- >>> safeDiv 4 2 -- Just 2 ---- -- A definition of safeDiv using guards, but not guard: -- --
-- safeDiv :: Int -> Int -> Maybe Int -- safeDiv x y | y /= 0 = Just (x `div` y) -- | otherwise = Nothing ---- -- A definition of safeDiv using guard and Monad -- do-notation: -- --
-- safeDiv :: Int -> Int -> Maybe Int -- safeDiv x y = do -- guard (y /= 0) -- return (x `div` y) --guard :: Alternative f => Bool -> f () -- | 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. -- --
-- atomically :: STM a -> IO a ---- -- is used to run STM transactions atomically. So, by specializing -- the types of atomically and join to -- --
-- atomically :: STM (IO b) -> IO (IO b) -- join :: IO (IO b) -> IO b ---- -- we can compose them as -- --
-- join . atomically :: STM (IO b) -> IO b ---- -- to run an STM transaction and the IO action it returns. join :: Monad m => m (m a) -> m 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 -- | 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 -- | 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 -- | The Eq class defines equality (==) and inequality -- (/=). All the basic datatypes exported by the Prelude -- are instances of Eq, and Eq may be derived for any -- datatype whose constituents are also instances of Eq. -- -- The Haskell Report defines no laws for Eq. However, == -- is customarily expected to implement an equivalence relationship where -- two values comparing equal are indistinguishable by "public" -- functions, with a "public" function being one not allowing to see -- implementation details. For example, for a type representing -- non-normalised natural numbers modulo 100, a "public" function doesn't -- make the difference between 1 and 201. It is expected to have the -- following properties: -- --
-- (x `quot` y)*y + (x `rem` y) == x --rem :: Integral a => a -> a -> a -- | integer division truncated toward negative infinity div :: Integral a => a -> a -> a -- | integer modulus, satisfying -- --
-- (x `div` y)*y + (x `mod` y) == x --mod :: Integral a => a -> a -> a -- | simultaneous quot and rem quotRem :: Integral a => a -> a -> (a, a) -- | simultaneous div and mod divMod :: Integral a => a -> a -> (a, a) -- | conversion to Integer toInteger :: Integral a => a -> Integer infixl 7 `quot` infixl 7 `rem` infixl 7 `div` infixl 7 `mod` -- | 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 :: Type -> Type) -- | 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 infixl 1 >>= infixl 1 >> -- | The Data class comprehends a fundamental primitive -- gfoldl for folding over constructor applications, say terms. -- This primitive can be instantiated in several ways to map over the -- immediate subterms of a term; see the gmap combinators later -- in this class. Indeed, a generic programmer does not necessarily need -- to use the ingenious gfoldl primitive but rather the intuitive -- gmap combinators. The gfoldl primitive is completed by -- means to query top-level constructors, to turn constructor -- representations into proper terms, and to list all possible datatype -- constructors. This completion allows us to serve generic programming -- scenarios like read, show, equality, term generation. -- -- The combinators gmapT, gmapQ, gmapM, etc are all -- provided with default definitions in terms of gfoldl, leaving -- open the opportunity to provide datatype-specific definitions. (The -- inclusion of the gmap combinators as members of class -- Data allows the programmer or the compiler to derive -- specialised, and maybe more efficient code per datatype. Note: -- gfoldl is more higher-order than the gmap combinators. -- This is subject to ongoing benchmarking experiments. It might turn out -- that the gmap combinators will be moved out of the class -- Data.) -- -- Conceptually, the definition of the gmap combinators in terms -- of the primitive gfoldl requires the identification of the -- gfoldl function arguments. Technically, we also need to -- identify the type constructor c for the construction of the -- result type from the folded term type. -- -- In the definition of gmapQx combinators, we use -- phantom type constructors for the c in the type of -- gfoldl because the result type of a query does not involve the -- (polymorphic) type of the term argument. In the definition of -- gmapQl we simply use the plain constant type constructor -- because gfoldl is left-associative anyway and so it is readily -- suited to fold a left-associative binary operation over the immediate -- subterms. In the definition of gmapQr, extra effort is needed. We use -- a higher-order accumulation trick to mediate between left-associative -- constructor application vs. right-associative binary operation (e.g., -- (:)). When the query is meant to compute a value of type -- r, then the result type withing generic folding is r -- -> r. So the result of folding is a function to which we -- finally pass the right unit. -- -- With the -XDeriveDataTypeable option, GHC can generate -- instances of the Data class automatically. For example, given -- the declaration -- --
-- data T a b = C1 a b | C2 deriving (Typeable, Data) ---- -- GHC will generate an instance that is equivalent to -- --
-- instance (Data a, Data b) => Data (T a b) where -- gfoldl k z (C1 a b) = z C1 `k` a `k` b -- gfoldl k z C2 = z C2 -- -- gunfold k z c = case constrIndex c of -- 1 -> k (k (z C1)) -- 2 -> z C2 -- -- toConstr (C1 _ _) = con_C1 -- toConstr C2 = con_C2 -- -- dataTypeOf _ = ty_T -- -- con_C1 = mkConstr ty_T "C1" [] Prefix -- con_C2 = mkConstr ty_T "C2" [] Prefix -- ty_T = mkDataType "Module.T" [con_C1, con_C2] ---- -- This is suitable for datatypes that are exported transparently. class Typeable a => Data a -- | Left-associative fold operation for constructor applications. -- -- The type of gfoldl is a headache, but operationally it is a -- simple generalisation of a list fold. -- -- The default definition for gfoldl is const -- id, which is suitable for abstract datatypes with no -- substructures. gfoldl :: Data a => (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. () => g -> c g) -> a -> c a -- | Unfolding constructor applications gunfold :: Data a => (forall b r. Data b => c (b -> r) -> c r) -> (forall r. () => r -> c r) -> Constr -> c a -- | Obtaining the constructor from a given datum. For proper terms, this -- is meant to be the top-level constructor. Primitive datatypes are here -- viewed as potentially infinite sets of values (i.e., constructors). toConstr :: Data a => a -> Constr -- | The outer type constructor of the type dataTypeOf :: Data a => a -> DataType -- | Mediate types and unary type constructors. -- -- In Data instances of the form -- --
-- instance (Data a, ...) => Data (T a) ---- -- dataCast1 should be defined as gcast1. -- -- The default definition is const Nothing, which -- is appropriate for instances of other forms. dataCast1 :: (Data a, Typeable t) => (forall d. Data d => c (t d)) -> Maybe (c a) -- | Mediate types and binary type constructors. -- -- In Data instances of the form -- --
-- instance (Data a, Data b, ...) => Data (T a b) ---- -- dataCast2 should be defined as gcast2. -- -- The default definition is const Nothing, which -- is appropriate for instances of other forms. dataCast2 :: (Data a, Typeable t) => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a) -- | A generic transformation that maps over the immediate subterms -- -- The default definition instantiates the type constructor c in -- the type of gfoldl to an identity datatype constructor, using -- the isomorphism pair as injection and projection. gmapT :: Data a => (forall b. Data b => b -> b) -> a -> a -- | A generic query with a left-associative binary operator gmapQl :: Data a => (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r -- | A generic query with a right-associative binary operator gmapQr :: Data a => (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r -- | A generic query that processes the immediate subterms and returns a -- list of results. The list is given in the same order as originally -- specified in the declaration of the data constructors. gmapQ :: Data a => (forall d. Data d => d -> u) -> a -> [u] -- | A generic query that processes one child by index (zero-based) gmapQi :: Data a => Int -> (forall d. Data d => d -> u) -> a -> u -- | A generic monadic transformation that maps over the immediate subterms -- -- The default definition instantiates the type constructor c in -- the type of gfoldl to the monad datatype constructor, defining -- injection and projection using return and >>=. gmapM :: (Data a, Monad m) => (forall d. Data d => d -> m d) -> a -> m a -- | Transformation of at least one immediate subterm does not fail gmapMp :: (Data a, MonadPlus m) => (forall d. Data d => d -> m d) -> a -> m a -- | Transformation of one immediate subterm with success gmapMo :: (Data a, MonadPlus m) => (forall d. Data d => d -> m d) -> a -> m a -- | 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 :: Type -> Type) 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 infixl 4 <$ -- | Basic numeric class. -- -- The Haskell Report defines no laws for Num. However, '(+)' and -- '(*)' are customarily expected to define a ring and have the following -- properties: -- --
-- abs x * signum x == x ---- -- For real numbers, the signum is either -1 (negative), -- 0 (zero) or 1 (positive). signum :: Num a => a -> a -- | Conversion from an Integer. An integer literal represents the -- application of the function fromInteger to the appropriate -- value of type Integer, so such literals have type -- (Num a) => a. fromInteger :: Num a => Integer -> a infixl 6 + infixl 7 * infixl 6 - -- | 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. -- -- The Haskell Report defines no laws for Ord. However, -- <= is customarily expected to implement a non-strict partial -- order and have the following properties: -- --
-- infixr 5 :^: -- data Tree a = Leaf a | Tree a :^: Tree a ---- -- the derived instance of Read in Haskell 2010 is equivalent to -- --
-- instance (Read a) => Read (Tree a) where
--
-- readsPrec d r = readParen (d > app_prec)
-- (\r -> [(Leaf m,t) |
-- ("Leaf",s) <- lex r,
-- (m,t) <- readsPrec (app_prec+1) s]) r
--
-- ++ readParen (d > up_prec)
-- (\r -> [(u:^:v,w) |
-- (u,s) <- readsPrec (up_prec+1) r,
-- (":^:",t) <- lex s,
-- (v,w) <- readsPrec (up_prec+1) t]) r
--
-- where app_prec = 10
-- up_prec = 5
--
--
-- Note that right-associativity of :^: is unused.
--
-- The derived instance in GHC is equivalent to
--
-- -- instance (Read a) => Read (Tree a) where -- -- readPrec = parens $ (prec app_prec $ do -- Ident "Leaf" <- lexP -- m <- step readPrec -- return (Leaf m)) -- -- +++ (prec up_prec $ do -- u <- step readPrec -- Symbol ":^:" <- lexP -- v <- step readPrec -- return (u :^: v)) -- -- where app_prec = 10 -- up_prec = 5 -- -- readListPrec = readListPrecDefault ---- -- Why do both readsPrec and readPrec exist, and why does -- GHC opt to implement readPrec in derived Read instances -- instead of readsPrec? The reason is that readsPrec is -- based on the ReadS type, and although ReadS is mentioned -- in the Haskell 2010 Report, it is not a very efficient parser data -- structure. -- -- readPrec, on the other hand, is based on a much more efficient -- ReadPrec datatype (a.k.a "new-style parsers"), but its -- definition relies on the use of the RankNTypes language -- extension. Therefore, readPrec (and its cousin, -- readListPrec) are marked as GHC-only. Nevertheless, it is -- recommended to use readPrec instead of readsPrec -- whenever possible for the efficiency improvements it brings. -- -- As mentioned above, derived Read instances in GHC will -- implement readPrec instead of readsPrec. The default -- implementations of readsPrec (and its cousin, readList) -- will simply use readPrec under the hood. If you are writing a -- Read instance by hand, it is recommended to write it like so: -- --
-- instance Read T where -- readPrec = ... -- readListPrec = readListPrecDefault --class Read a class (Num a, Ord a) => Real a -- | the rational equivalent of its real argument with full precision toRational :: Real a => a -> Rational -- | Efficient, machine-independent access to the components of a -- floating-point number. class (RealFrac a, Floating a) => RealFloat a -- | a constant function, returning the radix of the representation (often -- 2) floatRadix :: RealFloat a => a -> Integer -- | a constant function, returning the number of digits of -- floatRadix in the significand floatDigits :: RealFloat a => a -> Int -- | a constant function, returning the lowest and highest values the -- exponent may assume floatRange :: RealFloat a => a -> (Int, Int) -- | The function decodeFloat applied to a real floating-point -- number returns the significand expressed as an Integer and an -- appropriately scaled exponent (an Int). If -- decodeFloat x yields (m,n), then x -- is equal in value to m*b^^n, where b is the -- floating-point radix, and furthermore, either m and -- n are both zero or else b^(d-1) <= abs m < -- b^d, where d is the value of floatDigits -- x. In particular, decodeFloat 0 = (0,0). If the -- type contains a negative zero, also decodeFloat (-0.0) = -- (0,0). The result of decodeFloat x is -- unspecified if either of isNaN x or -- isInfinite x is True. decodeFloat :: RealFloat a => a -> (Integer, Int) -- | encodeFloat performs the inverse of decodeFloat in the -- sense that for finite x with the exception of -0.0, -- uncurry encodeFloat (decodeFloat x) = -- x. encodeFloat m n is one of the two closest -- representable floating-point numbers to m*b^^n (or -- ±Infinity if overflow occurs); usually the closer, but if -- m contains too many bits, the result may be rounded in the -- wrong direction. encodeFloat :: RealFloat a => Integer -> Int -> a -- | exponent corresponds to the second component of -- decodeFloat. exponent 0 = 0 and for finite -- nonzero x, exponent x = snd (decodeFloat x) -- + floatDigits x. If x is a finite floating-point -- number, it is equal in value to significand x * b ^^ -- exponent x, where b is the floating-point radix. -- The behaviour is unspecified on infinite or NaN values. exponent :: RealFloat a => a -> Int -- | The first component of decodeFloat, scaled to lie in the open -- interval (-1,1), either 0.0 or of absolute -- value >= 1/b, where b is the floating-point -- radix. The behaviour is unspecified on infinite or NaN -- values. significand :: RealFloat a => a -> a -- | multiplies a floating-point number by an integer power of the radix scaleFloat :: RealFloat a => Int -> a -> a -- | True if the argument is an IEEE "not-a-number" (NaN) value isNaN :: RealFloat a => a -> Bool -- | True if the argument is an IEEE infinity or negative infinity isInfinite :: RealFloat a => a -> Bool -- | True if the argument is too small to be represented in -- normalized format isDenormalized :: RealFloat a => a -> Bool -- | True if the argument is an IEEE negative zero isNegativeZero :: RealFloat a => a -> Bool -- | True if the argument is an IEEE floating point number isIEEE :: RealFloat a => a -> Bool -- | a version of arctangent taking two real floating-point arguments. For -- real floating x and y, atan2 y x -- computes the angle (from the positive x-axis) of the vector from the -- origin to the point (x,y). atan2 y x returns -- a value in the range [-pi, pi]. It follows the -- Common Lisp semantics for the origin when signed zeroes are supported. -- atan2 y 1, with y in a type that is -- RealFloat, should return the same value as atan -- y. A default definition of atan2 is provided, but -- implementors can provide a more accurate implementation. atan2 :: RealFloat a => a -> a -> a -- | Extracting components of fractions. class (Real a, Fractional a) => RealFrac a -- | The function properFraction takes a real fractional number -- x and returns a pair (n,f) such that x = -- n+f, and: -- --
-- infixr 5 :^: -- data Tree a = Leaf a | Tree a :^: Tree a ---- -- the derived instance of Show is equivalent to -- --
-- instance (Show a) => Show (Tree a) where -- -- showsPrec d (Leaf m) = showParen (d > app_prec) $ -- showString "Leaf " . showsPrec (app_prec+1) m -- where app_prec = 10 -- -- showsPrec d (u :^: v) = showParen (d > up_prec) $ -- showsPrec (up_prec+1) u . -- showString " :^: " . -- showsPrec (up_prec+1) v -- where up_prec = 5 ---- -- Note that right-associativity of :^: is ignored. For example, -- --
-- fail s >>= f = fail s ---- -- If your Monad is also MonadPlus, a popular definition -- is -- --
-- fail _ = mzero --class Monad m => MonadFail (m :: Type -> Type) -- | Class for string-like datastructures; used by the overloaded string -- extension (-XOverloadedStrings in GHC). class IsString a fromString :: IsString a => String -> a -- | A functor with application, providing operations to -- --
-- (<*>) = liftA2 id ---- --
-- liftA2 f x y = f <$> x <*> y ---- -- Further, any definition must satisfy the following: -- --
pure id <*> -- v = v
pure (.) <*> u -- <*> v <*> w = u <*> (v -- <*> w)
pure f <*> -- pure x = pure (f x)
u <*> pure y = -- pure ($ y) <*> u
-- forall x y. p (q x y) = f x . g y ---- -- it follows from the above that -- --
-- liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g v ---- -- If f is also a Monad, it should satisfy -- -- -- -- (which implies that pure and <*> satisfy the -- applicative functor laws). class Functor f => Applicative (f :: Type -> Type) -- | Lift a value. pure :: Applicative f => a -> f a -- | Sequential application. -- -- A few functors support an implementation of <*> that is -- more efficient than the default one. (<*>) :: Applicative f => f (a -> b) -> f a -> f b -- | Lift a binary function to actions. -- -- Some functors support an implementation of liftA2 that is more -- efficient than the default one. In particular, if fmap is an -- expensive operation, it is likely better to use liftA2 than to -- fmap over the structure and then use <*>. liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c -- | Sequence actions, discarding the value of the first argument. (*>) :: Applicative f => f a -> f b -> f b -- | Sequence actions, discarding the value of the second argument. (<*) :: Applicative f => f a -> f b -> f a infixl 4 <*> infixl 4 *> infixl 4 <* -- | 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 ---- --
-- length = getSum . foldMap (Sum . const 1) ---- -- 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 :: Type -> Type) -- | 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 -- | Left-associative fold of a structure but with strict application of -- the operator. -- -- 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 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 -- | 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 -- | The sum function computes the sum of the numbers of a -- structure. sum :: (Foldable t, Num a) => t a -> a -- | The product function computes the product of the numbers of a -- structure. product :: (Foldable t, Num a) => t a -> a infix 4 `elem` -- | 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: -- --
-- from . to ≡ id -- to . from ≡ id --class Generic a -- | The class of semigroups (types with an associative binary operation). -- -- Instances should satisfy the associativity law: -- -- class Semigroup a -- | An associative operation. (<>) :: Semigroup a => a -> a -> a infixr 6 <> -- | The class of monoids (types with an associative binary operation that -- has an identity). Instances should satisfy the following laws: -- --
x <> mempty = x
mempty <> x = x
mconcat = foldr '(<>)' -- mempty
-- >>> 2^100 :: Natural -- 1267650600228229401496703205376 ---- -- Operations whose result would be negative throw -- (Underflow :: ArithException), -- --
-- >>> -1 :: Natural -- *** Exception: arithmetic underflow --data Natural -- | 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 data Ordering LT :: Ordering EQ :: Ordering GT :: Ordering -- | Arbitrary-precision rational numbers, represented as a ratio of two -- Integer values. A rational number may be constructed using the -- % operator. type Rational = Ratio Integer -- | 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 -- | A Word is an unsigned integral type, with the same size as -- Int. data Word -- | 8-bit unsigned integer type data Word8 -- | 16-bit unsigned integer type data Word16 -- | 32-bit unsigned integer type data Word32 -- | 64-bit unsigned integer type data Word64 -- | 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 -- | CallStacks are a lightweight method of obtaining a partial -- call-stack at any point in the program. -- -- A function can request its call-site with the HasCallStack -- constraint. For example, we can define -- --
-- putStrLnWithCallStack :: HasCallStack => String -> IO () ---- -- as a variant of putStrLn that will get its call-site and -- print it, along with the string given as argument. We can access the -- call-stack inside putStrLnWithCallStack with -- callStack. -- --
-- putStrLnWithCallStack :: HasCallStack => String -> IO () -- putStrLnWithCallStack msg = do -- putStrLn msg -- putStrLn (prettyCallStack callStack) ---- -- Thus, if we call putStrLnWithCallStack we will get a -- formatted call-stack alongside our string. -- --
-- >>> putStrLnWithCallStack "hello" -- hello -- CallStack (from HasCallStack): -- putStrLnWithCallStack, called at <interactive>:2:1 in interactive:Ghci1 ---- -- GHC solves HasCallStack constraints in three steps: -- --
-- runST (writeSTRef _|_ v >>= f) = _|_ --data ST s a -- | Promote a function to a monad. liftM :: Monad m => (a1 -> r) -> m a1 -> m r -- | Case analysis for the Either type. If the value is -- Left a, apply the first function to a; if it -- is Right b, apply the second function to b. -- --
-- >>> let s = Left "foo" :: Either String Int -- -- >>> let n = Right 3 :: Either String Int -- -- >>> either length (*2) s -- 3 -- -- >>> either length (*2) n -- 6 --either :: () => (a -> c) -> (b -> c) -> Either a b -> c -- | See examples in Control.Monad.Reader. Note, the partially -- applied function type (->) r is a simple reader monad. See -- the instance declaration below. class Monad m => MonadReader r (m :: Type -> Type) | m -> r -- | Retrieves the monad environment. ask :: MonadReader r m => m r -- | Executes a computation in a modified environment. local :: MonadReader r m => (r -> r) -> m a -> m a -- | A space-efficient representation of a Word8 vector, supporting -- many efficient operations. -- -- A ByteString contains 8-bit bytes, or by using the operations -- from Data.ByteString.Char8 it can be interpreted as containing -- 8-bit characters. data ByteString -- | Builders denote sequences of bytes. They are Monoids -- where mempty is the zero-length sequence and mappend is -- concatenation, which runs in O(1). data Builder -- | 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 <$> -- | The class of types that can be converted to a hash value. -- -- Minimal implementation: hashWithSalt. class Hashable a -- | A space efficient, packed, unboxed Unicode text type. data Text -- | const x is a unary function which evaluates to x for -- all inputs. -- --
-- >>> const 42 "hello" -- 42 ---- --
-- >>> map (const 42) [0..3] -- [42,42,42,42] --const :: () => a -> b -> a -- | Function composition. (.) :: () => (b -> c) -> (a -> b) -> a -> c infixr 9 . -- | A map from keys to values. A map cannot contain duplicate keys; each -- key can map to at most one value. data HashMap k v -- | A Map from keys k to values a. data Map k a -- | A handle managing output to the Haskell program's standard output -- channel. stdout :: Handle -- | Haskell defines operations to read and write characters from and to -- files, represented by values of type Handle. Each value of -- this type is a handle: a record used by the Haskell run-time -- system to manage I/O with file system objects. A handle has at -- least the following properties: -- --
-- mzero >>= f = mzero -- v >> mzero = mzero ---- -- The default definition is -- --
-- mzero = empty --mzero :: MonadPlus m => m a -- | An associative operation. The default definition is -- --
-- mplus = (<|>) --mplus :: MonadPlus m => m a -> m a -> m a -- | Since Void values logically don't exist, this witnesses the -- logical reasoning tool of "ex falso quodlibet". -- --
-- >>> let x :: Either Void Int; x = Right 5
--
-- >>> :{
-- case x of
-- Right r -> r
-- Left l -> absurd l
-- :}
-- 5
--
absurd :: () => Void -> a
-- | Uninhabited data type
data Void
-- | Chan is an abstract type representing an unbounded FIFO
-- channel.
data Chan 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 :: Type -> Type)
-- | Lift a computation from the IO monad.
liftIO :: MonadIO m => IO a -> m a
-- | Direct MonadPlus equivalent of filter.
--
-- -- filter = ( mfilter :: (a -> Bool) -> [a] -> [a] ) ---- -- An example using mfilter with the Maybe monad: -- --
-- >>> mfilter odd (Just 1) -- Just 1 -- >>> mfilter odd (Just 2) -- Nothing --mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a -- | Strict version of <$>. (<$!>) :: Monad m => (a -> b) -> m a -> m b infixl 4 <$!> -- | The reverse of when. unless :: Applicative f => Bool -> f () -> f () -- | Like replicateM, but discards the result. replicateM_ :: Applicative m => Int -> m a -> m () -- | Like foldM, but discards the result. foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () -- | The foldM function is analogous to foldl, except that -- its result is encapsulated in a monad. Note that foldM works -- from left-to-right over the list arguments. This could be an issue -- where (>>) and the `folded function' are not -- commutative. -- --
-- foldM f a1 [x1, x2, ..., xm] -- -- == -- -- do -- a2 <- f a1 x1 -- a3 <- f a2 x2 -- ... -- f am xm ---- -- If right-to-left evaluation is required, the input list should be -- reversed. -- -- Note: foldM is the same as foldlM foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b -- | zipWithM_ is the extension of zipWithM which ignores the -- final result. zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () -- | The zipWithM function generalizes zipWith to arbitrary -- applicative functors. zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] -- | Repeat an action indefinitely. -- --
-- echoServer :: Socket -> IO () -- echoServer socket = forever $ do -- client <- accept socket -- forkFinally (echo client) (\_ -> hClose client) -- where -- echo :: Handle -> IO () -- echo client = forever $ -- hGetLine client >>= hPutStrLn client --forever :: Applicative f => f a -> f b -- | Right-to-left composition of Kleisli arrows. -- (>=>), 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 <=< -- | Left-to-right composition of Kleisli arrows. (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 >=> -- | This generalizes the list-based filter function. filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] -- | forM is mapM with its arguments flipped. For a version -- that ignores the results see forM_. forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) -- | for is traverse with its arguments flipped. For a -- version that ignores the results see for_. for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) -- | One or none. optional :: Alternative f => f a -> f (Maybe a) -- | The basic arrow class. -- -- Instances should satisfy the following laws: -- --
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 :: Type -> Type -> Type) -- | Send the first component of the input through the argument arrow, and -- copy the rest unchanged to the output. first :: Arrow a => a b c -> a (b, d) (c, d) -- | A mirror image of first. -- -- The default definition may be overridden with a more efficient version -- if desired. second :: Arrow a => a b c -> a (d, b) (d, 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') infixr 3 *** infixr 3 &&& -- | Identity functor and monad. (a non-strict monad) newtype Identity a Identity :: a -> Identity a [runIdentity] :: Identity a -> a -- | A handle managing output to the Haskell program's standard error -- channel. stderr :: Handle -- | A handle managing input from the Haskell program's standard input -- channel. stdin :: Handle -- | Write the supplied value into a TVar. writeTVar :: () => TVar a -> a -> STM () -- | Return the current value stored in a TVar. readTVar :: () => TVar a -> STM a -- | Create a new TVar holding a value supplied newTVar :: () => a -> STM (TVar a) -- | A monad supporting atomic memory transactions. data STM a -- | Shared memory locations that support atomic memory transactions. data TVar a -- | Superclass for asynchronous exceptions. data SomeAsyncException [SomeAsyncException] :: forall e. Exception e => e -> SomeAsyncException -- | Defines the exit codes that a program can return. data ExitCode -- | indicates successful termination; ExitSuccess :: ExitCode -- | indicates program failure with an exit code. The exact interpretation -- of the code is operating-system dependent. In particular, some values -- may be prohibited (e.g. 0 on a POSIX-compliant system). ExitFailure :: Int -> ExitCode -- | Three kinds of buffering are supported: line-buffering, -- block-buffering or no-buffering. These modes have the following -- effects. For output, items are written out, or flushed, from -- the internal buffer according to the buffer mode: -- --
-- data MyException = ThisException | ThatException -- deriving Show -- -- instance Exception MyException ---- -- The default method definitions in the Exception class do what -- we need in this case. You can now throw and catch -- ThisException and ThatException as exceptions: -- --
-- *Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
-- Caught ThisException
--
--
-- In more complicated examples, you may wish to define a whole hierarchy
-- of exceptions:
--
-- -- --------------------------------------------------------------------- -- -- Make the root exception type for all the exceptions in a compiler -- -- data SomeCompilerException = forall e . Exception e => SomeCompilerException e -- -- instance Show SomeCompilerException where -- show (SomeCompilerException e) = show e -- -- instance Exception SomeCompilerException -- -- compilerExceptionToException :: Exception e => e -> SomeException -- compilerExceptionToException = toException . SomeCompilerException -- -- compilerExceptionFromException :: Exception e => SomeException -> Maybe e -- compilerExceptionFromException x = do -- SomeCompilerException a <- fromException x -- cast a -- -- --------------------------------------------------------------------- -- -- Make a subhierarchy for exceptions in the frontend of the compiler -- -- data SomeFrontendException = forall e . Exception e => SomeFrontendException e -- -- instance Show SomeFrontendException where -- show (SomeFrontendException e) = show e -- -- instance Exception SomeFrontendException where -- toException = compilerExceptionToException -- fromException = compilerExceptionFromException -- -- frontendExceptionToException :: Exception e => e -> SomeException -- frontendExceptionToException = toException . SomeFrontendException -- -- frontendExceptionFromException :: Exception e => SomeException -> Maybe e -- frontendExceptionFromException x = do -- SomeFrontendException a <- fromException x -- cast a -- -- --------------------------------------------------------------------- -- -- Make an exception type for a particular frontend compiler exception -- -- data MismatchedParentheses = MismatchedParentheses -- deriving Show -- -- instance Exception MismatchedParentheses where -- toException = frontendExceptionToException -- fromException = frontendExceptionFromException ---- -- We can now catch a MismatchedParentheses exception as -- MismatchedParentheses, SomeFrontendException or -- SomeCompilerException, but not other types, e.g. -- IOException: -- --
-- *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
-- Caught MismatchedParentheses
-- *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
-- Caught MismatchedParentheses
-- *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
-- Caught MismatchedParentheses
-- *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException))
-- *** Exception: MismatchedParentheses
--
class (Typeable e, Show e) => Exception e
toException :: Exception e => e -> SomeException
fromException :: Exception e => SomeException -> Maybe e
-- | Render this exception value in a human-friendly manner.
--
-- Default implementation: show.
displayException :: Exception e => e -> String
-- | The Const functor.
newtype Const a (b :: k) :: forall k. () => Type -> k -> Type
Const :: a -> Const a
[getConst] :: Const a -> a
-- | notElem is the negation of elem.
notElem :: (Foldable t, Eq a) => a -> t a -> Bool
infix 4 `notElem`
-- | Determines whether all elements of the structure satisfy the
-- predicate.
all :: Foldable t => (a -> Bool) -> t a -> Bool
-- | Determines whether any element of the structure satisfies the
-- predicate.
any :: Foldable t => (a -> Bool) -> t a -> 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
-- | 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
-- | Map a function over all the elements of a container and concatenate
-- the resulting lists.
concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
-- | The concatenation of all the elements of a container of lists.
concat :: Foldable t => t [a] -> [a]
-- | The sum of a collection of actions, generalizing concat. As of
-- base 4.8.0.0, msum is just asum, specialized to
-- MonadPlus.
msum :: (Foldable t, MonadPlus m) => t (m a) -> m a
-- | The sum of a collection of actions, generalizing concat.
--
-- asum [Just Hello, Nothing, Just World] Just Hello
asum :: (Foldable t, Alternative f) => t (f a) -> f a
-- | Evaluate each monadic action in the structure from left to right, and
-- ignore the results. For a version that doesn't ignore the results see
-- sequence.
--
-- As of base 4.8.0.0, sequence_ is just sequenceA_,
-- specialized to Monad.
sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
-- | Evaluate each action in the structure from left to right, and ignore
-- the results. For a version that doesn't ignore the results see
-- sequenceA.
sequenceA_ :: (Foldable t, Applicative f) => t (f a) -> f ()
-- | forM_ is mapM_ with its arguments flipped. For a version
-- that doesn't ignore the results see forM.
--
-- As of base 4.8.0.0, forM_ is just for_, specialized to
-- Monad.
forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
-- | Map each element of a structure to a monadic action, evaluate these
-- actions from left to right, and ignore the results. For a version that
-- doesn't ignore the results see mapM.
--
-- As of base 4.8.0.0, mapM_ is just traverse_, specialized
-- to Monad.
mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
-- | for_ is traverse_ with its arguments flipped. For a
-- version that doesn't ignore the results see for.
--
-- -- >>> for_ [1..4] print -- 1 -- 2 -- 3 -- 4 --for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () -- | Map each element of a structure to an action, evaluate these actions -- from left to right, and ignore the results. For a version that doesn't -- ignore the results see traverse. traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f () -- | unwords is an inverse operation to words. It joins words -- with separating spaces. -- --
-- >>> unwords ["Lorem", "ipsum", "dolor"] -- "Lorem ipsum dolor" --unwords :: [String] -> String -- | words breaks a string up into a list of words, which were -- delimited by white space. -- --
-- >>> words "Lorem ipsum\ndolor" -- ["Lorem","ipsum","dolor"] --words :: String -> [String] -- | unlines is an inverse operation to lines. It joins -- lines, after appending a terminating newline to each. -- --
-- >>> unlines ["Hello", "World", "!"] -- "Hello\nWorld\n!\n" --unlines :: [String] -> String -- | lines breaks a string up into a list of strings at newline -- characters. The resulting strings do not contain newlines. -- -- Note that after splitting the string at newline characters, the last -- part of the string is considered a line even if it doesn't end with a -- newline. For example, -- --
-- >>> lines "" -- [] ---- --
-- >>> lines "\n" -- [""] ---- --
-- >>> lines "one" -- ["one"] ---- --
-- >>> lines "one\n" -- ["one"] ---- --
-- >>> lines "one\n\n" -- ["one",""] ---- --
-- >>> lines "one\ntwo" -- ["one","two"] ---- --
-- >>> lines "one\ntwo\n" -- ["one","two"] ---- -- Thus lines s contains at least as many elements as -- newlines in s. lines :: String -> [String] -- | Parse a string using the Read instance. Succeeds if there is -- exactly one valid result. -- --
-- >>> readMaybe "123" :: Maybe Int -- Just 123 ---- --
-- >>> readMaybe "hello" :: Maybe Int -- Nothing --readMaybe :: Read a => String -> Maybe a -- | Return True if the given value is a Right-value, -- False otherwise. -- --
-- >>> isRight (Left "foo") -- False -- -- >>> isRight (Right 3) -- True ---- -- Assuming a Left value signifies some sort of error, we can use -- isRight to write a very simple reporting function that only -- outputs "SUCCESS" when a computation has succeeded. -- -- This example shows how isRight might be used to avoid pattern -- matching when one does not care about the value contained in the -- constructor: -- --
-- >>> import Control.Monad ( when ) -- -- >>> let report e = when (isRight e) $ putStrLn "SUCCESS" -- -- >>> report (Left "parse error") -- -- >>> report (Right 1) -- SUCCESS --isRight :: () => Either a b -> Bool -- | Return True if the given value is a Left-value, -- False otherwise. -- --
-- >>> isLeft (Left "foo") -- True -- -- >>> isLeft (Right 3) -- False ---- -- Assuming a Left value signifies some sort of error, we can use -- isLeft to write a very simple error-reporting function that -- does absolutely nothing in the case of success, and outputs "ERROR" if -- any error occurred. -- -- This example shows how isLeft might be used to avoid pattern -- matching when one does not care about the value contained in the -- constructor: -- --
-- >>> import Control.Monad ( when ) -- -- >>> let report e = when (isLeft e) $ putStrLn "ERROR" -- -- >>> report (Right 1) -- -- >>> report (Left "parse error") -- ERROR --isLeft :: () => Either a b -> Bool -- | 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]) -- | 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] -- | 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] -- |
-- 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 -- | 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 newtype Down a Down :: a -> Down a -- | Proxy is a type that holds no data, but has a phantom parameter -- of arbitrary type (or even kind). Its use is to provide type -- information, even though there is no value available of that type (or -- it may be too costly to create one). -- -- Historically, Proxy :: Proxy a is a safer -- alternative to the 'undefined :: a' idiom. -- --
-- >>> Proxy :: Proxy (Void, Int -> Int) -- Proxy ---- -- Proxy can even hold types of higher kinds, -- --
-- >>> Proxy :: Proxy Either -- Proxy ---- --
-- >>> Proxy :: Proxy Functor -- Proxy ---- --
-- >>> Proxy :: Proxy complicatedStructure -- Proxy --data Proxy (t :: k) :: forall k. () => k -> Type Proxy :: Proxy -- | Left-to-right composition (>>>) :: Category cat => cat a b -> cat b c -> cat a c infixr 1 >>> -- | A class for categories. Instances should satisfy the laws -- --
-- f . id = f -- (right identity) -- id . f = f -- (left identity) -- f . (g . h) = (f . g) . h -- (associativity) --class Category (cat :: k -> k -> Type) -- | See openFile data IOMode ReadMode :: IOMode WriteMode :: IOMode AppendMode :: IOMode ReadWriteMode :: IOMode -- | The member functions of this class facilitate writing values of -- primitive types to raw memory (which may have been allocated with the -- above mentioned routines) and reading values from blocks of raw -- memory. The class, furthermore, includes support for computing the -- storage requirements and alignment restrictions of storable types. -- -- Memory addresses are represented as values of type Ptr -- a, for some a which is an instance of class -- Storable. The type argument to Ptr helps provide some -- valuable type safety in FFI code (you can't mix pointers of different -- types without an explicit cast), while helping the Haskell type system -- figure out which marshalling method is needed for a given pointer. -- -- All marshalling between Haskell and a foreign language ultimately -- boils down to translating Haskell data structures into the binary -- representation of a corresponding data structure of the foreign -- language and vice versa. To code this marshalling in Haskell, it is -- necessary to manipulate primitive data types stored in unstructured -- memory blocks. The class Storable facilitates this manipulation -- on all types for which it is instantiated, which are the standard -- basic types of Haskell, the fixed size Int types -- (Int8, Int16, Int32, Int64), the fixed -- size Word types (Word8, Word16, Word32, -- Word64), StablePtr, all types from -- Foreign.C.Types, as well as Ptr. class Storable a -- | Reverse order of bytes in Word64. byteSwap64 :: Word64 -> Word64 -- | Reverse order of bytes in Word32. byteSwap32 :: Word32 -> Word32 -- | Swap bytes in Word16. byteSwap16 :: Word16 -> Word16 -- | Return the value computed by a state transformer computation. The -- forall ensures that the internal state used by the ST -- computation is inaccessible to the rest of the program. runST :: () => (forall s. () => ST s a) -> a -- | Case analysis for the Bool type. bool x y p -- evaluates to x when p is False, and evaluates -- to y when p is True. -- -- This is equivalent to if p then y else x; that is, one can -- think of it as an if-then-else construct with its arguments reordered. -- --
-- >>> bool "foo" "bar" True -- "bar" -- -- >>> bool "foo" "bar" False -- "foo" ---- -- Confirm that bool x y p and if p then y else -- x are equivalent: -- --
-- >>> let p = True; x = "bar"; y = "foo" -- -- >>> bool x y p == if p then y else x -- True -- -- >>> let p = False -- -- >>> bool x y p == if p then y else x -- True --bool :: () => a -> a -> Bool -> a -- | on b u x y runs the binary function b -- on the results of applying unary function u to two -- arguments x and y. From the opposite perspective, it -- transforms two inputs and combines the outputs. -- --
-- ((+) `on` f) x y = f x + f y ---- -- Typical usage: sortBy (compare `on` -- fst). -- -- Algebraic properties: -- --
(*) `on` id = (*) -- (if (*) ∉ {⊥, const -- ⊥})
((*) `on` f) `on` g = (*) `on` (f . g)
flip on f . flip on g = flip on (g . -- f)
-- >>> let fac n = if n <= 1 then 1 else n * fac (n-1) in fac 5 -- 120 ---- -- This uses the fact that Haskell’s let introduces recursive -- bindings. We can rewrite this definition using fix, -- --
-- >>> fix (\rec n -> if n <= 1 then 1 else n * rec (n-1)) 5 -- 120 ---- -- Instead of making a recursive call, we introduce a dummy parameter -- rec; when used within fix, this parameter then refers -- to fix' argument, hence the recursion is reintroduced. fix :: () => (a -> a) -> a -- | 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 () -- | 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 $> -- | Flipped version of <$>. -- --
-- (<&>) = flip fmap ---- --
-- >>> Just 2 <&> (+1) -- Just 3 ---- --
-- >>> [1,2,3] <&> (+1) -- [2,3,4] ---- --
-- >>> Right 3 <&> (+1) -- Right 4 --(<&>) :: Functor f => f a -> (a -> b) -> f b infixl 1 <&> -- | lcm x y is the smallest positive integer that both -- x and y divide. lcm :: Integral a => a -> a -> a -- | gcd x y is the non-negative factor of both x -- and y of which every common factor of x and -- y is also a factor; for example gcd 4 2 = 2, -- gcd (-4) 6 = 2, gcd 0 4 = 4. -- gcd 0 0 = 0. (That is, the common divisor -- that is "greatest" in the divisibility preordering.) -- -- Note: Since for signed fixed-width integer types, abs -- minBound < 0, the result may be negative if one of the -- arguments is minBound (and necessarily is if the other -- is 0 or minBound) for such types. gcd :: Integral a => a -> a -> a -- | raise a number to an integral power (^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 ^^ -- | raise a number to a non-negative integral power (^) :: (Num a, Integral b) => a -> b -> a infixr 8 ^ odd :: Integral a => a -> Bool even :: Integral a => a -> Bool -- | 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] -- | lookup key assocs looks up a key in an association -- list. lookup :: Eq a => a -> [(a, b)] -> Maybe b -- | reverse xs returns the elements of xs in -- reverse order. xs must be finite. reverse :: () => [a] -> [a] -- | break, applied to a predicate p and a list -- xs, returns a tuple where first element is longest prefix -- (possibly empty) of xs of elements that do not satisfy -- p and second element is the remainder of the list: -- --
-- break (> 3) [1,2,3,4,1,2,3,4] == ([1,2,3],[4,1,2,3,4]) -- break (< 9) [1,2,3] == ([],[1,2,3]) -- break (> 9) [1,2,3] == ([1,2,3],[]) ---- -- break p is equivalent to span (not . -- p). break :: () => (a -> Bool) -> [a] -> ([a], [a]) -- | span, applied to a predicate p and a list xs, -- returns a tuple where first element is longest prefix (possibly empty) -- of xs of elements that satisfy p and second element -- is the remainder of the list: -- --
-- span (< 3) [1,2,3,4,1,2,3,4] == ([1,2],[3,4,1,2,3,4]) -- span (< 9) [1,2,3] == ([1,2,3],[]) -- span (< 0) [1,2,3] == ([],[1,2,3]) ---- -- span p xs is equivalent to (takeWhile p xs, -- dropWhile p xs) span :: () => (a -> Bool) -> [a] -> ([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] -- | 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] -- | 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] -- | 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] -- | 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] -- | The mapMaybe function is a version of map which can -- throw out elements. In particular, the functional argument returns -- something of type Maybe b. If this is Nothing, -- no element is added on to the result list. If it is Just -- b, then b is included in the result list. -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> let readMaybeInt = readMaybe :: String -> Maybe Int -- -- >>> mapMaybe readMaybeInt ["1", "Foo", "3"] -- [1,3] -- -- >>> catMaybes $ map readMaybeInt ["1", "Foo", "3"] -- [1,3] ---- -- If we map the Just constructor, the entire list should be -- returned: -- --
-- >>> mapMaybe Just [1,2,3] -- [1,2,3] --mapMaybe :: () => (a -> Maybe b) -> [a] -> [b] -- | The catMaybes function takes a list of Maybes and -- returns a list of all the Just values. -- --
-- >>> catMaybes [Just 1, Nothing, Just 3] -- [1,3] ---- -- When constructing a list of Maybe values, catMaybes can -- be used to return all of the "success" results (if the list is the -- result of a map, then mapMaybe would be more -- appropriate): -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ] -- [Just 1,Nothing,Just 3] -- -- >>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ] -- [1,3] --catMaybes :: () => [Maybe a] -> [a] -- | The listToMaybe function returns Nothing on an empty -- list or Just a where a is the first element -- of the list. -- --
-- >>> listToMaybe [] -- Nothing ---- --
-- >>> listToMaybe [9] -- Just 9 ---- --
-- >>> listToMaybe [1,2,3] -- Just 1 ---- -- Composing maybeToList with listToMaybe should be the -- identity on singleton/empty lists: -- --
-- >>> maybeToList $ listToMaybe [5] -- [5] -- -- >>> maybeToList $ listToMaybe [] -- [] ---- -- But not on lists with more than one element: -- --
-- >>> maybeToList $ listToMaybe [1,2,3] -- [1] --listToMaybe :: () => [a] -> Maybe a -- | The maybeToList function returns an empty list when given -- Nothing or a singleton list when not given Nothing. -- --
-- >>> maybeToList (Just 7) -- [7] ---- --
-- >>> maybeToList Nothing -- [] ---- -- One can use maybeToList to avoid pattern matching when combined -- with a function that (safely) works on lists: -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> sum $ maybeToList (readMaybe "3") -- 3 -- -- >>> sum $ maybeToList (readMaybe "") -- 0 --maybeToList :: () => Maybe a -> [a] -- | 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 -- | The isNothing function returns True iff its argument is -- Nothing. -- --
-- >>> isNothing (Just 3) -- False ---- --
-- >>> isNothing (Just ()) -- False ---- --
-- >>> isNothing Nothing -- True ---- -- Only the outer constructor is taken into consideration: -- --
-- >>> isNothing (Just Nothing) -- False --isNothing :: () => Maybe a -> Bool -- | The isJust function returns True iff its argument is of -- the form Just _. -- --
-- >>> isJust (Just 3) -- True ---- --
-- >>> isJust (Just ()) -- True ---- --
-- >>> isJust Nothing -- False ---- -- Only the outer constructor is taken into consideration: -- --
-- >>> isJust (Just Nothing) -- True --isJust :: () => Maybe a -> Bool -- | 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 -- | uncurry converts a curried function to a function on pairs. -- --
-- >>> uncurry (+) (1,2) -- 3 ---- --
-- >>> uncurry ($) (show, 1) -- "1" ---- --
-- >>> map (uncurry max) [(1,2), (3,4), (6,8)] -- [2,4,8] --uncurry :: () => (a -> b -> c) -> (a, b) -> c -- | curry converts an uncurried function to a curried function. -- --
-- >>> curry fst 1 2 -- 1 --curry :: () => ((a, b) -> c) -> a -> b -> c -- | An MVar (pronounced "em-var") is a synchronising variable, used -- for communication between concurrent threads. It can be thought of as -- a box, which may be empty or full. data MVar a -- | the same as flip (-). -- -- Because - is treated specially in the Haskell grammar, -- (- e) is not a section, but an application of -- prefix negation. However, (subtract -- exp) is equivalent to the disallowed section. subtract :: Num a => a -> a -> a -- | asTypeOf is a type-restricted version of const. It is -- usually used as an infix operator, and its typing forces its first -- argument (which is usually overloaded) to have the same type as the -- second. asTypeOf :: () => a -> a -> a -- | Strict (call-by-value) application operator. It takes a function and -- an argument, evaluates the argument to weak head normal form (WHNF), -- then calls the function with that value. ($!) :: () => (a -> b) -> a -> b infixr 0 $! -- | flip f takes its (first) two arguments in the reverse -- order of f. -- --
-- >>> flip (++) "hello" "world" -- "worldhello" --flip :: () => (a -> b -> c) -> b -> a -> c -- | Promote a function to a monad, scanning the monadic arguments from -- left to right. For example, -- --
-- liftM2 (+) [0,1] [0,2] = [0,2,1,3] -- liftM2 (+) (Just 1) Nothing = Nothing --liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r -- | 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 () -- | Same as >>=, but with the arguments interchanged. (=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 =<< -- | Lift a ternary function to actions. liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d -- | Lift a function to actions. This function may be used as a value for -- fmap in a Functor instance. liftA :: Applicative f => (a -> b) -> f a -> f b -- | Non-empty (and non-strict) list type. data NonEmpty a (:|) :: a -> [a] -> NonEmpty a infixr 5 :| -- | 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 -- | Request a CallStack. -- -- NOTE: The implicit parameter ?callStack :: CallStack is an -- implementation detail and should not be considered part of the -- CallStack API, we may decide to change the implementation in -- the future. type HasCallStack = ?callStack :: CallStack -- | The SomeException type is the root of the exception type -- hierarchy. When an exception of type e is thrown, behind the -- scenes it is encapsulated in a SomeException. data SomeException [SomeException] :: forall e. Exception e => e -> SomeException -- | Boolean "and" (&&) :: Bool -> Bool -> Bool infixr 3 && -- | Boolean "or" (||) :: Bool -> Bool -> Bool infixr 2 || -- | Boolean "not" not :: Bool -> Bool -- | O(n). Convert a ShortByteString into a -- ByteString. fromShort :: ShortByteString -> ByteString -- | A compact representation of a Word8 vector. -- -- It has a lower memory overhead than a ByteString and and does -- not contribute to heap fragmentation. It can be converted to or from a -- ByteString (at the cost of copying the string data). It -- supports very few other operations. -- -- It is suitable for use as an internal representation for code that -- needs to keep many short strings in memory, but it should not -- be used as an interchange type. That is, it should not generally be -- used in public APIs. The ByteString type is usually more -- suitable for use in interfaces; it is more flexible and it supports a -- wide range of operations. data ShortByteString -- | O(n). Convert a ByteString into a -- ShortByteString. -- -- This makes a copy, so does not retain the input string. toShort :: ByteString -> ShortByteString -- | The reader monad transformer, which adds a read-only environment to -- the given monad. -- -- The return function ignores the environment, while -- >>= passes the inherited environment to both -- subcomputations. newtype ReaderT r (m :: k -> Type) (a :: k) :: forall k. () => Type -> k -> Type -> k -> Type ReaderT :: (r -> m a) -> ReaderT r [runReaderT] :: ReaderT r -> r -> m a -- | Monads which allow their actions to be run in IO. -- -- While MonadIO allows an IO action to be lifted into -- another monad, this class captures the opposite concept: allowing you -- to capture the monadic context. Note that, in order to meet the laws -- given below, the intuition is that a monad must have no monadic state, -- but may have monadic context. This essentially limits -- MonadUnliftIO to ReaderT and IdentityT -- transformers on top of IO. -- -- Laws. For any value u returned by askUnliftIO, it must -- meet the monad transformer laws as reformulated for -- MonadUnliftIO: -- --
unliftIO u . return = return
unliftIO u (m >>= f) = unliftIO u m >>= unliftIO -- u . f
askUnliftIO >>= (u -> liftIO (unliftIO u m)) = -- m
-- throwM e >> x = throwM e ---- -- In other words, throwing an exception short-circuits the rest of the -- monadic computation. class Monad m => MonadThrow (m :: Type -> Type) -- | Throw an exception. Note that this throws when this action is run in -- the monad m, not when it is applied. It is a generalization -- of Control.Exception's throwIO. -- -- Should satisfy the law: -- --
-- throwM e >> f = throwM e --throwM :: (MonadThrow m, Exception e) => e -> m a -- | A map of integers to values a. data IntMap a -- | A set of integers. data IntSet -- | General-purpose finite sequences. data Seq a -- | A set of values a. data Set a -- | A class of types that can be fully evaluated. class NFData a -- | rnf should reduce its argument to normal form (that is, fully -- evaluate all sub-components), and then return '()'. -- --
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics (Generic, Generic1)
-- import Control.DeepSeq
--
-- data Foo a = Foo a String
-- deriving (Eq, Generic, Generic1)
--
-- instance NFData a => NFData (Foo a)
-- instance NFData1 Foo
--
-- data Colour = Red | Green | Blue
-- deriving Generic
--
-- instance NFData Colour
--
--
-- Starting with GHC 7.10, the example above can be written more
-- concisely by enabling the new DeriveAnyClass extension:
--
--
-- {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
--
-- import GHC.Generics (Generic)
-- import Control.DeepSeq
--
-- data Foo a = Foo a String
-- deriving (Eq, Generic, Generic1, NFData, NFData1)
--
-- data Colour = Red | Green | Blue
-- deriving (Generic, NFData)
--
--
-- -- rnf a = seq a () ---- -- However, starting with deepseq-1.4.0.0, the default -- implementation is based on DefaultSignatures allowing for -- more accurate auto-derived NFData instances. If you need the -- previously used exact default rnf method implementation -- semantics, use -- --
-- instance NFData Colour where rnf x = seq x () ---- -- or alternatively -- --
-- instance NFData Colour where rnf = rwhnf ---- -- or -- --
-- {-# LANGUAGE BangPatterns #-}
-- instance NFData Colour where rnf !_ = ()
--
rnf :: NFData a => a -> ()
-- | a variant of deepseq that is useful in some circumstances:
--
-- -- force x = x `deepseq` x ---- -- force x fully evaluates x, and then returns it. Note -- that force x only performs evaluation when the value of -- force x itself is demanded, so essentially it turns shallow -- evaluation into deep evaluation. -- -- force can be conveniently used in combination with -- ViewPatterns: -- --
-- {-# LANGUAGE BangPatterns, ViewPatterns #-}
-- import Control.DeepSeq
--
-- someFun :: ComplexData -> SomeResult
-- someFun (force -> !arg) = {- 'arg' will be fully evaluated -}
--
--
-- Another useful application is to combine force with
-- evaluate in order to force deep evaluation relative to other
-- IO operations:
--
--
-- import Control.Exception (evaluate)
-- import Control.DeepSeq
--
-- main = do
-- result <- evaluate $ force $ pureComputation
-- {- 'result' will be fully evaluated at this point -}
-- return ()
--
--
-- Finally, here's an exception safe variant of the readFile'
-- example:
--
-- -- readFile' :: FilePath -> IO String -- readFile' fn = bracket (openFile fn ReadMode) hClose $ \h -> -- evaluate . force =<< hGetContents h --force :: NFData a => a -> a -- | the deep analogue of $!. In the expression f $!! x, -- x is fully evaluated before the function f is -- applied to it. ($!!) :: NFData a => (a -> b) -> a -> b infixr 0 $!! -- | deepseq: fully evaluates the first argument, before returning -- the second. -- -- The name deepseq is used to illustrate the relationship to -- seq: where seq is shallow in the sense that it only -- evaluates the top level of its argument, deepseq traverses the -- entire data structure evaluating it completely. -- -- deepseq can be useful for forcing pending exceptions, -- eradicating space leaks, or forcing lazy I/O to happen. It is also -- useful in conjunction with parallel Strategies (see the -- parallel package). -- -- There is no guarantee about the ordering of evaluation. The -- implementation may evaluate the components of the structure in any -- order or in parallel. To impose an actual order on evaluation, use -- pseq from Control.Parallel in the parallel -- package. deepseq :: NFData a => a -> b -> b -- | A set of values. A set cannot contain duplicate values. data HashSet a class (Vector Vector a, MVector MVector a) => Unbox a -- | Boxed vectors, supporting efficient slicing. data Vector a -- | The parameterizable reader monad. -- -- Computations are functions of a shared environment. -- -- The return function ignores the environment, while -- >>= passes the inherited environment to both -- subcomputations. type Reader r = ReaderT r Identity -- | lens creates a Lens from a getter and a setter. The -- resulting lens isn't the most effective one (because of having to -- traverse the structure twice when modifying), but it shouldn't matter -- much. -- -- A (partial) lens for list indexing: -- --
-- ix :: Int -> Lens' [a] a -- ix i = lens (!! i) -- getter -- (\s b -> take i s ++ b : drop (i+1) s) -- setter ---- -- Usage: -- --
-- >>> [1..9] ^. ix 3 -- 4 -- -- >>> [1..9] & ix 3 %~ negate -- [1,2,3,-4,5,6,7,8,9] ---- -- When getting, the setter is completely unused; when setting, the -- getter is unused. Both are used only when the value is being modified. -- For instance, here we define a lens for the 1st element of a list, but -- instead of a legitimate getter we use undefined. Then we use -- the resulting lens for setting and it works, which proves that -- the getter wasn't used: -- --
-- >>> [1,2,3] & lens undefined (\s b -> b : tail s) .~ 10 -- [10,2,3] --lens :: () => (s -> a) -> (s -> b -> t) -> Lens s t a b -- | to creates a getter from any function: -- --
-- a ^. to f = f a ---- -- It's most useful in chains, because it lets you mix lenses and -- ordinary functions. Suppose you have a record which comes from some -- third-party library and doesn't have any lens accessors. You want to -- do something like this: -- --
-- value ^. _1 . field . at 2 ---- -- However, field isn't a getter, and you have to do this -- instead: -- --
-- field (value ^. _1) ^. at 2 ---- -- but now value is in the middle and it's hard to read the -- resulting code. A variant with to is prettier and more -- readable: -- --
-- value ^. _1 . to field . at 2 --to :: () => (s -> a) -> SimpleGetter s a -- | (^.) applies a getter to a value; in other words, it gets a -- value out of a structure using a getter (which can be a lens, -- traversal, fold, etc.). -- -- Getting 1st field of a tuple: -- --
-- (^. _1) :: (a, b) -> a -- (^. _1) = fst ---- -- When (^.) is used with a traversal, it combines all results -- using the Monoid instance for the resulting type. For instance, -- for lists it would be simple concatenation: -- --
-- >>> ("str","ing") ^. each
-- "string"
--
--
-- The reason for this is that traversals use Applicative, and the
-- Applicative instance for Const uses monoid concatenation
-- to combine “effects” of Const.
--
-- A non-operator version of (^.) is called view, and
-- it's a bit more general than (^.) (it works in
-- MonadReader). If you need the general version, you can get it
-- from microlens-mtl; otherwise there's view available in
-- Lens.Micro.Extras.
(^.) :: () => s -> Getting a s a -> a
infixl 8 ^.
-- | set is a synonym for (.~).
--
-- Setting the 1st component of a pair:
--
-- -- set _1 :: x -> (a, b) -> (x, b) -- set _1 = \x t -> (x, snd t) ---- -- Using it to rewrite (<$): -- --
-- set mapped :: Functor f => a -> f b -> f a -- set mapped = (<$) --set :: () => ASetter s t a b -> b -> s -> t -- | over is a synonym for (%~). -- -- Getting fmap in a roundabout way: -- --
-- over mapped :: Functor f => (a -> b) -> f a -> f b -- over mapped = fmap ---- -- Applying a function to both components of a pair: -- --
-- over both :: (a -> b) -> (a, a) -> (b, b) -- over both = \f t -> (f (fst t), f (snd t)) ---- -- Using over _2 as a replacement for -- second: -- --
-- >>> over _2 show (10,20) -- (10,"20") --over :: () => ASetter s t a b -> (a -> b) -> s -> t -- | sets creates an ASetter from an ordinary function. (The -- only thing it does is wrapping and unwrapping Identity.) sets :: () => ((a -> b) -> s -> t) -> ASetter s t a b -- | ASetter s t a b is something that turns a function modifying -- a value into a function modifying a structure. If you ignore -- Identity (as Identity a is the same thing as -- a), the type is: -- --
-- type ASetter s t a b = (a -> b) -> s -> t ---- -- The reason Identity is used here is for ASetter to be -- composable with other types, such as Lens. -- -- Technically, if you're writing a library, you shouldn't use this type -- for setters you are exporting from your library; the right type to use -- is Setter, but it is not provided by this package -- (because then it'd have to depend on distributive). It's -- completely alright, however, to export functions which take an -- ASetter as an argument. type ASetter s t a b = a -> Identity b -> s -> Identity t -- | This is a type alias for monomorphic setters which don't change the -- type of the container (or of the value inside). It's useful more often -- than the same type in lens, because we can't provide real setters and -- so it does the job of both ASetter' and -- Setter'. type ASetter' s a = ASetter s s a a -- | A SimpleGetter s a extracts a from s; so, -- it's the same thing as (s -> a), but you can use it in -- lens chains because its type looks like this: -- --
-- type SimpleGetter s a = -- forall r. (a -> Const r a) -> s -> Const r s ---- -- Since Const r is a functor, SimpleGetter has the same -- shape as other lens types and can be composed with them. To get (s -- -> a) out of a SimpleGetter, choose r ~ a and -- feed Const :: a -> Const a a to the getter: -- --
-- -- the actual signature is more permissive: -- -- view :: Getting a s a -> s -> a -- view :: SimpleGetter s a -> s -> a -- view getter = getConst . getter Const ---- -- The actual Getter from lens is more general: -- --
-- type Getter s a = -- forall f. (Contravariant f, Functor f) => (a -> f a) -> s -> f s ---- -- I'm not currently aware of any functions that take lens's -- Getter but won't accept SimpleGetter, but you should -- try to avoid exporting SimpleGetters anyway to minimise -- confusion. Alternatively, look at microlens-contra, which -- provides a fully lens-compatible Getter. -- -- Lens users: you can convert a SimpleGetter to Getter -- by applying to . view to it. type SimpleGetter s a = forall r. () => Getting r s a -- | Functions that operate on getters and folds – such as (^.), -- (^..), (^?) – use Getter r s a (with different -- values of r) to describe what kind of result they need. For -- instance, (^.) needs the getter to be able to return a single -- value, and so it accepts a getter of type Getting a s a. -- (^..) wants the getter to gather values together, so it uses -- Getting (Endo [a]) s a (it could've used Getting [a] s -- a instead, but it's faster with Endo). The choice of -- r depends on what you want to do with elements you're -- extracting from s. type Getting r s a = a -> Const r a -> s -> Const r s -- | Lens s t a b is the lowest common denominator of a setter and -- a getter, something that has the power of both; it has a -- Functor constraint, and since both Const and -- Identity are functors, it can be used whenever a getter or a -- setter is needed. -- --
-- import Say -- -- action :: Int -> IO Int -- action n = do -- tid <- myThreadId -- sayString $ show tid -- threadDelay (2 * 10^6) -- 2 seconds -- return n -- -- main :: IO () -- main = do -- yx <- pooledMapConcurrentlyN 5 (\x -> action x) [1..5] -- print yx ---- -- On executing you can see that five threads have been spawned: -- --
-- $ ./pool -- ThreadId 36 -- ThreadId 38 -- ThreadId 40 -- ThreadId 42 -- ThreadId 44 -- [1,2,3,4,5] ---- -- Let's modify the above program such that there are less threads than -- the number of items in the list: -- --
-- import Say -- -- action :: Int -> IO Int -- action n = do -- tid <- myThreadId -- sayString $ show tid -- threadDelay (2 * 10^6) -- 2 seconds -- return n -- -- main :: IO () -- main = do -- yx <- pooledMapConcurrentlyN 3 (\x -> action x) [1..5] -- print yx ---- -- On executing you can see that only three threads are active totally: -- --
-- $ ./pool -- ThreadId 35 -- ThreadId 37 -- ThreadId 39 -- ThreadId 35 -- ThreadId 39 -- [1,2,3,4,5] --pooledMapConcurrentlyN :: (MonadUnliftIO m, Traversable t) => Int -> (a -> m b) -> t a -> m (t b) -- | Similar to pooledMapConcurrentlyN but with number of threads -- set from getNumCapabilities. Usually this is useful for CPU -- bound tasks. pooledMapConcurrently :: (MonadUnliftIO m, Traversable t) => (a -> m b) -> t a -> m (t b) -- | Similar to pooledMapConcurrentlyN but with flipped arguments. pooledForConcurrentlyN :: (MonadUnliftIO m, Traversable t) => Int -> t a -> (a -> m b) -> m (t b) -- | Similar to pooledForConcurrentlyN but with number of threads -- set from getNumCapabilities. Usually this is useful for CPU -- bound tasks. pooledForConcurrently :: (MonadUnliftIO m, Traversable t) => t a -> (a -> m b) -> m (t b) -- | Like pooledMapConcurrentlyN but with the return value -- discarded. pooledMapConcurrentlyN_ :: (MonadUnliftIO m, Foldable f) => Int -> (a -> m b) -> f a -> m () -- | Like pooledMapConcurrently but with the return value discarded. pooledMapConcurrently_ :: (MonadUnliftIO m, Foldable f) => (a -> m b) -> f a -> m () -- | Like pooledMapConcurrently_ but with flipped arguments. pooledForConcurrently_ :: (MonadUnliftIO m, Foldable f) => f a -> (a -> m b) -> m () -- | Like pooledMapConcurrentlyN_ but with flipped arguments. pooledForConcurrentlyN_ :: (MonadUnliftIO m, Foldable t) => Int -> t a -> (a -> m b) -> m () -- | Pooled version of replicateConcurrently. Performs the action in -- the pooled threads. pooledReplicateConcurrentlyN :: MonadUnliftIO m => Int -> Int -> m a -> m [a] -- | Similar to pooledReplicateConcurrentlyN but with number of -- threads set from getNumCapabilities. Usually this is useful for -- CPU bound tasks. pooledReplicateConcurrently :: MonadUnliftIO m => Int -> m a -> m [a] -- | Pooled version of replicateConcurrently_. Performs the action -- in the pooled threads. pooledReplicateConcurrentlyN_ :: MonadUnliftIO m => Int -> Int -> m a -> m () -- | Similar to pooledReplicateConcurrently_ but with number of -- threads set from getNumCapabilities. Usually this is useful for -- CPU bound tasks. pooledReplicateConcurrently_ :: MonadUnliftIO m => Int -> m a -> m () -- | Lifted newEmptyMVar. newEmptyMVar :: MonadIO m => m (MVar a) -- | Lifted newMVar. newMVar :: MonadIO m => a -> m (MVar a) -- | Lifted takeMVar. takeMVar :: MonadIO m => MVar a -> m a -- | Lifted putMVar. putMVar :: MonadIO m => MVar a -> a -> m () -- | Lifted readMVar. readMVar :: MonadIO m => MVar a -> m a -- | Lifted swapMVar. swapMVar :: MonadIO m => MVar a -> a -> m a -- | Lifted tryTakeMVar. tryTakeMVar :: MonadIO m => MVar a -> m (Maybe a) -- | Lifted tryPutMVar. tryPutMVar :: MonadIO m => MVar a -> a -> m Bool -- | Lifted isEmptyMVar. isEmptyMVar :: MonadIO m => MVar a -> m Bool -- | Lifted tryReadMVar. tryReadMVar :: MonadIO m => MVar a -> m (Maybe a) -- | Unlifted withMVar. withMVar :: MonadUnliftIO m => MVar a -> (a -> m b) -> m b -- | Unlifted withMVarMasked. withMVarMasked :: MonadUnliftIO m => MVar a -> (a -> m b) -> m b -- | Unlifted modifyMVar_. modifyMVar_ :: MonadUnliftIO m => MVar a -> (a -> m a) -> m () -- | Unlifted modifyMVar. modifyMVar :: MonadUnliftIO m => MVar a -> (a -> m (a, b)) -> m b -- | Unlifted modifyMVarMasked_. modifyMVarMasked_ :: MonadUnliftIO m => MVar a -> (a -> m a) -> m () -- | Unlifted modifyMVarMasked. modifyMVarMasked :: MonadUnliftIO m => MVar a -> (a -> m (a, b)) -> m b -- | Unlifted mkWeakMVar. mkWeakMVar :: MonadUnliftIO m => MVar a -> m () -> m (Weak (MVar a)) -- | A "run once" value, with results saved. Extract the value with -- runMemoized. For single-threaded usage, you can use -- memoizeRef to create a value. If you need guarantees that only -- one thread will run the action at a time, use memoizeMVar. -- -- Note that this type provides a Show instance for convenience, -- but not useful information can be provided. data Memoized a -- | Extract a value from a Memoized, running an action if no cached -- value is available. runMemoized :: MonadIO m => Memoized a -> m a -- | Create a new Memoized value using an IORef under the -- surface. Note that the action may be run in multiple threads -- simultaneously, so this may not be thread safe (depending on the -- underlying action). Consider using memoizeMVar. memoizeRef :: MonadUnliftIO m => m a -> m (Memoized a) -- | Same as memoizeRef, but uses an MVar to ensure that an -- action is only run once, even in a multithreaded application. memoizeMVar :: MonadUnliftIO m => m a -> m (Memoized a) -- | Lifted version of atomically atomically :: MonadIO m => STM a -> m a -- | Renamed retry for unqualified export retrySTM :: () => STM a -- | Renamed check for unqualified export checkSTM :: Bool -> STM () -- | Lifted version of newTVarIO newTVarIO :: MonadIO m => a -> m (TVar a) -- | Lifted version of readTVarIO readTVarIO :: MonadIO m => TVar a -> m a -- | Lifted version of registerDelay registerDelay :: MonadIO m => Int -> m (TVar Bool) -- | Lifted version of mkWeakTVar mkWeakTVar :: MonadUnliftIO m => TVar a -> m () -> m (Weak (TVar a)) -- | Lifted version of newTMVarIO newTMVarIO :: MonadIO m => a -> m (TMVar a) -- | Lifted version of newEmptyTMVarIO newEmptyTMVarIO :: MonadIO m => m (TMVar a) -- | Lifted version of mkWeakTMVar mkWeakTMVar :: MonadUnliftIO m => TMVar a -> m () -> m (Weak (TMVar a)) -- | Lifted version of newTChanIO newTChanIO :: MonadIO m => m (TChan a) -- | Lifted version of newBroadcastTChanIO newBroadcastTChanIO :: MonadIO m => m (TChan a) -- | Lifted version of newTQueueIO newTQueueIO :: MonadIO m => m (TQueue a) -- | Lifted version of newTBQueueIO newTBQueueIO :: MonadIO m => Natural -> m (TBQueue a) -- | Create and use a temporary file in the system standard temporary -- directory. -- -- Behaves exactly the same as withTempFile, except that the -- parent temporary directory will be that returned by -- getCanonicalTemporaryDirectory. withSystemTempFile :: MonadUnliftIO m => String -> (FilePath -> Handle -> m a) -> m a -- | Create and use a temporary directory in the system standard temporary -- directory. -- -- Behaves exactly the same as withTempDirectory, except that the -- parent temporary directory will be that returned by -- getCanonicalTemporaryDirectory. withSystemTempDirectory :: MonadUnliftIO m => String -> (FilePath -> m a) -> m a -- | Use a temporary filename that doesn't already exist. -- -- Creates a new temporary file inside the given directory, making use of -- the template. The temp file is deleted after use. For example: -- --
-- withTempFile "src" "sdist." $ \tmpFile hFile -> do ... ---- -- The tmpFile will be file in the given directory, e.g. -- src/sdist.342. withTempFile :: MonadUnliftIO m => FilePath -> String -> (FilePath -> Handle -> m a) -> m a -- | Create and use a temporary directory. -- -- Creates a new temporary directory inside the given directory, making -- use of the template. The temp directory is deleted after use. For -- example: -- --
-- withTempDirectory "src" "sdist." $ \tmpDir -> do ... ---- -- The tmpDir will be a new subdirectory of the given directory, -- e.g. src/sdist.342. withTempDirectory :: MonadUnliftIO m => FilePath -> String -> (FilePath -> m a) -> m a -- | A helper function for implementing MonadUnliftIO instances. -- Useful for the common case where you want to simply delegate to the -- underlying transformer. -- --
-- newtype AppT m a = AppT { unAppT :: ReaderT Int (ResourceT m) a }
-- deriving (Functor, Applicative, Monad, MonadIO)
-- -- Unfortunately, deriving MonadUnliftIO does not work.
--
-- instance MonadUnliftIO m => MonadUnliftIO (AppT m) where
-- withRunInIO = wrappedWithRunInIO AppT unAppT
--
wrappedWithRunInIO :: MonadUnliftIO n => (n b -> m b) -> (forall a. () => m a -> n a) -> ((forall a. () => m a -> IO a) -> IO b) -> m b
-- | Convert an action in m to an action in IO.
toIO :: MonadUnliftIO m => m a -> m (IO a)
-- | Convenience function for capturing the monadic context and running an
-- IO action. The UnliftIO newtype wrapper is rarely
-- needed, so prefer withRunInIO to this function.
withUnliftIO :: MonadUnliftIO m => (UnliftIO m -> IO a) -> m a
-- | Same as askUnliftIO, but returns a monomorphic function instead
-- of a polymorphic newtype wrapper. If you only need to apply the
-- transformation on one concrete type, this function can be more
-- convenient.
askRunInIO :: MonadUnliftIO m => m (m a -> IO a)
-- | The ability to run any monadic action m a as IO a.
--
-- This is more precisely a natural transformation. We need to new
-- datatype (instead of simply using a forall) due to lack of
-- support in GHC for impredicative types.
newtype UnliftIO (m :: Type -> Type)
UnliftIO :: (forall a. () => m a -> IO a) -> UnliftIO
[unliftIO] :: UnliftIO -> forall a. () => m a -> IO a
-- | TBQueue is an abstract type representing a bounded FIFO
-- channel.
data TBQueue a
-- | Builds and returns a new instance of TBQueue.
newTBQueue :: () => Natural -> STM (TBQueue a)
-- | Write a value to a TBQueue; blocks if the queue is full.
writeTBQueue :: () => TBQueue a -> a -> STM ()
-- | Read the next value from the TBQueue.
readTBQueue :: () => TBQueue a -> STM a
-- | A version of readTBQueue which does not retry. Instead it
-- returns Nothing if no value is available.
tryReadTBQueue :: () => TBQueue a -> STM (Maybe a)
-- | Get the next value from the TBQueue without removing it,
-- retrying if the channel is empty.
peekTBQueue :: () => TBQueue a -> STM a
-- | A version of peekTBQueue which does not retry. Instead it
-- returns Nothing if no value is available.
tryPeekTBQueue :: () => TBQueue a -> STM (Maybe a)
-- | Put a data item back onto a channel, where it will be the next item
-- read. Blocks if the queue is full.
unGetTBQueue :: () => TBQueue a -> a -> STM ()
-- | Returns True if the supplied TBQueue is empty.
isEmptyTBQueue :: () => TBQueue a -> STM Bool
-- | Returns True if the supplied TBQueue is full.
isFullTBQueue :: () => TBQueue a -> STM Bool
-- | TChan is an abstract type representing an unbounded FIFO
-- channel.
data TChan a
-- | Build and return a new instance of TChan
newTChan :: () => STM (TChan a)
-- | Create a write-only TChan. More precisely, readTChan
-- will retry even after items have been written to the channel.
-- The only way to read a broadcast channel is to duplicate it with
-- dupTChan.
--
-- Consider a server that broadcasts messages to clients:
--
-- -- serve :: TChan Message -> Client -> IO loop -- serve broadcastChan client = do -- myChan <- dupTChan broadcastChan -- forever $ do -- message <- readTChan myChan -- send client message ---- -- The problem with using newTChan to create the broadcast channel -- is that if it is only written to and never read, items will pile up in -- memory. By using newBroadcastTChan to create the broadcast -- channel, items can be garbage collected after clients have seen them. newBroadcastTChan :: () => STM (TChan a) -- | Write a value to a TChan. writeTChan :: () => TChan a -> a -> STM () -- | Read the next value from the TChan. readTChan :: () => TChan a -> STM a -- | A version of readTChan which does not retry. Instead it returns -- Nothing if no value is available. tryReadTChan :: () => TChan a -> STM (Maybe a) -- | Get the next value from the TChan without removing it, -- retrying if the channel is empty. peekTChan :: () => TChan a -> STM a -- | A version of peekTChan which does not retry. Instead it returns -- Nothing if no value is available. tryPeekTChan :: () => TChan a -> STM (Maybe a) -- | Duplicate a TChan: the duplicate channel begins empty, but data -- written to either channel from then on will be available from both. -- Hence this creates a kind of broadcast channel, where data written by -- anyone is seen by everyone else. dupTChan :: () => TChan a -> STM (TChan a) -- | Put a data item back onto a channel, where it will be the next item -- read. unGetTChan :: () => TChan a -> a -> STM () -- | Returns True if the supplied TChan is empty. isEmptyTChan :: () => TChan a -> STM Bool -- | Clone a TChan: similar to dupTChan, but the cloned channel -- starts with the same content available as the original channel. cloneTChan :: () => TChan a -> STM (TChan a) -- | A TMVar is a synchronising variable, used for communication -- between concurrent threads. It can be thought of as a box, which may -- be empty or full. data TMVar a -- | Create a TMVar which contains the supplied value. newTMVar :: () => a -> STM (TMVar a) -- | Create a TMVar which is initially empty. newEmptyTMVar :: () => STM (TMVar a) -- | Return the contents of the TMVar. If the TMVar is -- currently empty, the transaction will retry. After a -- takeTMVar, the TMVar is left empty. takeTMVar :: () => TMVar a -> STM a -- | A version of takeTMVar that does not retry. The -- tryTakeTMVar function returns Nothing if the -- TMVar was empty, or Just a if the TMVar -- was full with contents a. After tryTakeTMVar, the -- TMVar is left empty. tryTakeTMVar :: () => TMVar a -> STM (Maybe a) -- | Put a value into a TMVar. If the TMVar is currently -- full, putTMVar will retry. putTMVar :: () => TMVar a -> a -> STM () -- | A version of putTMVar that does not retry. The -- tryPutTMVar function attempts to put the value a into -- the TMVar, returning True if it was successful, or -- False otherwise. tryPutTMVar :: () => TMVar a -> a -> STM Bool -- | This is a combination of takeTMVar and putTMVar; ie. it -- takes the value from the TMVar, puts it back, and also returns -- it. readTMVar :: () => TMVar a -> STM a -- | A version of readTMVar which does not retry. Instead it returns -- Nothing if no value is available. tryReadTMVar :: () => TMVar a -> STM (Maybe a) -- | Swap the contents of a TMVar for a new value. swapTMVar :: () => TMVar a -> a -> STM a -- | Check whether a given TMVar is empty. isEmptyTMVar :: () => TMVar a -> STM Bool -- | TQueue is an abstract type representing an unbounded FIFO -- channel. data TQueue a -- | Build and returns a new instance of TQueue newTQueue :: () => STM (TQueue a) -- | Write a value to a TQueue. writeTQueue :: () => TQueue a -> a -> STM () -- | Read the next value from the TQueue. readTQueue :: () => TQueue a -> STM a -- | A version of readTQueue which does not retry. Instead it -- returns Nothing if no value is available. tryReadTQueue :: () => TQueue a -> STM (Maybe a) -- | Get the next value from the TQueue without removing it, -- retrying if the channel is empty. peekTQueue :: () => TQueue a -> STM a -- | A version of peekTQueue which does not retry. Instead it -- returns Nothing if no value is available. tryPeekTQueue :: () => TQueue a -> STM (Maybe a) -- | Put a data item back onto a channel, where it will be the next item -- read. unGetTQueue :: () => TQueue a -> a -> STM () -- | Returns True if the supplied TQueue is empty. isEmptyTQueue :: () => TQueue a -> STM Bool -- | Mutate the contents of a TVar. N.B., this version is -- non-strict. modifyTVar :: () => TVar a -> (a -> a) -> STM () -- | Strict version of modifyTVar. modifyTVar' :: () => TVar a -> (a -> a) -> STM () -- | Swap the contents of a TVar for a new value. swapTVar :: () => TVar a -> a -> STM a traceDisplayStack :: Display a => a -> b -> b traceDisplayMarkerIO :: (Display a, MonadIO m) => a -> m () traceDisplayMarker :: Display a => a -> b -> b traceDisplayEventIO :: (Display a, MonadIO m) => a -> m () traceDisplayEvent :: Display a => a -> b -> b traceDisplayM :: (Display a, Applicative f) => a -> f () traceDisplayIO :: (Display a, MonadIO m) => a -> m () traceDisplayId :: Display a => a -> a traceDisplay :: Display a => a -> b -> b traceShowStack :: Show a => a -> b -> b traceShowMarkerIO :: (Show a, MonadIO m) => a -> m () traceShowMarker :: Show a => a -> b -> b traceShowEventIO :: (Show a, MonadIO m) => a -> m () traceShowEvent :: Show a => a -> b -> b traceShowM :: (Show a, Applicative f) => a -> f () traceShowIO :: (Show a, MonadIO m) => a -> m () traceShowId :: Show a => a -> a traceShow :: Show a => a -> b -> b traceStack :: () => Text -> a -> a traceMarkerIO :: MonadIO m => Text -> m () traceMarker :: () => Text -> a -> a traceEventIO :: MonadIO m => Text -> m () traceEvent :: () => Text -> a -> a traceM :: Applicative f => Text -> f () traceIO :: MonadIO m => Text -> m () traceId :: Text -> Text trace :: () => Text -> a -> a -- | Run with a default configured SimpleApp, consisting of: -- --
-- >>> :set -XTypeApplications -- -- >>> import qualified RIO.Vector.Unboxed as U -- -- >>> d <- newDeque @U.MVector @Int -- -- >>> mapM_ (pushFrontDeque d) [0..10] -- -- >>> freezeDeque @U.Vector d -- [10,9,8,7,6,5,4,3,2,1,0] --freezeDeque :: (Vector v a, PrimMonad m) => Deque (Mutable v) (PrimState m) a -> m (v a) -- | Convert to an immutable vector of any type. If resulting pure vector -- corresponds to the mutable one used by the Deque, it will be -- more efficient to use freezeDeque instead. -- --
-- >>> :set -XTypeApplications -- -- >>> import qualified RIO.Vector.Unboxed as U -- -- >>> import qualified RIO.Vector.Storable as S -- -- >>> d <- newDeque @U.MVector @Int -- -- >>> mapM_ (pushFrontDeque d) [0..10] -- -- >>> dequeToVector @S.Vector d -- [10,9,8,7,6,5,4,3,2,1,0] --dequeToVector :: (Vector v' a, MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m (v' a) -- | Convert a Deque into a list. Does not modify the Deque. dequeToList :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m [a] -- | Fold over a Deque, starting at the end. Does not modify the -- Deque. foldrDeque :: (MVector v a, PrimMonad m) => (a -> acc -> m acc) -> acc -> Deque v (PrimState m) a -> m acc -- | Fold over a Deque, starting at the beginning. Does not modify -- the Deque. foldlDeque :: (MVector v a, PrimMonad m) => (acc -> a -> m acc) -> acc -> Deque v (PrimState m) a -> m acc -- | Push a new value to the end of the Deque pushBackDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> a -> m () -- | Push a new value to the beginning of the Deque pushFrontDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> a -> m () -- | Pop the first value from the end of the Deque popBackDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m (Maybe a) -- | Pop the first value from the beginning of the Deque popFrontDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m (Maybe a) -- | O(1) - Get the number of elements that is currently in the -- Deque getDequeSize :: PrimMonad m => Deque v (PrimState m) a -> m Int -- | Create a new, empty Deque newDeque :: (MVector v a, PrimMonad m) => m (Deque v (PrimState m) a) -- | Helper function to assist with type inference, forcing usage of a -- boxed vector. asBDeque :: () => BDeque s a -> BDeque s a -- | Helper function to assist with type inference, forcing usage of a -- storable vector. asSDeque :: () => SDeque s a -> SDeque s a -- | Helper function to assist with type inference, forcing usage of an -- unboxed vector. asUDeque :: () => UDeque s a -> UDeque s a -- | A double-ended queue supporting any underlying vector type and any -- monad. -- -- This implements a circular double-ended queue with exponential growth. data Deque (v :: Type -> Type -> Type) s a -- | A Deque specialized to unboxed vectors. type UDeque = Deque MVector -- | A Deque specialized to storable vectors. type SDeque = Deque MVector -- | A Deque specialized to boxed vectors. type BDeque = Deque MVector -- | Read a file in UTF8 encoding, throwing an exception on invalid -- character encoding. -- -- This function will use OS-specific line ending handling. readFileUtf8 :: MonadIO m => FilePath -> m Text -- | Same as writeFile, but generalized to MonadIO writeFileBinary :: MonadIO m => FilePath -> ByteString -> m () -- | Same as readFile, but generalized to MonadIO readFileBinary :: MonadIO m => FilePath -> m ByteString hPutBuilder :: MonadIO m => Handle -> Builder -> m () -- | Write a file in UTF8 encoding -- -- This function will use OS-specific line ending handling. writeFileUtf8 :: MonadIO m => FilePath -> Text -> m () -- | Lazily get the contents of a file. Unlike readFile, this -- ensures that if an exception is thrown, the file handle is closed -- immediately. withLazyFile :: MonadUnliftIO m => FilePath -> (ByteString -> m a) -> m a -- | Disable logging capabilities in a given sub-routine -- -- Intended to skip logging in general purpose implementations, where -- secrets might be logged accidently. noLogging :: (HasLogFunc env, MonadReader env m) => m a -> m a -- | Is the log func configured to use color output? -- -- Intended for use by code which wants to optionally add additional -- color to its log messages. logFuncUseColorL :: HasLogFunc env => SimpleGetter env Bool -- | Convert a CallStack value into a Utf8Builder indicating -- the first source location. -- -- TODO Consider showing the entire call stack instead. displayCallStack :: CallStack -> Utf8Builder -- | Set format method for messages -- -- Default: id setLogFormat :: (Utf8Builder -> Utf8Builder) -> LogOptions -> LogOptions -- | Use code location in the log output. -- -- Default: True if in verbose mode, False otherwise. setLogUseLoc :: Bool -> LogOptions -> LogOptions -- | Use ANSI color codes in the log output. -- -- Default: True if in verbose mode and the Handle -- is a terminal device. setLogUseColor :: Bool -> LogOptions -> LogOptions -- | Include the time when printing log messages. -- -- Default: True in debug mode, False otherwise. setLogUseTime :: Bool -> LogOptions -> LogOptions -- | Do we treat output as a terminal. If True, we will enabled -- sticky logging functionality. -- -- Default: checks if the Handle provided to -- logOptionsHandle is a terminal with hIsTerminalDevice. setLogTerminal :: Bool -> LogOptions -> LogOptions -- | Refer to setLogVerboseFormat. This modifier allows to alter the -- verbose format value dynamically at runtime. -- -- Default: follows the value of the verbose flag. setLogVerboseFormatIO :: IO Bool -> LogOptions -> LogOptions -- | Use the verbose format for printing log messages. -- -- Default: follows the value of the verbose flag. setLogVerboseFormat :: Bool -> LogOptions -> LogOptions -- | Refer to setLogMinLevel. This modifier allows to alter the -- verbose format value dynamically at runtime. -- -- Default: in verbose mode, LevelDebug. Otherwise, -- LevelInfo. setLogMinLevelIO :: IO LogLevel -> LogOptions -> LogOptions -- | Set the minimum log level. Messages below this level will not be -- printed. -- -- Default: in verbose mode, LevelDebug. Otherwise, -- LevelInfo. setLogMinLevel :: LogLevel -> LogOptions -> LogOptions -- | Given a LogOptions value, run the given function with the -- specified LogFunc. A common way to use this function is: -- --
-- let isVerbose = False -- get from the command line instead
-- logOptions' <- logOptionsHandle stderr isVerbose
-- let logOptions = setLogUseTime True logOptions'
-- withLogFunc logOptions $ \lf -> do
-- let app = App -- application specific environment
-- { appLogFunc = lf
-- , appOtherStuff = ...
-- }
-- runRIO app $ do
-- logInfo "Starting app"
-- myApp
--
withLogFunc :: MonadUnliftIO m => LogOptions -> (LogFunc -> m a) -> m a
-- | Given a LogOptions value, returns both a new LogFunc and
-- a sub-routine that disposes it.
--
-- Intended for use if you want to deal with the teardown of
-- LogFunc yourself, otherwise prefer the withLogFunc
-- function instead.
newLogFunc :: (MonadIO n, MonadIO m) => LogOptions -> n (LogFunc, m ())
-- | Create a LogOptions value from the given Handle and
-- whether to perform verbose logging or not. Individiual settings can be
-- overridden using appropriate set functions.
--
-- When Verbose Flag is True, the following happens:
--
-- -- forMaybeM == flip mapMaybeM --forMaybeM :: Monad m => [a] -> (a -> m (Maybe b)) -> m [b] -- | Monadic mapMaybe. mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b] -- |
-- forMaybeA == flip mapMaybeA --forMaybeA :: Applicative f => [a] -> (a -> f (Maybe b)) -> f [b] -- | Applicative mapMaybe. mapMaybeA :: Applicative f => (a -> f (Maybe b)) -> [a] -> f [b] -- | Get a First value with a default fallback fromFirst :: () => a -> First a -> a -- | Apply a function to a Left constructor mapLeft :: () => (a1 -> a2) -> Either a1 b -> Either a2 b -- | Lifted version of "System.Exit.exitWith". -- -- @since 0.1.9.0. exitWith :: MonadIO m => ExitCode -> m a -- | Lifted version of "System.Exit.exitSuccess". -- -- @since 0.1.9.0. exitSuccess :: MonadIO m => m a -- | Lifted version of "System.Exit.exitFailure". -- -- @since 0.1.9.0. exitFailure :: MonadIO m => m a -- | Write the given Utf8Builder value to a file. writeFileUtf8Builder :: MonadIO m => FilePath -> Utf8Builder -> m () -- | Convert a Utf8Builder value into a lazy Text. utf8BuilderToLazyText :: Utf8Builder -> Text -- | Convert a Utf8Builder value into a strict Text. utf8BuilderToText :: Utf8Builder -> Text -- | Convert a ByteString into a Utf8Builder. -- -- NOTE This function performs no checks to ensure that the data -- is, in fact, UTF8 encoded. If you provide non-UTF8 data, later -- functions may fail. displayBytesUtf8 :: ByteString -> Utf8Builder -- | Use the Show instance for a value to convert it to a -- Utf8Builder. displayShow :: Show a => a -> Utf8Builder -- | A builder of binary data, with the invariant that the underlying data -- is supposed to be UTF-8 encoded. newtype Utf8Builder Utf8Builder :: Builder -> Utf8Builder [getUtf8Builder] :: Utf8Builder -> Builder -- | A typeclass for values which can be converted to a Utf8Builder. -- The intention of this typeclass is to provide a human-friendly display -- of the data. class Display a display :: Display a => a -> Utf8Builder -- | Display data as Text, which will also be used for -- display if it is not overriden. textDisplay :: Display a => a -> Text -- | Unlifted version of withBinaryFile. withBinaryFile :: MonadUnliftIO m => FilePath -> IOMode -> (Handle -> m a) -> m a -- | Lifted version of myThreadId. myThreadId :: MonadIO m => m ThreadId -- | Lifted version of threadDelay. threadDelay :: MonadIO m => Int -> m () -- | Lifted version of threadWaitRead. threadWaitRead :: MonadIO m => Fd -> m () -- | Lifted version of threadWaitWrite. threadWaitWrite :: MonadIO m => Fd -> m () -- | Lifted version of isCurrentThreadBound. isCurrentThreadBound :: MonadIO m => m Bool -- | An exception type for representing Unicode encoding errors. data UnicodeException -- | Could not decode a byte sequence because it was invalid under the -- given encoding, or ran out of input in mid-decode. DecodeError :: String -> Maybe Word8 -> UnicodeException -- | Tried to encode a character that could not be represented under the -- given encoding, or ran out of input in mid-encode. EncodeError :: String -> Maybe Char -> UnicodeException -- | Replace an invalid input byte with the Unicode replacement character -- U+FFFD. lenientDecode :: OnDecodeError -- | Decode a ByteString containing UTF-8 encoded text. -- -- NOTE: The replacement character returned by -- OnDecodeError MUST be within the BMP plane; surrogate code -- points will automatically be remapped to the replacement char -- U+FFFD (since 0.11.3.0), whereas code points beyond -- the BMP will throw an error (since 1.2.3.1); For earlier -- versions of text using those unsupported code points would -- result in undefined behavior. decodeUtf8With :: OnDecodeError -> ByteString -> Text -- | Decode a ByteString containing UTF-8 encoded text. -- -- If the input contains any invalid UTF-8 data, the relevant exception -- will be returned, otherwise the decoded text. decodeUtf8' :: ByteString -> Either UnicodeException Text -- | Encode text to a ByteString Builder using UTF-8 encoding. encodeUtf8Builder :: Text -> Builder -- | Encode text using UTF-8 encoding. encodeUtf8 :: Text -> ByteString identity :: a -> a logInfo :: (ToLogStr msg, MonadLogger m) => msg -> m () logDebug :: (ToLogStr msg, MonadLogger m) => msg -> m () logWarn :: (ToLogStr msg, MonadLogger m) => msg -> m () logError :: (ToLogStr msg, MonadLogger m) => msg -> m () logOther :: (ToLogStr msg, MonadLogger m) => LogLevel -> msg -> m () module Network.IPFS.Peer.Error data Error DecodeFailure :: String -> Error CannotConnect :: Peer -> Error UnknownErr :: Text -> Error instance GHC.Show.Show Network.IPFS.Peer.Error.Error instance GHC.Generics.Generic Network.IPFS.Peer.Error.Error instance GHC.Classes.Eq Network.IPFS.Peer.Error.Error instance GHC.Exception.Type.Exception Network.IPFS.Peer.Error.Error instance RIO.Prelude.Display.Display Network.IPFS.Peer.Error.Error module Network.IPFS.Path.Types -- | CID path -- -- Exmaple -- --
-- "QmcaHAFzUPRCRaUK12dC6YyhcqEEtdfg94XrPwgCxZ1ihD/myfile.txt" --newtype Path Path :: Text -> Path [$sel:unpath:Path] :: Path -> Text instance Data.Swagger.Internal.Schema.ToSchema Network.IPFS.Path.Types.Path instance Web.Internal.HttpApiData.ToHttpApiData Network.IPFS.Path.Types.Path instance Data.String.IsString Network.IPFS.Path.Types.Path instance GHC.Classes.Ord Network.IPFS.Path.Types.Path instance GHC.Show.Show Network.IPFS.Path.Types.Path instance GHC.Generics.Generic Network.IPFS.Path.Types.Path instance GHC.Classes.Eq Network.IPFS.Path.Types.Path instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.PlainText Network.IPFS.Path.Types.Path instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.OctetStream Network.IPFS.Path.Types.Path module Network.IPFS.Name.Types newtype Name Name :: String -> Name [$sel:unName:Name] :: Name -> String instance Data.Swagger.Internal.ParamSchema.ToParamSchema Network.IPFS.Name.Types.Name instance Data.Swagger.Internal.Schema.ToSchema Network.IPFS.Name.Types.Name instance Data.String.IsString Network.IPFS.Name.Types.Name instance GHC.Classes.Ord Network.IPFS.Name.Types.Name instance GHC.Show.Show Network.IPFS.Name.Types.Name instance GHC.Generics.Generic Network.IPFS.Name.Types.Name instance GHC.Classes.Eq Network.IPFS.Name.Types.Name instance RIO.Prelude.Display.Display Network.IPFS.Name.Types.Name instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.Name.Types.Name instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.Name.Types.Name instance Web.Internal.HttpApiData.FromHttpApiData Network.IPFS.Name.Types.Name module Network.IPFS.Internal.Orphanage.Natural instance RIO.Prelude.Display.Display GHC.Natural.Natural instance System.Envy.Var GHC.Natural.Natural module Network.IPFS.Internal.Orphanage.ByteString.Lazy instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.PlainText Data.ByteString.Lazy.Internal.ByteString instance Data.Aeson.Types.FromJSON.FromJSON Data.ByteString.Internal.ByteString module Network.IPFS.Info.Types data Info Info :: Text -> Text -> [Peer] -> Text -> Text -> Info [$sel:id:Info] :: Info -> Text [$sel:publicKey:Info] :: Info -> Text [$sel:addresses:Info] :: Info -> [Peer] [$sel:agentVersion:Info] :: Info -> Text [$sel:protocolVersion:Info] :: Info -> Text instance GHC.Classes.Eq Network.IPFS.Info.Types.Info instance GHC.Show.Show Network.IPFS.Info.Types.Info instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.Info.Types.Info module Network.IPFS.Gateway.Types -- | Type safety wrapper for IPFS Gateway Used as cname value for DNS -- updates newtype Gateway Gateway :: Text -> Gateway [$sel:getGateway:Gateway] :: Gateway -> Text instance Data.String.IsString Network.IPFS.Gateway.Types.Gateway instance Data.Swagger.Internal.Schema.ToSchema Network.IPFS.Gateway.Types.Gateway instance GHC.Show.Show Network.IPFS.Gateway.Types.Gateway instance GHC.Generics.Generic Network.IPFS.Gateway.Types.Gateway instance GHC.Classes.Eq Network.IPFS.Gateway.Types.Gateway instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.Gateway.Types.Gateway -- | File types module Network.IPFS.File.Types -- | A file serialized as a lazy bytestring newtype Serialized Serialized :: ByteString -> Serialized [$sel:unserialize:Serialized] :: Serialized -> ByteString instance Data.String.IsString Network.IPFS.File.Types.Serialized instance GHC.Show.Show Network.IPFS.File.Types.Serialized instance GHC.Classes.Eq Network.IPFS.File.Types.Serialized instance Data.Swagger.Internal.Schema.ToSchema Network.IPFS.File.Types.Serialized instance RIO.Prelude.Display.Display Network.IPFS.File.Types.Serialized instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.PlainText Network.IPFS.File.Types.Serialized instance Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.PlainText Network.IPFS.File.Types.Serialized instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.OctetStream Network.IPFS.File.Types.Serialized instance Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.OctetStream Network.IPFS.File.Types.Serialized module Network.IPFS.Client.Param type CID = QueryParam' '[Required, Strict] "arg" Text type IsRecursive = QueryFlag "recursive" module Network.IPFS.Client.Cat type API = CID :> Get '[PlainText] Serialized module Network.IPFS.Client.Error.Types data ErrorBody ErrorBody :: String -> ErrorBody [$sel:message:ErrorBody] :: ErrorBody -> String instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.Client.Error.Types.ErrorBody module Network.IPFS.CID.Types newtype CID CID :: Text -> CID [$sel:unaddress:CID] :: CID -> Text -- | Smart constructor for CID mkCID :: Text -> CID instance Web.Internal.HttpApiData.ToHttpApiData Network.IPFS.CID.Types.CID instance Data.String.IsString Network.IPFS.CID.Types.CID instance Data.Swagger.Internal.ParamSchema.ToParamSchema Network.IPFS.CID.Types.CID instance GHC.Show.Show Network.IPFS.CID.Types.CID instance GHC.Read.Read Network.IPFS.CID.Types.CID instance GHC.Classes.Ord Network.IPFS.CID.Types.CID instance GHC.Generics.Generic Network.IPFS.CID.Types.CID instance GHC.Classes.Eq Network.IPFS.CID.Types.CID instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.CID.Types.CID instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.CID.Types.CID instance Data.Swagger.Internal.Schema.ToSchema Network.IPFS.CID.Types.CID instance RIO.Prelude.Display.Display Network.IPFS.CID.Types.CID instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.PlainText Network.IPFS.CID.Types.CID instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.OctetStream Network.IPFS.CID.Types.CID instance Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.PlainText Network.IPFS.CID.Types.CID instance Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.PlainText [Network.IPFS.CID.Types.CID] instance Web.Internal.HttpApiData.FromHttpApiData Network.IPFS.CID.Types.CID module Network.IPFS.Client.Pin type API = AddAPI :<|> RemoveAPI type AddAPI = "add" :> CID :> Put '[JSON] Response type RemoveAPI = "rm" :> CID :> IsRecursive :> Delete '[JSON] Response newtype Response Response :: [CID] -> Response [$sel:cids:Response] :: Response -> [CID] instance GHC.Show.Show Network.IPFS.Client.Pin.Response instance GHC.Classes.Eq Network.IPFS.Client.Pin.Response instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.Client.Pin.Response module Network.IPFS.Client.Add type API = ReqBody '[PlainText] ByteString :> Post '[PlainText] CID module Network.IPFS.Client type API = "api" :> "v0" :> V0API add :: ByteString -> ClientM CID cat :: Text -> ClientM Serialized pin :: Text -> ClientM Response unpin :: Text -> Bool -> ClientM Response module Network.IPFS.BinPath.Types -- | Path to the IPFS binary newtype BinPath BinPath :: FilePath -> BinPath [$sel:getBinPath:BinPath] :: BinPath -> FilePath instance Data.String.IsString Network.IPFS.BinPath.Types.BinPath instance GHC.Generics.Generic Network.IPFS.BinPath.Types.BinPath instance GHC.Show.Show Network.IPFS.BinPath.Types.BinPath instance System.Envy.FromEnv Network.IPFS.BinPath.Types.BinPath instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.BinPath.Types.BinPath module Network.IPFS.Process.Types type Opt = String type Command = String type StreamIn stdin = StreamSpec 'STInput stdin type StreamOut stdout = StreamSpec 'STOutput stdout type RawMessage = ByteString module Network.IPFS.Process.Error data Error Timeout :: Natural -> Error UnknownErr :: RawMessage -> Error type RawMessage = ByteString instance GHC.Show.Show Network.IPFS.Process.Error.Error instance GHC.Generics.Generic Network.IPFS.Process.Error.Error instance GHC.Classes.Eq Network.IPFS.Process.Error.Error instance GHC.Exception.Type.Exception Network.IPFS.Process.Error.Error instance RIO.Prelude.Display.Display Network.IPFS.Process.Error.Error module Network.IPFS.Process runProc :: (MonadRIO cfg m, HasProcessContext cfg, HasLogFunc cfg) => (ProcessConfig stdin stdout () -> m a) -> FilePath -> StreamIn stdin -> StreamOut stdout -> [Opt] -> m a module Network.IPFS.SparseTree.Types -- | Directory structure for CIDs and other identifiers -- -- Examples: -- --
-- Content "abcdef" ---- --
-- show $ Directory [(Key "abcdef", Stub "myfile.txt")])] ---- -- "abcdef/myfile.txt" data SparseTree Stub :: Name -> SparseTree Content :: CID -> SparseTree Directory :: Map Tag SparseTree -> SparseTree data Tag Key :: Name -> Tag Hash :: CID -> Tag instance GHC.Show.Show Network.IPFS.SparseTree.Types.SparseTree instance GHC.Generics.Generic Network.IPFS.SparseTree.Types.SparseTree instance GHC.Classes.Eq Network.IPFS.SparseTree.Types.SparseTree instance GHC.Show.Show Network.IPFS.SparseTree.Types.Tag instance GHC.Classes.Ord Network.IPFS.SparseTree.Types.Tag instance GHC.Generics.Generic Network.IPFS.SparseTree.Types.Tag instance GHC.Classes.Eq Network.IPFS.SparseTree.Types.Tag instance Data.Swagger.Internal.Schema.ToSchema Network.IPFS.SparseTree.Types.SparseTree instance RIO.Prelude.Display.Display (Data.Map.Internal.Map Network.IPFS.SparseTree.Types.Tag Network.IPFS.SparseTree.Types.SparseTree) instance RIO.Prelude.Display.Display Network.IPFS.SparseTree.Types.SparseTree instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.SparseTree.Types.SparseTree instance RIO.Prelude.Display.Display Network.IPFS.SparseTree.Types.Tag instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.SparseTree.Types.Tag instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.SparseTree.Types.Tag instance Data.Aeson.Types.FromJSON.FromJSONKey Network.IPFS.SparseTree.Types.Tag instance Data.Aeson.Types.ToJSON.ToJSONKey Network.IPFS.SparseTree.Types.Tag instance Data.Swagger.Internal.Schema.ToSchema Network.IPFS.SparseTree.Types.Tag instance Web.Internal.HttpApiData.FromHttpApiData Network.IPFS.SparseTree.Types.Tag module Network.IPFS.Timeout.Types newtype Timeout Timeout :: Natural -> Timeout [$sel:getSeconds:Timeout] :: Timeout -> Natural instance GHC.Num.Num Network.IPFS.Timeout.Types.Timeout instance GHC.Generics.Generic Network.IPFS.Timeout.Types.Timeout instance GHC.Show.Show Network.IPFS.Timeout.Types.Timeout instance GHC.Classes.Eq Network.IPFS.Timeout.Types.Timeout instance System.Envy.FromEnv Network.IPFS.Timeout.Types.Timeout instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.Timeout.Types.Timeout module Network.IPFS.URL.Types -- | IPFS client URL newtype URL URL :: BaseUrl -> URL [$sel:getURL:URL] :: URL -> BaseUrl instance Data.Aeson.Types.FromJSON.FromJSON Network.IPFS.URL.Types.URL instance GHC.Show.Show Network.IPFS.URL.Types.URL instance GHC.Generics.Generic Network.IPFS.URL.Types.URL instance GHC.Classes.Eq Network.IPFS.URL.Types.URL -- | Types related to IPFS module Network.IPFS.Types -- | Path to the IPFS binary newtype BinPath BinPath :: FilePath -> BinPath [$sel:getBinPath:BinPath] :: BinPath -> FilePath newtype CID CID :: Text -> CID [$sel:unaddress:CID] :: CID -> Text -- | Smart constructor for CID mkCID :: Text -> CID newtype Name Name :: String -> Name [$sel:unName:Name] :: Name -> String type Opt = String type Command = String type RawMessage = ByteString newtype Peer Peer :: Text -> Peer [$sel:peer:Peer] :: Peer -> Text -- | CID path -- -- Exmaple -- --
-- "QmcaHAFzUPRCRaUK12dC6YyhcqEEtdfg94XrPwgCxZ1ihD/myfile.txt" --newtype Path Path :: Text -> Path [$sel:unpath:Path] :: Path -> Text -- | Directory structure for CIDs and other identifiers -- -- Examples: -- --
-- Content "abcdef" ---- --
-- show $ Directory [(Key "abcdef", Stub "myfile.txt")])] ---- -- "abcdef/myfile.txt" data SparseTree Stub :: Name -> SparseTree Content :: CID -> SparseTree Directory :: Map Tag SparseTree -> SparseTree data Tag Key :: Name -> Tag Hash :: CID -> Tag newtype Timeout Timeout :: Natural -> Timeout [$sel:getSeconds:Timeout] :: Timeout -> Natural -- | IPFS client URL newtype URL URL :: BaseUrl -> URL [$sel:getURL:URL] :: URL -> BaseUrl type Ignored = [Pattern] -- | Type safety wrapper for IPFS Gateway Used as cname value for DNS -- updates newtype Gateway Gateway :: Text -> Gateway [$sel:getGateway:Gateway] :: Gateway -> Text data ErrorBody ErrorBody :: String -> ErrorBody [$sel:message:ErrorBody] :: ErrorBody -> String module Network.IPFS.Remote.Class class Monad m => MonadRemoteIPFS m runRemote :: MonadRemoteIPFS m => ClientM a -> m (Either ClientError a) ipfsAdd :: MonadRemoteIPFS m => ByteString -> m (Either ClientError CID) ipfsCat :: MonadRemoteIPFS m => CID -> m (Either ClientError Serialized) ipfsPin :: MonadRemoteIPFS m => CID -> m (Either ClientError Response) ipfsUnpin :: MonadRemoteIPFS m => CID -> Bool -> m (Either ClientError Response) module Network.IPFS.Local.Class class Monad m => MonadLocalIPFS m runLocal :: MonadLocalIPFS m => [Opt] -> ByteString -> m (Either Error RawMessage) module Network.IPFS.Peer all :: MonadLocalIPFS m => m (Either Error [Peer]) rawList :: MonadLocalIPFS m => m (Either Error RawMessage) connect :: MonadLocalIPFS m => Peer -> m (Either Error ()) connectRetry :: MonadLocalIPFS m => Peer -> Int -> m (Either Error ()) -- | Get all external ipfs peer addresses getExternalAddress :: MonadLocalIPFS m => m (Either Error [Peer]) module Network.IPFS class Monad m => MonadLocalIPFS m runLocal :: MonadLocalIPFS m => [Opt] -> ByteString -> m (Either Error RawMessage) class Monad m => MonadRemoteIPFS m runRemote :: MonadRemoteIPFS m => ClientM a -> m (Either ClientError a) ipfsAdd :: MonadRemoteIPFS m => ByteString -> m (Either ClientError CID) ipfsCat :: MonadRemoteIPFS m => CID -> m (Either ClientError Serialized) ipfsPin :: MonadRemoteIPFS m => CID -> m (Either ClientError Response) ipfsUnpin :: MonadRemoteIPFS m => CID -> Bool -> m (Either ClientError Response) module Network.IPFS.Get.Error data Error InvalidCID :: Text -> Error TimedOut :: CID -> Natural -> Error UnexpectedOutput :: Text -> Error UnknownErr :: Text -> Error instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.Get.Error.Error instance GHC.Show.Show Network.IPFS.Get.Error.Error instance GHC.Generics.Generic Network.IPFS.Get.Error.Error instance GHC.Classes.Eq Network.IPFS.Get.Error.Error instance GHC.Exception.Type.Exception Network.IPFS.Get.Error.Error instance RIO.Prelude.Display.Display Network.IPFS.Get.Error.Error module Network.IPFS.Stat getSize :: MonadLocalIPFS m => CID -> m (Either Error Integer) module Network.IPFS.Add.Error data Error InvalidFile :: Error UnexpectedOutput :: Text -> Error RecursiveAddErr :: Error -> Error IPFSDaemonErr :: Text -> Error UnknownAddErr :: Text -> Error instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.Add.Error.Error instance GHC.Show.Show Network.IPFS.Add.Error.Error instance GHC.Generics.Generic Network.IPFS.Add.Error.Error instance GHC.Classes.Eq Network.IPFS.Add.Error.Error instance GHC.Exception.Type.Exception Network.IPFS.Add.Error.Error instance RIO.Prelude.Display.Display Network.IPFS.Add.Error.Error module Network.IPFS.Pin -- | Pin a CID add :: (MonadRIO cfg m, MonadRemoteIPFS m, MonadLogger m) => CID -> m (Either Error CID) -- | Unpin a CID rm :: (MonadRIO cfg m, MonadRemoteIPFS m, MonadLogger m) => CID -> m (Either Error CID) module Network.IPFS.Get getFile :: MonadLocalIPFS m => CID -> m (Either Error Serialized) getFileOrDirectory :: MonadLocalIPFS m => CID -> m (Either Error ByteString) module Network.IPFS.Error data Error AddErr :: Error -> Error GetErr :: Error -> Error LinearizationErr :: Linearization -> Error newtype Linearization NonLinear :: SparseTree -> Linearization instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.Error.Error instance GHC.Show.Show Network.IPFS.Error.Error instance GHC.Generics.Generic Network.IPFS.Error.Error instance GHC.Classes.Eq Network.IPFS.Error.Error instance GHC.Exception.Type.Exception Network.IPFS.Error.Error instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.Error.Linearization instance GHC.Exception.Type.Exception Network.IPFS.Error.Linearization instance GHC.Show.Show Network.IPFS.Error.Linearization instance GHC.Generics.Generic Network.IPFS.Error.Linearization instance GHC.Classes.Eq Network.IPFS.Error.Linearization instance RIO.Prelude.Display.Display Network.IPFS.Error.Linearization module Network.IPFS.SparseTree -- | Directory structure for CIDs and other identifiers -- -- Examples: -- --
-- Content "abcdef" ---- --
-- show $ Directory [(Key "abcdef", Stub "myfile.txt")])] ---- -- "abcdef/myfile.txt" data SparseTree Stub :: Name -> SparseTree Content :: CID -> SparseTree Directory :: Map Tag SparseTree -> SparseTree newtype Linearization NonLinear :: SparseTree -> Linearization linearize :: SparseTree -> Either Linearization Path -- | Get all CIDs from a SparseTree (all levels) cIDs :: (Monoid (f CID), Applicative f) => SparseTree -> f CID module Network.IPFS.DAG.Link.Types data Link Link :: CID -> Name -> Integer -> Link [$sel:cid:Link] :: Link -> CID [$sel:name:Link] :: Link -> Name [$sel:size:Link] :: Link -> Integer instance GHC.Generics.Generic Network.IPFS.DAG.Link.Types.Link instance GHC.Classes.Eq Network.IPFS.DAG.Link.Types.Link instance GHC.Show.Show Network.IPFS.DAG.Link.Types.Link instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.DAG.Link.Types.Link module Network.IPFS.DAG.Node.Types data Node Node :: Text -> [Link] -> Node [$sel:dataBlock:Node] :: Node -> Text [$sel:links:Node] :: Node -> [Link] instance GHC.Classes.Eq Network.IPFS.DAG.Node.Types.Node instance GHC.Show.Show Network.IPFS.DAG.Node.Types.Node instance Data.Aeson.Types.ToJSON.ToJSON Network.IPFS.DAG.Node.Types.Node module Network.IPFS.DAG.Link create :: MonadLocalIPFS m => CID -> Name -> m (Either Error Link) module Network.IPFS.DAG put :: MonadLocalIPFS m => ByteString -> m (Either Error CID) putNode :: MonadLocalIPFS m => Node -> m (Either Error CID) module Network.IPFS.Add addRaw :: MonadLocalIPFS m => ByteString -> m (Either Error CID) addFile :: MonadLocalIPFS m => ByteString -> Name -> m (Either Error (SparseTree, CID)) addPath :: MonadLocalIPFS m => FilePath -> m (Either Error CID) addDir :: (MonadIO m, MonadLocalIPFS m) => Ignored -> FilePath -> m (Either Error CID) module Paths_ipfs version :: Version getBinDir :: IO FilePath getLibDir :: IO FilePath getDynLibDir :: IO FilePath getDataDir :: IO FilePath getLibexecDir :: IO FilePath getDataFileName :: FilePath -> IO FilePath getSysconfDir :: IO FilePath