Safe Haskell | None |
---|---|
Language | Haskell2010 |
- Miscellaneous
- System.Process.Ext reëxports
- Data.Text.Lazy reëxports
- Control.Composition reëxports
- Dhall reëxports
- Shake reëxports
- Network.HTTP.Client.TLS reëxports
- System.FilePath reëxports
- ByteString reëxports
- Helpers for pretty-printing
- Text.PrettyPrint.ANSI.Leijen reëxports
- Orphan instances
Synopsis
- hex :: Int -> String
- bool :: a -> a -> Bool -> a
- intersperse :: a -> [a] -> [a]
- transpose :: [[a]] -> [[a]]
- sortBy :: (a -> a -> Ordering) -> [a] -> [a]
- void :: Functor f => f a -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- when :: Applicative f => Bool -> f () -> f ()
- join :: Monad m => m (m a) -> m a
- fold :: (Foldable t, Monoid m) => t m -> m
- zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()
- zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a]
- encode :: Binary a => a -> ByteString
- decode :: Binary a => ByteString -> a
- fromMaybe :: a -> Maybe a -> a
- isNothing :: Maybe a -> Bool
- isPrefixOf :: Eq a => [a] -> [a] -> Bool
- isSuffixOf :: Eq a => [a] -> [a] -> Bool
- on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
- both :: (a -> b) -> (a, a) -> (b, b)
- (***) :: Arrow a => a b c -> a b' c' -> a (b, b') (c, c')
- (&&&) :: Arrow a => a b c -> a b c' -> a b (c, c')
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- ($>) :: Functor f => f a -> b -> f b
- first :: Arrow a => a b c -> a (b, d) (c, d)
- second :: Arrow a => a b c -> a (d, b) (d, c)
- getEnv :: String -> IO String
- exitWith :: ExitCode -> IO a
- showVersion :: Version -> String
- traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
- nubSpecial :: Eq a => [[a]] -> [[a]]
- (<>) :: Semigroup a => a -> a -> a
- data ExitCode = ExitSuccess
- class Monad m => MonadIO (m :: * -> *) where
- makeExe :: String
- shouldWrite :: (MonadIO m, Binary a) => a -> FilePath -> m Bool
- silentCreateProcess :: Verbosity -> CreateProcess -> IO ()
- data Text
- pack :: String -> Text
- unpack :: Text -> String
- biaxe :: (Traversable t, Applicative f) => t (a -> b -> f ()) -> a -> b -> f ()
- (.*) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
- (.**) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e
- thread :: [a -> a] -> a -> a
- bisequence' :: (Traversable t, Applicative f) => t (a -> b -> f c) -> a -> b -> t (f c)
- class Interpret a
- class Inject a
- class Generic a
- class Binary t
- input :: Type a -> Text -> IO a
- auto :: Interpret a => Type a
- detailed :: IO a -> IO a
- data Rules a
- data Action a
- command :: CmdResult r => [CmdOption] -> String -> [String] -> Action r
- command_ :: [CmdOption] -> String -> [String] -> Action ()
- (%>) :: FilePattern -> (FilePath -> Action ()) -> Rules ()
- need :: [FilePath] -> Action ()
- want :: [FilePath] -> Rules ()
- shake :: ShakeOptions -> Rules () -> IO ()
- data Rebuild
- (~>) :: String -> Action () -> Rules ()
- cmd :: CmdArguments args => args :-> Action r
- cmd_ :: (CmdArguments args, Unit args) => args :-> Action ()
- data ShakeOptions = ShakeOptions {
- shakeFiles :: FilePath
- shakeThreads :: Int
- shakeVersion :: String
- shakeVerbosity :: Verbosity
- shakeStaunch :: Bool
- shakeReport :: [FilePath]
- shakeLint :: Maybe Lint
- shakeLintInside :: [FilePath]
- shakeLintIgnore :: [FilePattern]
- shakeCommandOptions :: [CmdOption]
- shakeFlush :: Maybe Double
- shakeRebuild :: [(Rebuild, FilePattern)]
- shakeAbbreviations :: [(String, String)]
- shakeStorageLog :: Bool
- shakeLineBuffering :: Bool
- shakeTimings :: Bool
- shakeRunCommands :: Bool
- shakeChange :: Change
- shakeCreationCheck :: Bool
- shakeLiveFiles :: [FilePath]
- shakeVersionIgnore :: Bool
- shakeColor :: Bool
- shakeProgress :: IO Progress -> IO ()
- shakeOutput :: Verbosity -> String -> IO ()
- shakeExtra :: HashMap TypeRep Dynamic
- shakeOptions :: ShakeOptions
- copyFile' :: FilePath -> FilePath -> Action ()
- data Change
- data Verbosity
- removeFilesAfter :: FilePath -> [FilePattern] -> Action ()
- data Lint
- takeBaseName :: FilePath -> String
- takeFileName :: FilePath -> FilePath
- takeDirectory :: FilePath -> FilePath
- (-<.>) :: FilePath -> String -> FilePath
- makeExecutable :: FilePath -> IO ()
- tlsManagerSettings :: ManagerSettings
- newManager :: ManagerSettings -> IO Manager
- parseRequest :: MonadThrow m => String -> m Request
- httpLbs :: Request -> Manager -> IO (Response ByteString)
- data Response body
- data Request
- (</>) :: FilePath -> FilePath -> FilePath
- pathSeparator :: Char
- data ByteString
- (<#>) :: Doc -> Doc -> Doc
- (<+>) :: Doc -> Doc -> Doc
- text :: String -> Doc
- punctuate :: Doc -> [Doc] -> [Doc]
- dullred :: Doc -> Doc
- linebreak :: Doc
- dullyellow :: Doc -> Doc
- hardline :: Doc
- hang :: Int -> Doc -> Doc
- indent :: Int -> Doc -> Doc
- putDoc :: Doc -> IO ()
- class Pretty a where
- module System.Process
- module System.Directory
- type Lens' s a = Lens s s a a
- over :: ASetter s t a b -> (a -> b) -> s -> t
- _Just :: Applicative f => (a -> f a') -> Maybe a -> f (Maybe a')
- view :: Getting a s a -> s -> a
- _1 :: Field1 s t a b => Lens s t a b
- _2 :: Field2 s t a b => Lens s t a b
- _4 :: Field4 s t a b => Lens s t a b
- each :: Each s t a b => Traversal s t a b
- (&) :: a -> (a -> b) -> b
- (%~) :: ASetter s t a b -> (a -> b) -> s -> t
Documentation
Case analysis for the Bool
type.
evaluates to bool
x y px
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.
Examples
Basic usage:
>>>
bool "foo" "bar" True
"bar">>>
bool "foo" "bar" False
"foo"
Confirm that
and bool
x y pif 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
Since: base-4.7.0.0
intersperse :: a -> [a] -> [a] #
The intersperse
function takes an element and a list and
`intersperses' that element between the elements of the list.
For example,
>>>
intersperse ',' "abcde"
"a,b,c,d,e"
The transpose
function transposes the rows and columns of its argument.
For example,
>>>
transpose [[1,2,3],[4,5,6]]
[[1,4],[2,5],[3,6]]
If some of the rows are shorter than the following rows, their elements are skipped:
>>>
transpose [[10,11],[20],[],[30,31,32]]
[[10,20,30],[11,31],[32]]
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void
valueIO
action.
Examples
Replace the contents of a
with unit:Maybe
Int
>>>
void Nothing
Nothing>>>
void (Just 3)
Just ()
Replace the contents of an
with unit,
resulting in an Either
Int
Int
: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
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
when :: Applicative f => Bool -> f () -> f () #
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.
join :: Monad m => m (m a) -> m a #
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.
zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () #
zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] #
filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] #
This generalizes the list-based filter
function.
encode :: Binary a => a -> ByteString #
Encode a value using binary serialisation to a lazy ByteString.
decode :: Binary a => ByteString -> a #
Decode a value from a lazy ByteString, reconstructing the original structure.
fromMaybe :: a -> 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
.
Examples
Basic usage:
>>>
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
isPrefixOf :: Eq a => [a] -> [a] -> Bool #
The isPrefixOf
function takes two lists and returns True
iff the first list is a prefix of the second.
>>>
"Hello" `isPrefixOf` "Hello World!"
True
>>>
"Hello" `isPrefixOf` "Wello Horld!"
False
isSuffixOf :: Eq a => [a] -> [a] -> Bool #
The isSuffixOf
function takes two lists and returns True
iff
the first list is a suffix of the second. The second list must be
finite.
>>>
"ld!" `isSuffixOf` "Hello World!"
True
>>>
"World" `isSuffixOf` "Hello World!"
False
(***) :: Arrow a => a b c -> a b' c' -> a (b, b') (c, c') infixr 3 #
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 (c, c') infixr 3 #
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.
($>) :: Functor f => f a -> b -> f b infixl 4 #
Flipped version of <$
.
Examples
Replace the contents of a
with a constant Maybe
Int
String
:
>>>
Nothing $> "foo"
Nothing>>>
Just 90210 $> "foo"
Just "foo"
Replace the contents of an
with a constant
Either
Int
Int
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")
Since: base-4.7.0.0
first :: Arrow a => a b c -> a (b, d) (c, d) #
Send the first component of the input through the argument arrow, and copy the rest unchanged to the output.
second :: Arrow a => a b c -> a (d, b) (d, c) #
A mirror image of first
.
The default definition may be overridden with a more efficient version if desired.
getEnv :: String -> IO String #
Computation getEnv
var
returns the value
of the environment variable var
. For the inverse, the
setEnv
function can be used.
This computation may fail with:
isDoesNotExistError
if the environment variable does not exist.
exitWith :: ExitCode -> IO a #
Computation exitWith
code
throws ExitCode
code
.
Normally this terminates the program, returning code
to the
program's caller.
On program termination, the standard Handle
s stdout
and
stderr
are flushed automatically; any other buffered Handle
s
need to be flushed manually, otherwise the buffered data will be
discarded.
A program that fails in any other way is treated as if it had
called exitFailure
.
A program that terminates successfully without calling exitWith
explicitly is treated as if it had called exitWith
ExitSuccess
.
As an ExitCode
is not an IOError
, exitWith
bypasses
the error handling in the IO
monad and cannot be intercepted by
catch
from the Prelude. However it is a SomeException
, and can
be caught using the functions of Control.Exception. This means
that cleanup computations added with bracket
(from Control.Exception) are also executed properly on exitWith
.
Note: in GHC, exitWith
should be called from the main program
thread in order to exit the process. When called from another
thread, exitWith
will throw an ExitException
as normal, but the
exception will not cause the process itself to exit.
showVersion :: Version -> String #
Provides one possible concrete representation for Version
. For
a version with versionBranch
= [1,2,3]
and versionTags
= ["tag1","tag2"]
, the output will be 1.2.3-tag1-tag2
.
traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> 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
.
nubSpecial :: Eq a => [[a]] -> [[a]] Source #
Defines the exit codes that a program can return.
ExitSuccess | indicates successful termination; |
Instances
Eq ExitCode | |
Ord ExitCode | |
Defined in GHC.IO.Exception | |
Read ExitCode | |
Show ExitCode | |
Generic ExitCode | |
Exception ExitCode | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception toException :: ExitCode -> SomeException # fromException :: SomeException -> Maybe ExitCode # displayException :: ExitCode -> String # | |
CmdResult ExitCode | |
Defined in Development.Shake.Command | |
type Rep ExitCode | |
Defined in GHC.IO.Exception |
class Monad m => MonadIO (m :: * -> *) where #
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:
Instances
MonadIO IO | Since: base-4.9.0.0 |
Defined in Control.Monad.IO.Class | |
MonadIO Q | |
Defined in Language.Haskell.TH.Syntax | |
MonadIO Rules | |
Defined in Development.Shake.Internal.Core.Rules | |
MonadIO Action | |
Defined in Development.Shake.Internal.Core.Types | |
(Functor f, MonadIO m) => MonadIO (FreeT f m) | |
Defined in Control.Monad.Trans.Free | |
(Error e, MonadIO m) => MonadIO (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
MonadIO m => MonadIO (StateT s m) | |
Defined in Control.Monad.Trans.State.Lazy | |
MonadIO (RAW ro rw) | |
Defined in Development.Shake.Internal.Core.Monad |
Miscellaneous
System.Process.Ext reëxports
silentCreateProcess :: Verbosity -> CreateProcess -> IO () Source #
Data.Text.Lazy reëxports
Instances
Control.Composition reëxports
biaxe :: (Traversable t, Applicative f) => t (a -> b -> f ()) -> a -> b -> f () #
bisequence' :: (Traversable t, Applicative f) => t (a -> b -> f c) -> a -> b -> t (f c) #
Dhall reëxports
Any value that implements Interpret
can be automatically decoded based on
the inferred return type of input
>>>
input auto "[1, 2, 3]" :: IO (Vector Natural)
[1,2,3]
This class auto-generates a default implementation for records that
implement Generic
. This does not auto-generate an instance for recursive
types.
Instances
Interpret Bool | |
Interpret Double | |
Interpret Integer | |
Interpret Natural | |
Interpret Scientific | |
Defined in Dhall autoWith :: InterpretOptions -> Type Scientific # | |
Interpret Text | |
Interpret Text | |
Interpret [Char] | |
Interpret a => Interpret [a] | |
Defined in Dhall autoWith :: InterpretOptions -> Type [a] # | |
Interpret a => Interpret (Maybe a) | |
Interpret a => Interpret (Seq a) | |
Interpret a => Interpret (Vector a) | |
(Inject a, Interpret b) => Interpret (a -> b) | |
Defined in Dhall autoWith :: InterpretOptions -> Type (a -> b) # | |
(Interpret a, Interpret b) => Interpret (a, b) | |
Defined in Dhall autoWith :: InterpretOptions -> Type (a, b) # |
This class is used by Interpret
instance for functions:
instance (Inject a, Interpret b) => Interpret (a -> b)
You can convert Dhall functions with "simple" inputs (i.e. instances of this class) into Haskell functions. This works by:
- Marshaling the input to the Haskell function into a Dhall expression (i.e.
x :: Expr Src X
) - Applying the Dhall function (i.e.
f :: Expr Src X
) to the Dhall input (i.e.App f x
) - Normalizing the syntax tree (i.e.
normalize (App f x)
) - Marshaling the resulting Dhall expression back into a Haskell value
Instances
Representable types of kind *
.
This class is derivable in GHC with the DeriveGeneric
flag on.
A Generic
instance must satisfy the following laws:
from
.to
≡id
to
.from
≡id
Instances
The Binary
class provides put
and get
, methods to encode and
decode a Haskell value to a lazy ByteString
. It mirrors the Read
and
Show
classes for textual representation of Haskell types, and is
suitable for serialising Haskell values to disk, over the network.
For decoding and generating simple external binary formats (e.g. C
structures), Binary may be used, but in general is not suitable
for complex protocols. Instead use the Put
and Get
primitives
directly.
Instances of Binary should satisfy the following property:
decode . encode == id
That is, the get
and put
methods should be the inverse of each
other. A range of instances are provided for basic Haskell types.
Instances
Binary Bool | |
Binary Char | |
Binary Double | |
Binary Float | |
Binary Int | |
Binary Int8 | |
Binary Int16 | |
Binary Int32 | |
Binary Int64 | |
Binary Integer | |
Binary Natural | Since: 0.7.3.0 |
Binary Ordering | |
Binary Word | |
Binary Word8 | |
Binary Word16 | |
Binary Word32 | |
Binary Word64 | |
Binary RuntimeRep | |
Defined in Data.Binary.Class | |
Binary VecCount | |
Binary VecElem | |
Binary SomeTypeRep | |
Defined in Data.Binary.Class | |
Binary () | |
Binary TyCon | |
Binary KindRep | |
Binary TypeLitSort | |
Defined in Data.Binary.Class | |
Binary ByteString | |
Defined in Data.Binary.Class | |
Binary ByteString | |
Defined in Data.Binary.Class | |
Binary Scientific | Note that in the future I intend to change the type of the |
Defined in Data.Scientific | |
Binary Void | Since: 0.8.0.0 |
Binary Version | Since: 0.8.0.0 |
Binary All | Since: 0.8.4.0 |
Binary Any | Since: 0.8.4.0 |
Binary Fingerprint | Since: 0.7.6.0 |
Defined in Data.Binary.Class | |
Binary ShortByteString | |
Defined in Data.Binary.Class | |
Binary IntSet | |
Binary FileQ | |
Binary UUID | |
Binary DoesDirectoryExistQ | |
Binary DoesFileExistQ | |
Binary GetDirectoryContentsQ | |
Binary GetDirectoryDirsQ | |
Binary GetDirectoryFilesQ | |
Binary GetEnvQ | |
Binary FilesQ | |
Binary AlwaysRerunQ | |
Binary a => Binary [a] | |
Binary a => Binary (Maybe a) | |
(Binary a, Integral a) => Binary (Ratio a) | |
Binary a => Binary (Complex a) | |
Binary (Fixed a) | Since: 0.8.0.0 |
Binary a => Binary (Min a) | Since: 0.8.4.0 |
Binary a => Binary (Max a) | Since: 0.8.4.0 |
Binary a => Binary (First a) | Since: 0.8.4.0 |
Binary a => Binary (Last a) | Since: 0.8.4.0 |
Binary m => Binary (WrappedMonoid m) | Since: 0.8.4.0 |
Defined in Data.Binary.Class | |
Binary a => Binary (Option a) | Since: 0.8.4.0 |
Binary a => Binary (First a) | Since: 0.8.4.0 |
Binary a => Binary (Last a) | Since: 0.8.4.0 |
Binary a => Binary (Dual a) | Since: 0.8.4.0 |
Binary a => Binary (Sum a) | Since: 0.8.4.0 |
Binary a => Binary (Product a) | Since: 0.8.4.0 |
Binary a => Binary (NonEmpty a) | Since: 0.8.4.0 |
Binary e => Binary (IntMap e) | |
Binary e => Binary (Tree e) | |
Binary e => Binary (Seq e) | |
Binary a => Binary (Set a) | |
Binary answer => Binary (OracleA answer) | |
Binary question => Binary (OracleQ question) | |
(Binary a, Binary b) => Binary (Either a b) | |
Typeable a => Binary (TypeRep a) | |
(Binary a, Binary b) => Binary (a, b) | |
(Binary k, Binary e) => Binary (Map k e) | |
(Binary i, Ix i, Binary e, IArray UArray e) => Binary (UArray i e) | |
(Binary i, Ix i, Binary e) => Binary (Array i e) | |
(Binary a, Binary b) => Binary (Arg a b) | Since: 0.8.4.0 |
(Binary a, Binary b, Binary c) => Binary (a, b, c) | |
Binary (f a) => Binary (Alt f a) | Since: 0.8.4.0 |
(Binary a, Binary b, Binary c, Binary d) => Binary (a, b, c, d) | |
(Binary a, Binary b, Binary c, Binary d, Binary e) => Binary (a, b, c, d, e) | |
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f) => Binary (a, b, c, d, e, f) | |
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f, Binary g) => Binary (a, b, c, d, e, f, g) | |
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f, Binary g, Binary h) => Binary (a, b, c, d, e, f, g, h) | |
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f, Binary g, Binary h, Binary i) => Binary (a, b, c, d, e, f, g, h, i) | |
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f, Binary g, Binary h, Binary i, Binary j) => Binary (a, b, c, d, e, f, g, h, i, j) | |
:: Type a | The type of value to decode from Dhall to Haskell |
-> Text | The Dhall program |
-> IO a | The decoded value in Haskell |
Type-check and evaluate a Dhall program, decoding the result into Haskell
The first argument determines the type of value that you decode:
>>>
input integer "+2"
2>>>
input (vector double) "[1.0, 2.0]"
[1.0,2.0]
Use auto
to automatically select which type to decode based on the
inferred return type:
>>>
input auto "True" :: IO Bool
True
This uses the settings from defaultInputSettings
.
auto :: Interpret a => Type a #
Use the default options for interpreting a configuration file
auto = autoWith defaultInterpretOptions
Use this to provide more detailed error messages
> input auto "True" :: IO Integer *** Exception: Error: Expression doesn't match annotation True : Integer (input):1:1
> detailed (input auto "True") :: IO Integer *** Exception: Error: Expression doesn't match annotation Explanation: You can annotate an expression with its type or kind using the ❰:❱ symbol, like this: ┌───────┐ │ x : t │ ❰x❱ is an expression and ❰t❱ is the annotated type or kind of ❰x❱ └───────┘ The type checker verifies that the expression's type or kind matches the provided annotation For example, all of the following are valid annotations that the type checker accepts: ┌─────────────┐ │ 1 : Natural │ ❰1❱ is an expression that has type ❰Natural❱, so the type └─────────────┘ checker accepts the annotation ┌───────────────────────┐ │ Natural/even 2 : Bool │ ❰Natural/even 2❱ has type ❰Bool❱, so the type └───────────────────────┘ checker accepts the annotation ┌────────────────────┐ │ List : Type → Type │ ❰List❱ is an expression that has kind ❰Type → Type❱, └────────────────────┘ so the type checker accepts the annotation ┌──────────────────┐ │ List Text : Type │ ❰List Text❱ is an expression that has kind ❰Type❱, so └──────────────────┘ the type checker accepts the annotation However, the following annotations are not valid and the type checker will reject them: ┌──────────┐ │ 1 : Text │ The type checker rejects this because ❰1❱ does not have type └──────────┘ ❰Text❱ ┌─────────────┐ │ List : Type │ ❰List❱ does not have kind ❰Type❱ └─────────────┘ You or the interpreter annotated this expression: ↳ True ... with this type or kind: ↳ Integer ... but the inferred type or kind of the expression is actually: ↳ Bool Some common reasons why you might get this error: ● The Haskell Dhall interpreter implicitly inserts a top-level annotation matching the expected type For example, if you run the following Haskell code: ┌───────────────────────────────┐ │ >>> input auto "1" :: IO Text │ └───────────────────────────────┘ ... then the interpreter will actually type check the following annotated expression: ┌──────────┐ │ 1 : Text │ └──────────┘ ... and then type-checking will fail ──────────────────────────────────────────────────────────────────────────────── True : Integer (input):1:1
Shake reëxports
Define a set of rules. Rules can be created with calls to functions such as %>
or action
.
Rules are combined with either the Monoid
instance, or (more commonly) the Monad
instance and do
notation.
To define your own custom types of rule, see Development.Shake.Rule.
The Action
monad, use liftIO
to raise IO
actions into it, and need
to execute files.
Action values are used by addUserRule
and action
. The Action
monad tracks the dependencies of a rule.
To raise an exception call error
, fail
or
.liftIO
. throwIO
Instances
Monad Action | |
Functor Action | |
MonadFail Action | |
Defined in Development.Shake.Internal.Core.Types | |
Applicative Action | |
MonadIO Action | |
Defined in Development.Shake.Internal.Core.Types | |
Semigroup a => Semigroup (Action a) # | |
(Semigroup a, Monoid a) => Monoid (Action a) # | |
CmdResult r => CmdArguments (Action r) | |
Defined in Development.Shake.Command cmdArguments :: CmdArgument -> Action r # |
command :: CmdResult r => [CmdOption] -> String -> [String] -> Action r #
Execute a system command. Before running command
make sure you need
any files
that are used by the command.
This function takes a list of options (often just []
, see CmdOption
for the available
options), the name of the executable (either a full name, or a program on the $PATH
) and
a list of arguments. The result is often ()
, but can be a tuple containg any of Stdout
,
Stderr
and Exit
. Some examples:
command_
[] "gcc" ["-c","myfile.c"] -- compile a file, throwing an exception on failureExit
c <-command
[] "gcc" ["-c",myfile] -- run a command, recording the exit code (Exit
c,Stderr
err) <-command
[] "gcc" ["-c","myfile.c"] -- run a command, recording the exit code and error outputStdout
out <-command
[] "gcc" ["-MM","myfile.c"] -- run a command, recording the outputcommand_
[Cwd
"generated"] "gcc" ["-c",myfile] -- run a command in a directory
Unless you retrieve the ExitCode
using Exit
, any ExitFailure
will throw an error, including
the Stderr
in the exception message. If you capture the Stdout
or Stderr
, that stream will not be echoed to the console,
unless you use the option EchoStdout
or EchoStderr
.
If you use command
inside a do
block and do not use the result, you may get a compile-time error about being
unable to deduce CmdResult
. To avoid this error, use command_
.
By default the stderr
stream will be captured for use in error messages, and also echoed. To only echo
pass
, which causes no streams to be captured by Shake, and certain programs (e.g. WithStderr
False
gcc
)
to detect they are running in a terminal.
(%>) :: FilePattern -> (FilePath -> Action ()) -> Rules () infix 1 #
Define a rule that matches a FilePattern
, see ?==
for the pattern rules.
Patterns with no wildcards have higher priority than those with wildcards, and no file
required by the system may be matched by more than one pattern at the same priority
(see priority
and alternatives
to modify this behaviour).
This function will create the directory for the result file, if necessary.
"*.asm.o"%>
\out -> do let src =dropExtension
outneed
[src]cmd
"as" [src] "-o" [out]
To define a build system for multiple compiled languages, we recommend using .asm.o
,
.cpp.o
, .hs.o
, to indicate which language produces an object file.
I.e., the file foo.cpp
produces object file foo.cpp.o
.
Note that matching is case-sensitive, even on Windows.
If the Action
completes successfully the file is considered up-to-date, even if the file
has not changed.
need :: [FilePath] -> Action () #
Add a dependency on the file arguments, ensuring they are built before continuing.
The file arguments may be built in parallel, in any order. This function is particularly
necessary when calling cmd
or command
. As an example:
"//*.rot13"%>
\out -> do let src =dropExtension
outneed
[src]cmd
"rot13" [src] "-o" [out]
Usually need [foo,bar]
is preferable to need [foo] >> need [bar]
as the former allows greater
parallelism, while the latter requires foo
to finish building before starting to build bar
.
This function should not be called with wildcards (e.g. *.txt
- use getDirectoryFiles
to expand them),
environment variables (e.g. $HOME
- use getEnv
to expand them) or directories (directories cannot be
tracked directly - track files within the directory instead).
want :: [FilePath] -> Rules () #
Require that the argument files are built by the rules, used to specify the target.
main =shake
shakeOptions
$ dowant
["Main.exe"] ...
This program will build Main.exe
, given sufficient rules. All arguments to all want
calls
may be built in parallel, in any order.
This function is defined in terms of action
and need
, use action
if you need more complex
targets than want
allows.
shake :: ShakeOptions -> Rules () -> IO () #
Main entry point for running Shake build systems. For an example see the top of the module Development.Shake.
Use ShakeOptions
to specify how the system runs, and Rules
to specify what to build. The function will throw
an exception if the build fails.
To use command line flags to modify ShakeOptions
see shakeArgs
.
The current assumptions made by the build system, used by shakeRebuild
. These options
allow the end user to specify that any rules run are either to be treated as clean, or as
dirty, regardless of what the build system thinks.
These assumptions only operate on files reached by the current action
commands. Any
other files in the database are left unchanged.
RebuildNow | Assume these files are dirty and require rebuilding. for benchmarking rebuild speed and for rebuilding if untracked dependencies have changed. This flag is safe, but may cause more rebuilding than necessary. |
RebuildNormal | Useful to reset the rebuild status to how it was before, equivalent to passing no |
RebuildLater | This assumption is unsafe, and may lead to incorrect build results in this run. Assume these files are clean in this run, but test them normally in future runs. |
Instances
Bounded Rebuild | |
Enum Rebuild | |
Eq Rebuild | |
Data Rebuild | |
Defined in Development.Shake.Internal.Options gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Rebuild -> c Rebuild # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Rebuild # toConstr :: Rebuild -> Constr # dataTypeOf :: Rebuild -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Rebuild) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Rebuild) # gmapT :: (forall b. Data b => b -> b) -> Rebuild -> Rebuild # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Rebuild -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Rebuild -> r # gmapQ :: (forall d. Data d => d -> u) -> Rebuild -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Rebuild -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Rebuild -> m Rebuild # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Rebuild -> m Rebuild # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Rebuild -> m Rebuild # | |
Ord Rebuild | |
Defined in Development.Shake.Internal.Options | |
Read Rebuild | |
Show Rebuild | |
(~>) :: String -> Action () -> Rules () infix 1 #
Infix operator alias for phony
, for sake of consistency with normal
rules.
cmd :: CmdArguments args => args :-> Action r #
Execute a system command. Before running cmd
make sure you need
any files
that are used by the command.
String
arguments are treated as whitespace separated arguments.[String]
arguments are treated as literal arguments.CmdOption
arguments are used as options.
As some examples, here are some calls, and the resulting command string:
cmd_
"git log --pretty=" "oneline" -- git log --pretty= onelinecmd_
"git log --pretty=" ["oneline"] -- git log --pretty= onelinecmd_
"git log" ("--pretty=" ++ "oneline") -- git log --pretty=onelinecmd_
"git log" ("--pretty=" ++ "one line") -- git log --pretty=one linecmd_
"git log" ["--pretty=" ++ "one line"] -- git log "--pretty=one line"
More examples, including return values, see this translation of the examples given for the command
function:
cmd_
"gcc -c myfile.c" -- compile a file, throwing an exception on failureExit
c <-cmd
"gcc -c" [myfile] -- run a command, recording the exit code (Exit
c,Stderr
err) <-cmd
"gcc -c myfile.c" -- run a command, recording the exit code and error outputStdout
out <-cmd
"gcc -MM myfile.c" -- run a command, recording the outputcmd
(Cwd
"generated") "gcc -c" [myfile] ::Action
() -- run a command in a directory
When passing file arguments we use [myfile]
so that if the myfile
variable contains spaces they are properly escaped.
If you use cmd
inside a do
block and do not use the result, you may get a compile-time error about being
unable to deduce CmdResult
. To avoid this error, use cmd_
.
The cmd
function can also be run in the IO
monad, but then Traced
is ignored and command lines are not echoed.
As an example:
cmd
(Cwd
"generated")Shell
"gcc -c myfile.c" :: IO ()
cmd_ :: (CmdArguments args, Unit args) => args :-> Action () #
data ShakeOptions #
Options to control the execution of Shake, usually specified by overriding fields in
shakeOptions
:
shakeOptions
{shakeThreads
=4,shakeReport
=["report.html"]}
The Data
instance for this type reports the shakeProgress
and shakeOutput
fields as having the abstract type Hidden
,
because Data
cannot be defined for functions or TypeRep
s.
ShakeOptions | |
|
Instances
Data ShakeOptions | |
Defined in Development.Shake.Internal.Options gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ShakeOptions -> c ShakeOptions # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ShakeOptions # toConstr :: ShakeOptions -> Constr # dataTypeOf :: ShakeOptions -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ShakeOptions) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ShakeOptions) # gmapT :: (forall b. Data b => b -> b) -> ShakeOptions -> ShakeOptions # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ShakeOptions -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ShakeOptions -> r # gmapQ :: (forall d. Data d => d -> u) -> ShakeOptions -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ShakeOptions -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ShakeOptions -> m ShakeOptions # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ShakeOptions -> m ShakeOptions # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ShakeOptions -> m ShakeOptions # | |
Show ShakeOptions | |
Defined in Development.Shake.Internal.Options showsPrec :: Int -> ShakeOptions -> ShowS # show :: ShakeOptions -> String # showList :: [ShakeOptions] -> ShowS # |
shakeOptions :: ShakeOptions #
The default set of ShakeOptions
.
copyFile' :: FilePath -> FilePath -> Action () #
copyFile' old new
copies the existing file from old
to new
.
The old
file will be tracked as a dependency.
Also creates the new directory if necessary.
How should you determine if a file has changed, used by shakeChange
. The most common values are
ChangeModtime
(the default, very fast, touch
causes files to rebuild) and ChangeModtimeAndDigestInput
(slightly slower, touch
and switching git
branches does not cause input files to rebuild).
ChangeModtime | Compare equality of modification timestamps, a file has changed if its last modified time changes.
A |
ChangeDigest | Compare equality of file contents digests, a file has changed if its digest changes.
A |
ChangeModtimeAndDigest | A file is rebuilt if both its modification time and digest have changed. For efficiency reasons, the modification time is checked first, and if that has changed, the digest is checked. |
ChangeModtimeAndDigestInput | Use |
ChangeModtimeOrDigest | A file is rebuilt if either its modification time or its digest has changed. A |
Instances
Bounded Change | |
Enum Change | |
Defined in Development.Shake.Internal.Options | |
Eq Change | |
Data Change | |
Defined in Development.Shake.Internal.Options gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Change -> c Change # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Change # toConstr :: Change -> Constr # dataTypeOf :: Change -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Change) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Change) # gmapT :: (forall b. Data b => b -> b) -> Change -> Change # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Change -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Change -> r # gmapQ :: (forall d. Data d => d -> u) -> Change -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Change -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Change -> m Change # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Change -> m Change # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Change -> m Change # | |
Ord Change | |
Read Change | |
Show Change | |
The verbosity data type, used by shakeVerbosity
.
Silent | Don't print any messages. |
Quiet | Only print essential messages, typically errors. |
Normal | Print errors and |
Loud | Print errors and full command lines when running a |
Chatty | Print errors, full command line and status messages when starting a rule. |
Diagnostic | Print messages for virtually everything (mostly for debugging). |
Instances
removeFilesAfter :: FilePath -> [FilePattern] -> Action () #
Remove files, like removeFiles
, but executed after the build completes successfully.
Useful for implementing clean
actions that delete files Shake may have open for building.
Which lint checks to perform, used by shakeLint
.
LintBasic | The most basic form of linting. Checks that the current directory does not change and that results do not change after they
are first written. Any calls to |
LintFSATrace | Track which files are accessed by command line programs using fsatrace. |
Instances
Bounded Lint | |
Enum Lint | |
Eq Lint | |
Data Lint | |
Defined in Development.Shake.Internal.Options gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Lint -> c Lint # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Lint # dataTypeOf :: Lint -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Lint) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Lint) # gmapT :: (forall b. Data b => b -> b) -> Lint -> Lint # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Lint -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Lint -> r # gmapQ :: (forall d. Data d => d -> u) -> Lint -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Lint -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Lint -> m Lint # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Lint -> m Lint # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Lint -> m Lint # | |
Ord Lint | |
Read Lint | |
Show Lint | |
takeBaseName :: FilePath -> String #
Get the base name, without an extension or path.
takeBaseName "/directory/file.ext" == "file" takeBaseName "file/test.txt" == "test" takeBaseName "dave.ext" == "dave" takeBaseName "" == "" takeBaseName "test" == "test" takeBaseName (addTrailingPathSeparator x) == "" takeBaseName "file/file.tar.gz" == "file.tar"
takeFileName :: FilePath -> FilePath #
Get the file name.
takeFileName "/directory/file.ext" == "file.ext" takeFileName "test/" == "" takeFileName x `isSuffixOf` x takeFileName x == snd (splitFileName x) Valid x => takeFileName (replaceFileName x "fred") == "fred" Valid x => takeFileName (x </> "fred") == "fred" Valid x => isRelative (takeFileName x)
takeDirectory :: FilePath -> FilePath #
Get the directory name, move up one level.
takeDirectory "/directory/other.ext" == "/directory" takeDirectory x `isPrefixOf` x || takeDirectory x == "." takeDirectory "foo" == "." takeDirectory "/" == "/" takeDirectory "/foo" == "/" takeDirectory "/foo/bar/baz" == "/foo/bar" takeDirectory "/foo/bar/baz/" == "/foo/bar/baz" takeDirectory "foo/bar/baz" == "foo/bar" Windows: takeDirectory "foo\\bar" == "foo" Windows: takeDirectory "foo\\bar\\\\" == "foo\\bar" Windows: takeDirectory "C:\\" == "C:\\"
(-<.>) :: FilePath -> String -> FilePath infixr 7 #
Remove the current extension and add another, equivalent to replaceExtension
.
"/directory/path.txt" -<.> "ext" == "/directory/path.ext" "/directory/path.txt" -<.> ".ext" == "/directory/path.ext" "foo.o" -<.> "c" == "foo.c"
makeExecutable :: FilePath -> IO () Source #
Network.HTTP.Client.TLS reëxports
tlsManagerSettings :: ManagerSettings #
Default TLS-enabled manager settings
newManager :: ManagerSettings -> IO Manager #
Create a Manager
. The Manager
will be shut down automatically via
garbage collection.
Creating a new Manager
is a relatively expensive operation, you are
advised to share a single Manager
between requests instead.
The first argument to this function is often defaultManagerSettings
,
though add-on libraries may provide a recommended replacement.
Since 0.1.0
parseRequest :: MonadThrow m => String -> m Request #
Convert a URL into a Request
.
This function defaults some of the values in Request
, such as setting method
to
GET
and requestHeaders
to []
.
Since this function uses MonadThrow
, the return monad can be anything that is
an instance of MonadThrow
, such as IO
or Maybe
.
You can place the request method at the beginning of the URL separated by a space, e.g.:
@@
parseRequest "POST http://httpbin.org/post"
@@
Note that the request method must be provided as all capital letters.
A Request
created by this function won't cause exceptions on non-2XX
response status codes.
To create a request which throws on non-2XX status codes, see parseUrlThrow
Since: http-client-0.4.30
httpLbs :: Request -> Manager -> IO (Response ByteString) #
A convenience wrapper around withResponse
which reads in the entire
response body and immediately closes the connection. Note that this function
performs fully strict I/O, and only uses a lazy ByteString in its response
for memory efficiency. If you are anticipating a large response body, you
are encouraged to use withResponse
and brRead
instead.
Since 0.1.0
A simple representation of the HTTP response.
Since 0.1.0
Instances
Functor Response | |
Foldable Response | |
Defined in Network.HTTP.Client.Types fold :: Monoid m => Response m -> m # foldMap :: Monoid m => (a -> m) -> Response a -> m # foldr :: (a -> b -> b) -> b -> Response a -> b # foldr' :: (a -> b -> b) -> b -> Response a -> b # foldl :: (b -> a -> b) -> b -> Response a -> b # foldl' :: (b -> a -> b) -> b -> Response a -> b # foldr1 :: (a -> a -> a) -> Response a -> a # foldl1 :: (a -> a -> a) -> Response a -> a # elem :: Eq a => a -> Response a -> Bool # maximum :: Ord a => Response a -> a # minimum :: Ord a => Response a -> a # | |
Traversable Response | |
Eq body => Eq (Response body) | |
Show body => Show (Response body) | |
All information on how to connect to a host and what should be sent in the HTTP request.
If you simply wish to download from a URL, see parseRequest
.
The constructor for this data type is not exposed. Instead, you should use
either the defaultRequest
value, or parseRequest
to
construct from a URL, and then use the records below to make modifications.
This approach allows http-client to add configuration options without
breaking backwards compatibility.
For example, to construct a POST request, you could do something like:
initReq <- parseRequest "http://www.example.com/path" let req = initReq { method = "POST" }
For more information, please see http://www.yesodweb.com/book/settings-types.
Since 0.1.0
System.FilePath reëxports
(</>) :: FilePath -> FilePath -> FilePath infixr 5 #
Combine two paths with a path separator.
If the second path starts with a path separator or a drive letter, then it returns the second.
The intention is that readFile (dir
will access the same file as
</>
file)setCurrentDirectory dir; readFile file
.
Posix: "/directory" </> "file.ext" == "/directory/file.ext" Windows: "/directory" </> "file.ext" == "/directory\\file.ext" "directory" </> "/file.ext" == "/file.ext" Valid x => (takeDirectory x </> takeFileName x) `equalFilePath` x
Combined:
Posix: "/" </> "test" == "/test" Posix: "home" </> "bob" == "home/bob" Posix: "x:" </> "foo" == "x:/foo" Windows: "C:\\foo" </> "bar" == "C:\\foo\\bar" Windows: "home" </> "bob" == "home\\bob"
Not combined:
Posix: "home" </> "/bob" == "/bob" Windows: "home" </> "C:\\bob" == "C:\\bob"
Not combined (tricky):
On Windows, if a filepath starts with a single slash, it is relative to the
root of the current drive. In [1], this is (confusingly) referred to as an
absolute path.
The current behavior of </>
is to never combine these forms.
Windows: "home" </> "/bob" == "/bob" Windows: "home" </> "\\bob" == "\\bob" Windows: "C:\\home" </> "\\bob" == "\\bob"
On Windows, from [1]: "If a file name begins with only a disk designator
but not the backslash after the colon, it is interpreted as a relative path
to the current directory on the drive with the specified letter."
The current behavior of </>
is to never combine these forms.
Windows: "D:\\foo" </> "C:bar" == "C:bar" Windows: "C:\\foo" </> "C:bar" == "C:bar"
pathSeparator :: Char #
The character that separates directories. In the case where more than
one character is possible, pathSeparator
is the 'ideal' one.
Windows: pathSeparator == '\\' Posix: pathSeparator == '/' isPathSeparator pathSeparator
ByteString reëxports
data ByteString #
A space-efficient representation of a Word8
vector, supporting many
efficient operations.
A lazy ByteString
contains 8-bit bytes, or by using the operations
from Data.ByteString.Lazy.Char8 it can be interpreted as containing
8-bit characters.
Instances
Helpers for pretty-printing
(<#>) :: Doc -> Doc -> Doc infixr 5 Source #
Same as Text.PrettyPrint.ANSI.Leijen's $
, but doesn't clash with the
prelude.
Text.PrettyPrint.ANSI.Leijen reëxports
(<+>) :: Doc -> Doc -> Doc infixr 6 #
The document (x <+> y)
concatenates document x
and y
with a
space
in between. (infixr 6)
The document (text s)
contains the literal string s
. The
string shouldn't contain any newline ('\n'
) characters. If the
string contains newline characters, the function string
should be
used.
punctuate :: Doc -> [Doc] -> [Doc] #
(punctuate p xs)
concatenates all documents in xs
with
document p
except for the last document.
someText = map text ["words","in","a","tuple"] test = parens (align (cat (punctuate comma someText)))
This is layed out on a page width of 20 as:
(words,in,a,tuple)
But when the page width is 15, it is layed out as:
(words, in, a, tuple)
(If you want put the commas in front of their elements instead of
at the end, you should use tupled
or, in general, encloseSep
.)
dullyellow :: Doc -> Doc #
Displays a document with the dull yellow forecolor
The hang combinator implements hanging indentation. The document
(hang i x)
renders document x
with a nesting level set to the
current column plus i
. The following example uses hanging
indentation for some text:
test = hang 4 (fillSep (map text (words "the hang combinator indents these words !")))
Which lays out on a page with a width of 20 characters as:
the hang combinator indents these words !
The hang
combinator is implemented as:
hang i x = align (nest i x)
The document (indent i x)
indents document x
with i
spaces.
test = indent 4 (fillSep (map text (words "the indent combinator indents these words !")))
Which lays out with a page width of 20 as:
the indent combinator indents these words !
The action (putDoc doc)
pretty prints document doc
to the
standard output, with a page width of 80 characters and a ribbon
width of 32 characters.
main :: IO () main = do{ putDoc (text "hello" <+> text "world") }
Which would output
hello world
Any ANSI colorisation in doc
will be output.
The member prettyList
is only used to define the instance Pretty
a => Pretty [a]
. In normal circumstances only the pretty
function
is used.
Instances
Pretty Bool | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
Pretty Char | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
Pretty Double | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
Pretty Float | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
Pretty Int | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
Pretty Integer | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
Pretty () | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
Pretty Doc | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
Pretty a => Pretty [a] | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
Pretty a => Pretty (Maybe a) | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
(Pretty a, Pretty b) => Pretty (a, b) | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal | |
(Pretty a, Pretty b, Pretty c) => Pretty (a, b, c) | |
Defined in Text.PrettyPrint.ANSI.Leijen.Internal |
module System.Process
module System.Directory
type Lens' s a = Lens s s a a #
This is a type alias for monomorphic lenses which don't change the type of the container (or of the value inside).
over :: ASetter s t a b -> (a -> b) -> s -> t #
Getting fmap
in a roundabout way:
over
mapped
::Functor
f => (a -> b) -> f a -> f bover
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
as a replacement for over
_2
second
:
>>>
over _2 show (10,20)
(10,"20")
_Just :: Applicative f => (a -> f a') -> Maybe a -> f (Maybe a') #
_Just
targets the value contained in a Maybe
, provided it's a Just
.
See documentation for _Left
(as these 2 are pretty similar). In particular, it can be used to write these:
- Unsafely extracting a value from a
Just
:
fromJust
= (^?!
_Just
)
- Checking whether a value is a
Just
:
isJust
=has
_Just
- Converting a
Maybe
to a list (empty or consisting of a single element):
maybeToList
= (^..
_Just
)
- Gathering all
Just
s in a list:
catMaybes
= (^..
each
.
_Just
)
view :: Getting a s a -> s -> a #
>>>
view _1 (1, 2)
1
The reason it's not in Lens.Micro is that view
in lens has a more general signature:
view :: MonadReader s m => Getting a s a -> m a
So, you would be able to use this view
with functions, but not in various reader monads. For most people this shouldn't be an issue; if it is for you, use view
from microlens-mtl.
_1 :: Field1 s t a b => Lens s t a b #
Gives access to the 1st field of a tuple (up to 5-tuples).
Getting the 1st component:
>>>
(1,2,3,4,5) ^. _1
1
Setting the 1st component:
>>>
(1,2,3) & _1 .~ 10
(10,2,3)
Note that this lens is lazy, and can set fields even of undefined
:
>>>
set _1 10 undefined :: (Int, Int)
(10,*** Exception: Prelude.undefined
This is done to avoid violating a lens law stating that you can get back what you put:
>>>
view _1 . set _1 10 $ (undefined :: (Int, Int))
10
The implementation (for 2-tuples) is:
_1
f t = (,)<$>
f (fst
t)<*>
pure
(snd
t)
or, alternatively,
_1
f ~(a,b) = (\a' -> (a',b))<$>
f a
(where ~
means a lazy pattern).
each :: Each s t a b => Traversal s t a b #
each
tries to be a universal Traversal
– it behaves like traversed
in most situations, but also adds support for e.g. tuples with same-typed values:
>>>
(1,2) & each %~ succ
(2,3)
>>>
["x", "y", "z"] ^. each
"xyz"
However, note that each
doesn't work on every instance of Traversable
. If you have a Traversable
which isn't supported by each
, you can use traversed
instead. Personally, I like using each
instead of traversed
whenever possible – it's shorter and more descriptive.
You can use each
with these things:
each
::Traversal
[a] [b] a beach
::Traversal
(Maybe
a) (Maybe
b) a beach
::Traversal
(a,a) (b,b) a beach
::Traversal
(a,a,a) (b,b,b) a beach
::Traversal
(a,a,a,a) (b,b,b,b) a beach
::Traversal
(a,a,a,a,a) (b,b,b,b,b) a beach
:: (RealFloat
a,RealFloat
b) =>Traversal
(Complex
a) (Complex
b) a b
You can also use each
with types from array, bytestring, and containers by using microlens-ghc, or additionally with types from vector, text, and unordered-containers by using microlens-platform.
(%~) :: ASetter s t a b -> (a -> b) -> s -> t infixr 4 #
(%~
) applies a function to the target; an alternative explanation is that it is an inverse of sets
, which turns a setter into an ordinary function.
is the same thing as mapped
%~
reverse
.fmap
reverse
See over
if you want a non-operator synonym.
Negating the 1st element of a pair:
>>>
(1,2) & _1 %~ negate
(-1,2)
Turning all Left
s in a list to upper case:
>>>
(mapped._Left.mapped %~ toUpper) [Left "foo", Right "bar"]
[Left "FOO",Right "bar"]