Safe Haskell | None |
---|---|
Language | Haskell2010 |
Custom Prelude
Synopsis
- data Bool
- data Either a b
- class Eq a
- data Int
- data IO a
- data Maybe a
- class Read a
- class Show a
- type String = [Char]
- (+) :: Num a => a -> a -> a
- (-) :: Num a => a -> a -> a
- (*) :: Num a => a -> a -> a
- (/) :: Fractional a => a -> a -> a
- (>) :: Ord a => a -> a -> Bool
- (.) :: (b -> c) -> (a -> b) -> a -> c
- ($) :: (a -> b) -> a -> b
- (<) :: Ord a => a -> a -> Bool
- (>=) :: Ord a => a -> a -> Bool
- (<=) :: Ord a => a -> a -> Bool
- (==) :: Eq a => a -> a -> Bool
- (/=) :: Eq a => a -> a -> Bool
- ($!) :: (a -> b) -> a -> b
- (>>) :: Monad m => m a -> m b -> m b
- (>>=) :: Monad m => m a -> (a -> m b) -> m b
- (&&) :: Bool -> Bool -> Bool
- (||) :: Bool -> Bool -> Bool
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<*>) :: Applicative f => f (a -> b) -> f a -> f b
- abs :: Num a => a -> a
- ceiling :: (RealFrac a, Integral b) => a -> b
- div :: Integral a => a -> a -> a
- error :: HasCallStack => [Char] -> a
- flip :: (a -> b -> c) -> b -> a -> c
- floor :: (RealFrac a, Integral b) => a -> b
- fmap :: Functor f => (a -> b) -> f a -> f b
- fromIntegral :: (Integral a, Num b) => a -> b
- fst :: (a, b) -> a
- id :: a -> a
- length :: Foldable t => t a -> Int
- mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- mod :: Integral a => a -> a -> a
- not :: Bool -> Bool
- otherwise :: Bool
- pure :: Applicative f => a -> f a
- read :: Read a => String -> a
- return :: Monad m => a -> m a
- seq :: a -> b -> b
- sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- show :: Show a => a -> String
- snd :: (a, b) -> b
- take :: Int -> [a] -> [a]
- undefined :: HasCallStack => a
- data SomeException
- bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c
- bracket_ :: IO a -> IO b -> IO c -> IO c
- catch :: Exception e => IO a -> (e -> IO a) -> IO a
- throw :: Exception e => e -> a
- throwIO :: Exception e => e -> IO a
- try :: Exception e => IO a -> IO (Either e a)
- forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- unless :: Applicative f => Bool -> f () -> f ()
- when :: Applicative f => Bool -> f () -> f ()
- liftIO :: MonadIO m => IO a -> m a
- runST :: (forall s. ST s a) -> a
- lift :: (MonadTrans t, Monad m) => m a -> t m a
- class FromJSON a
- class ToJSON a
- data Value
- (.=) :: (KeyValue kv, ToJSON v) => Text -> v -> kv
- genericParseJSON :: (Generic a, GFromJSON Zero (Rep a)) => Options -> Value -> Parser a
- genericToJSON :: (Generic a, GToJSON Value Zero (Rep a)) => Options -> a -> Value
- object :: [Pair] -> Value
- parseJSON :: FromJSON a => Value -> Parser a
- toJSON :: ToJSON a => a -> Value
- encodePretty :: ToJSON a => a -> ByteString
- (.&.) :: Bits a => a -> a -> a
- (.|.) :: Bits a => a -> a -> a
- data ByteString
- packCString :: CString -> IO ByteString
- packCStringLen :: CStringLen -> IO ByteString
- useAsCString :: ByteString -> (CString -> IO a) -> IO a
- useAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a
- isRight :: Either a b -> Bool
- fromRight' :: Either a b -> b
- foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b
- foldr' :: Foldable t => (a -> b -> b) -> b -> t a -> b
- data HashMap k v
- lookup :: (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
- data Int64
- fromJust :: Maybe a -> a
- isJust :: Maybe a -> Bool
- (<>) :: Semigroup a => a -> a -> a
- mconcat :: Monoid a => [a] -> a
- data Text
- pack :: String -> Text
- unpack :: Text -> String
- encodeUtf8 :: Text -> ByteString
- peekCStringLen :: CStringLen -> IO Text
- withCStringLen :: Text -> (CStringLen -> IO a) -> IO a
- appendFile :: FilePath -> Text -> IO ()
- getLine :: IO Text
- putStrLn :: Text -> IO ()
- readFile :: FilePath -> IO Text
- writeFile :: FilePath -> Text -> IO ()
- toStrict :: Text -> Text
- data Builder
- fromText :: Text -> Builder
- fromLazyText :: Text -> Builder
- fromString :: String -> Builder
- toLazyText :: Builder -> Text
- data UTCTime
- getCurrentTime :: IO UTCTime
- type POSIXTime = NominalDiffTime
- posixSecondsToUTCTime :: POSIXTime -> UTCTime
- utcTimeToPOSIXSeconds :: UTCTime -> POSIXTime
- class Typeable (a :: k)
- cast :: (Typeable a, Typeable b) => a -> Maybe b
- data Vector a
- (!) :: Vector a -> Int -> a
- fromList :: [a] -> Vector a
- ifoldl' :: (a -> Int -> b -> a) -> a -> Vector b -> a
- toList :: Vector a -> [a]
- singleton :: a -> Vector a
- data Word
- data Word8
- data Word16
- data Word32
- data Word64
- trace :: String -> a -> a
- data Ptr a
- castPtr :: Ptr a -> Ptr b
- newForeignPtr_ :: Ptr a -> IO (ForeignPtr a)
- nullPtr :: Ptr a
- peek :: Storable a => Ptr a -> IO a
- poke :: Storable a => Ptr a -> a -> IO ()
- plusPtr :: Ptr a -> Int -> Ptr b
- ptrToIntPtr :: Ptr a -> IntPtr
- type CString = Ptr CChar
- type CStringLen = (Ptr CChar, Int)
- newtype CChar = CChar Int8
- newtype CInt = CInt Int32
- newtype CLong = CLong Int64
- newtype CShort = CShort Int16
- newtype CSize = CSize Word64
- newtype CUChar = CUChar Word8
- newtype CUInt = CUInt Word32
- newtype CULong = CULong Word64
- newtype CUShort = CUShort Word16
- copyBytes :: Ptr a -> Ptr a -> Int -> IO ()
- class Storable a
- alignment :: Storable a => a -> Int
- peekByteOff :: Storable a => Ptr b -> Int -> IO a
- pokeByteOff :: Storable a => Ptr b -> Int -> a -> IO ()
- sizeOf :: Storable a => a -> Int
- class Generic a
- data Manager
- newManager :: ManagerSettings -> IO Manager
- parseRequest_ :: String -> Request
- withResponse :: Request -> Manager -> (Response BodyReader -> IO a) -> IO a
- type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
- data Request
- data RequestBodyLength
- lazyRequestBody :: Request -> IO ByteString
- queryString :: Request -> Query
- rawPathInfo :: Request -> ByteString
- requestBodyLength :: Request -> RequestBodyLength
- requestHeaders :: Request -> RequestHeaders
- requestMethod :: Request -> Method
- responseLBS :: Status -> ResponseHeaders -> ByteString -> Response
- (<|>) :: ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
- (<?>) :: ParsecT s u m a -> String -> ParsecT s u m a
- dateFormat :: Text -> UTCTime -> Text
- dateFormatISO8601 :: UTCTime -> Text
- dateParseISO8601 :: Text -> Either DateParseISO8601Error UTCTime
- errorShow :: Typeable e => e -> Text -> String
- ffiWithPtr :: Storable a => a -> (Ptr a -> IO b) -> IO b
- ffiWithPtrPtr :: (Ptr (Ptr a) -> IO b) -> IO b
- ffiWithUTF8 :: Text -> (CString -> IO a) -> IO a
- ffiWithUTF16 :: Text -> (Ptr Word16 -> IO a) -> IO a
- fsCopyDirectory :: Text -> Text -> IO ()
- httpContentTypeJSON :: Header
- httpRequestBodyJSON :: forall a. FromJSON a => Request -> IO a
- httpRequestBodyText :: Request -> IO Text
- httpRequestPath :: Request -> Text
- httpRequestHeaders :: Request -> Vector (Text, Text)
- httpRequestHeadersMap :: Request -> HashMap Text Text
- httpResponseBody :: Text -> Response BodyReader -> Int -> IO ByteString
- httpResponseBodyJSON :: forall a. FromJSON a => Text -> Response BodyReader -> Int -> IO a
- httpResponseBodyText :: Text -> Response BodyReader -> Int -> IO Text
- httpResponseHeaders :: Response a -> Vector (Text, Text)
- httpResponseHeadersMap :: Response a -> HashMap Text Text
- ioWithFileBytes :: Text -> (ByteString -> IO a) -> IO a
- ioWithFileText :: Text -> (Text -> IO a) -> IO a
- jsonDecodeFile :: forall a. FromJSON a => Text -> IO a
- jsonDecodeText :: forall a. FromJSON a => Text -> Either JSONDecodeError a
- jsonEncodeText :: ToJSON a => a -> Text
- jsonGet :: forall a. FromJSON a => Value -> Text -> Either JSONGetError a
- jsonUnwrapUnaryOptions :: Options
- mapFromVector :: (Eq k, Hashable k) => Vector v -> (Int -> v -> k) -> HashMap k v
- type Parser = Parsec Text ()
- parsecLineContains :: Text -> Parser Text
- parsecLinePrefix :: Text -> Parser Text
- parsecLineNoPrefix :: Text -> Parser Text
- parsecSkipLines :: Int -> Parser ()
- parsecSkipManyTill :: Text -> Parser ()
- parsecTry :: Parser a -> Parser a
- parsecWhitespace :: Parser ()
- parsecParseFile :: Parser a -> Text -> IO a
- parsecParseText :: Parser a -> Text -> Either ParsecParseTextError a
- pathIsAbsolute :: Text -> Bool
- pathConcat :: Text -> Text -> Text
- pathPrepend :: Text -> Text -> Text
- processSpawnAndWait :: Text -> Vector Text -> Text -> IO Int
- textDecodeUtf8 :: ByteString -> Text
- textFormat :: Text -> Vector Text -> Text
- textFormatParts :: Vector Text -> Vector Text -> Text
- textShow :: (Show a, Typeable a) => a -> Text
- textSplit :: Text -> Text -> Vector Text
Documentation
Instances
The Either
type represents values with two possibilities: a value of
type
is either Either
a b
or Left
a
.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").
Examples
The type
is the type of values which can be either
a Either
String
Int
String
or an Int
. The Left
constructor can be used only on
String
s, and the Right
constructor can be used only on Int
s:
>>>
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 Int
s.
>>>
:{
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"
Instances
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:
Instances
A fixed-precision integer type with at least the range [-2^29 .. 2^29-1]
.
The exact range for a given implementation can be determined by using
minBound
and maxBound
from the Bounded
class.
Instances
A value of type
is a computation which, when performed,
does some I/O before returning a value of type IO
aa
.
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.
Instances
The Maybe
type encapsulates an optional value. A value of type
either contains a value of type Maybe
aa
(represented as
),
or it is empty (represented as Just
aNothing
). 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.
Instances
Monad Maybe | Since: base-2.1 |
Functor Maybe | Since: base-2.1 |
Applicative Maybe | Since: base-2.1 |
Foldable Maybe | Since: base-2.1 |
Defined in Data.Foldable fold :: Monoid m => Maybe m -> m # foldMap :: Monoid m => (a -> m) -> Maybe a -> m # foldr :: (a -> b -> b) -> b -> Maybe a -> b # foldr' :: (a -> b -> b) -> b -> Maybe a -> b # foldl :: (b -> a -> b) -> b -> Maybe a -> b # foldl' :: (b -> a -> b) -> b -> Maybe a -> b # foldr1 :: (a -> a -> a) -> Maybe a -> a # foldl1 :: (a -> a -> a) -> Maybe a -> a # elem :: Eq a => a -> Maybe a -> Bool # maximum :: Ord a => Maybe a -> a # minimum :: Ord a => Maybe a -> a # | |
Traversable Maybe | Since: base-2.1 |
ToJSON1 Maybe | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Maybe a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Maybe a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Maybe a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Maybe a] -> Encoding # | |
FromJSON1 Maybe | |
Alternative Maybe | Since: base-2.1 |
MonadPlus Maybe | Since: base-2.1 |
Eq1 Maybe | Since: base-4.9.0.0 |
Ord1 Maybe | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 Maybe | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 Maybe | Since: base-4.9.0.0 |
MonadFailure Maybe | |
Hashable1 Maybe | |
Defined in Data.Hashable.Class | |
(Selector s, GToJSON enc arity (K1 i (Maybe a) :: Type -> Type), KeyValuePair enc pairs, Monoid pairs) => RecordToPairs enc pairs arity (S1 s (K1 i (Maybe a) :: Type -> Type)) | |
Defined in Data.Aeson.Types.ToJSON | |
(Selector s, FromJSON a) => RecordFromJSON arity (S1 s (K1 i (Maybe a) :: Type -> Type)) | |
Defined in Data.Aeson.Types.FromJSON | |
Eq a => Eq (Maybe a) | Since: base-2.1 |
Ord a => Ord (Maybe a) | Since: base-2.1 |
Read a => Read (Maybe a) | Since: base-2.1 |
Show a => Show (Maybe a) | Since: base-2.1 |
Generic (Maybe a) | |
Semigroup a => Semigroup (Maybe a) | Since: base-4.9.0.0 |
Semigroup a => Monoid (Maybe a) | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
Hashable a => Hashable (Maybe a) | |
Defined in Data.Hashable.Class | |
ToJSON a => ToJSON (Maybe a) | |
Defined in Data.Aeson.Types.ToJSON | |
FromJSON a => FromJSON (Maybe a) | |
SingKind a => SingKind (Maybe a) | Since: base-4.9.0.0 |
Generic1 Maybe | |
SingI (Nothing :: Maybe a) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
SingI a2 => SingI (Just a2 :: Maybe a1) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
type Failure Maybe | |
Defined in Basement.Monad | |
type Rep (Maybe a) | Since: base-4.6.0.0 |
data Sing (b :: Maybe a) | |
type DemoteRep (Maybe a) | |
Defined in GHC.Generics | |
type Rep1 Maybe | Since: base-4.6.0.0 |
Parsing of String
s, producing values.
Derived instances of Read
make the following assumptions, which
derived instances of Show
obey:
- If the constructor is defined to be an infix operator, then the
derived
Read
instance will parse only infix applications of the constructor (not the prefix form). - Associativity is not used to reduce the occurrence of parentheses, although precedence may be.
- If the constructor is defined using record syntax, the derived
Read
will parse only the record-syntax form, and furthermore, the fields must be given in the same order as the original declaration. - The derived
Read
instance allows arbitrary Haskell whitespace between tokens of the input string. Extra parentheses are also allowed.
For example, given the declarations
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:
instanceRead
T wherereadPrec
= ...readListPrec
=readListPrecDefault
Instances
Read Bool | Since: base-2.1 |
Read Char | Since: base-2.1 |
Read Double | Since: base-2.1 |
Read Float | Since: base-2.1 |
Read Int | Since: base-2.1 |
Read Int8 | Since: base-2.1 |
Read Int16 | Since: base-2.1 |
Read Int32 | Since: base-2.1 |
Read Int64 | Since: base-2.1 |
Read Integer | Since: base-2.1 |
Read Natural | Since: base-4.8.0.0 |
Read Ordering | Since: base-2.1 |
Read Word | Since: base-4.5.0.0 |
Read Word8 | Since: base-2.1 |
Read Word16 | Since: base-2.1 |
Read Word32 | Since: base-2.1 |
Read Word64 | Since: base-2.1 |
Read () | Since: base-2.1 |
Read Counts | |
Read State | |
Read Node | |
Read ByteString | |
Defined in Data.ByteString.Internal readsPrec :: Int -> ReadS ByteString # readList :: ReadS [ByteString] # readPrec :: ReadPrec ByteString # readListPrec :: ReadPrec [ByteString] # | |
Read ByteString | |
Defined in Data.ByteString.Lazy.Internal readsPrec :: Int -> ReadS ByteString # readList :: ReadS [ByteString] # readPrec :: ReadPrec ByteString # readListPrec :: ReadPrec [ByteString] # | |
Read Scientific | Supports the skipping of parentheses and whitespaces. Example: > read " ( (( -1.0e+3 ) ))" :: Scientific -1000.0 (Note: This |
Defined in Data.Scientific readsPrec :: Int -> ReadS Scientific # readList :: ReadS [Scientific] # readPrec :: ReadPrec Scientific # readListPrec :: ReadPrec [Scientific] # | |
Read Value | |
Read DotNetTime | |
Defined in Data.Aeson.Types.Internal readsPrec :: Int -> ReadS DotNetTime # readList :: ReadS [DotNetTime] # readPrec :: ReadPrec DotNetTime # readListPrec :: ReadPrec [DotNetTime] # | |
Read Void | Reading a Since: base-4.8.0.0 |
Read Version | Since: base-2.1 |
Read CDev | |
Read CIno | |
Read CMode | |
Read COff | |
Read CPid | |
Read CSsize | |
Read CGid | |
Read CNlink | |
Read CUid | |
Read CCc | |
Read CSpeed | |
Read CTcflag | |
Read CRLim | |
Read CBlkSize | |
Read CBlkCnt | |
Read CClockId | |
Read CFsBlkCnt | |
Read CFsFilCnt | |
Read CId | |
Read CKey | |
Read Fd | |
Read ExitCode | |
Read BufferMode | Since: base-4.2.0.0 |
Defined in GHC.IO.Handle.Types readsPrec :: Int -> ReadS BufferMode # readList :: ReadS [BufferMode] # readPrec :: ReadPrec BufferMode # readListPrec :: ReadPrec [BufferMode] # | |
Read Newline | Since: base-4.3.0.0 |
Read NewlineMode | Since: base-4.3.0.0 |
Defined in GHC.IO.Handle.Types readsPrec :: Int -> ReadS NewlineMode # readList :: ReadS [NewlineMode] # readPrec :: ReadPrec NewlineMode # readListPrec :: ReadPrec [NewlineMode] # | |
Read All | Since: base-2.1 |
Read Any | Since: base-2.1 |
Read Fixity | Since: base-4.6.0.0 |
Read Associativity | Since: base-4.6.0.0 |
Defined in GHC.Generics readsPrec :: Int -> ReadS Associativity # readList :: ReadS [Associativity] # | |
Read SourceUnpackedness | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
Read SourceStrictness | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
Read DecidedStrictness | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
Read CChar | |
Read CSChar | |
Read CUChar | |
Read CShort | |
Read CUShort | |
Read CInt | |
Read CUInt | |
Read CLong | |
Read CULong | |
Read CLLong | |
Read CULLong | |
Read CBool | |
Read CFloat | |
Read CDouble | |
Read CPtrdiff | |
Read CSize | |
Read CWchar | |
Read CSigAtomic | |
Defined in Foreign.C.Types readsPrec :: Int -> ReadS CSigAtomic # readList :: ReadS [CSigAtomic] # readPrec :: ReadPrec CSigAtomic # readListPrec :: ReadPrec [CSigAtomic] # | |
Read CClock | |
Read CTime | |
Read CUSeconds | |
Read CSUSeconds | |
Defined in Foreign.C.Types readsPrec :: Int -> ReadS CSUSeconds # readList :: ReadS [CSUSeconds] # readPrec :: ReadPrec CSUSeconds # readListPrec :: ReadPrec [CSUSeconds] # | |
Read CIntPtr | |
Read CUIntPtr | |
Read CIntMax | |
Read CUIntMax | |
Read WordPtr | |
Read IntPtr | |
Read IOMode | Since: base-4.2.0.0 |
Read Lexeme | Since: base-2.1 |
Read GeneralCategory | Since: base-2.1 |
Defined in GHC.Read | |
Read ShortByteString | |
Defined in Data.ByteString.Short.Internal | |
Read IntSet | |
Read Cookie | |
Read CookieJar | |
Read Proxy | |
Read StdMethod | |
Read AddrInfoFlag | |
Defined in Network.Socket.Info readsPrec :: Int -> ReadS AddrInfoFlag # readList :: ReadS [AddrInfoFlag] # | |
Read NameInfoFlag | |
Defined in Network.Socket.Info readsPrec :: Int -> ReadS NameInfoFlag # readList :: ReadS [NameInfoFlag] # | |
Read SocketType | |
Defined in Network.Socket.Types readsPrec :: Int -> ReadS SocketType # readList :: ReadS [SocketType] # readPrec :: ReadPrec SocketType # readListPrec :: ReadPrec [SocketType] # | |
Read Family | |
Read PortNumber | |
Defined in Network.Socket.Types readsPrec :: Int -> ReadS PortNumber # readList :: ReadS [PortNumber] # readPrec :: ReadPrec PortNumber # readListPrec :: ReadPrec [PortNumber] # | |
Read I16 | |
Read UnpackedUUID | |
Read UUID | |
Read DictionaryHash | |
Read a => Read [a] | Since: base-2.1 |
Read a => Read (Maybe a) | Since: base-2.1 |
(Integral a, Read a) => Read (Ratio a) | Since: base-2.1 |
Read p => Read (Par1 p) | Since: base-4.7.0.0 |
Read a => Read (Complex a) | Since: base-2.1 |
HasResolution a => Read (Fixed a) | Since: base-4.3.0.0 |
Read a => Read (Min a) | Since: base-4.9.0.0 |
Read a => Read (Max a) | Since: base-4.9.0.0 |
Read a => Read (First a) | Since: base-4.9.0.0 |
Read a => Read (Last a) | Since: base-4.9.0.0 |
Read m => Read (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup readsPrec :: Int -> ReadS (WrappedMonoid m) # readList :: ReadS [WrappedMonoid m] # readPrec :: ReadPrec (WrappedMonoid m) # readListPrec :: ReadPrec [WrappedMonoid m] # | |
Read a => Read (Option a) | Since: base-4.9.0.0 |
Read a => Read (Identity a) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
Read a => Read (First a) | Since: base-2.1 |
Read a => Read (Last a) | Since: base-2.1 |
Read a => Read (Dual a) | Since: base-2.1 |
Read a => Read (Sum a) | Since: base-2.1 |
Read a => Read (Product a) | Since: base-2.1 |
Read a => Read (NonEmpty a) | Since: base-4.11.0.0 |
(Read s, FoldCase s) => Read (CI s) | |
Read e => Read (IntMap e) | |
Read a => Read (Tree a) | |
Read a => Read (Seq a) | |
Read a => Read (ViewL a) | |
Read a => Read (ViewR a) | |
(Read a, Ord a) => Read (Set a) | |
Read a => Read (DList a) | |
Read a => Read (SmallArray a) | |
Defined in Data.Primitive.SmallArray readsPrec :: Int -> ReadS (SmallArray a) # readList :: ReadS [SmallArray a] # readPrec :: ReadPrec (SmallArray a) # readListPrec :: ReadPrec [SmallArray a] # | |
Read a => Read (Array a) | |
(Eq a, Hashable a, Read a) => Read (HashSet a) | |
(Read a, Storable a) => Read (Vector a) | |
(Read a, Prim a) => Read (Vector a) | |
Read a => Read (Vector a) | |
(Read a, Read b) => Read (Either a b) | Since: base-3.0 |
Read (V1 p) | Since: base-4.9.0.0 |
Read (U1 p) | Since: base-4.9.0.0 |
(Read a, Read b) => Read (a, b) | Since: base-2.1 |
(Eq k, Hashable k, Read k, Read e) => Read (HashMap k e) | |
(Ord k, Read k, Read e) => Read (Map k e) | |
(Ix a, Read a, Read b) => Read (Array a b) | Since: base-2.1 |
(Read a, Read b) => Read (Arg a b) | Since: base-4.9.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
(Read1 m, Read a) => Read (MaybeT m a) | |
(Read1 m, Read a) => Read (ListT m a) | |
Read (f p) => Read (Rec1 f p) | Since: base-4.7.0.0 |
(Read a, Read b, Read c) => Read (a, b, c) | Since: base-2.1 |
Read a => Read (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
Read (f a) => Read (Ap f a) | Since: base-4.12.0.0 |
Read (f a) => Read (Alt f a) | Since: base-4.8.0.0 |
a ~ b => Read (a :~: b) | Since: base-4.7.0.0 |
(Read1 f, Read a) => Read (IdentityT f a) | |
(Read e, Read1 m, Read a) => Read (ExceptT e m a) | |
(Read e, Read1 m, Read a) => Read (ErrorT e m a) | |
(Read w, Read1 m, Read a) => Read (WriterT w m a) | |
(Read w, Read1 m, Read a) => Read (WriterT w m a) | |
Read b => Read (Tagged s b) | |
Read c => Read (K1 i c p) | Since: base-4.7.0.0 |
(Read (f p), Read (g p)) => Read ((f :+: g) p) | Since: base-4.7.0.0 |
(Read (f p), Read (g p)) => Read ((f :*: g) p) | Since: base-4.7.0.0 |
(Read a, Read b, Read c, Read d) => Read (a, b, c, d) | Since: base-2.1 |
(Read1 f, Read1 g, Read a) => Read (Product f g a) | Since: base-4.9.0.0 |
(Read1 f, Read1 g, Read a) => Read (Sum f g a) | Since: base-4.9.0.0 |
a ~~ b => Read (a :~~: b) | Since: base-4.10.0.0 |
Read (f p) => Read (M1 i c f p) | Since: base-4.7.0.0 |
Read (f (g p)) => Read ((f :.: g) p) | Since: base-4.7.0.0 |
(Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) | Since: base-2.1 |
(Read1 f, Read1 g, Read a) => Read (Compose f g a) | Since: base-4.9.0.0 |
(Read a, Read b, Read c, Read d, Read e, Read f) => Read (a, b, c, d, e, f) | Since: base-2.1 |
(Read a, Read b, Read c, Read d, Read e, Read f, Read g) => Read (a, b, c, d, e, f, g) | Since: base-2.1 |
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) => Read (a, b, c, d, e, f, g, h) | Since: base-2.1 |
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i) => Read (a, b, c, d, e, f, g, h, i) | Since: base-2.1 |
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j) => Read (a, b, c, d, e, f, g, h, i, j) | Since: base-2.1 |
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k) => Read (a, b, c, d, e, f, g, h, i, j, k) | Since: base-2.1 |
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l) => Read (a, b, c, d, e, f, g, h, i, j, k, l) | Since: base-2.1 |
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) | Since: base-2.1 |
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | Since: base-2.1 |
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n, Read o) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | Since: base-2.1 |
Defined in GHC.Read |
Conversion of values to readable String
s.
Derived instances of Show
have the following properties, which
are compatible with derived instances of Read
:
- The result of
show
is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used. - If the constructor is defined to be an infix operator, then
showsPrec
will produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
x
is less thand
(associativity is ignored). Thus, ifd
is0
then the result is never surrounded in parentheses; ifd
is11
it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
show
will produce the record-syntax form, with the fields given in the same order as the original declaration.
For example, given the declarations
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,
produces the stringshow
(Leaf 1 :^: Leaf 2 :^: Leaf 3)"Leaf 1 :^: (Leaf 2 :^: Leaf 3)"
.
Instances
(/) :: Fractional a => a -> a -> a infixl 7 #
fractional division
($) :: (a -> b) -> a -> b infixr 0 #
Application operator. This operator is redundant, since ordinary
application (f x)
means the same as (f
. However, $
x)$
has
low, right-associative binding precedence, so it sometimes allows
parentheses to be omitted; for example:
f $ g $ h x = f (g (h x))
It is also useful in higher-order situations, such as
,
or map
($
0) xs
.zipWith
($
) fs xs
Note that ($)
is levity-polymorphic in its result type, so that
foo $ True where foo :: Bool -> Int#
is well-typed
($!) :: (a -> b) -> a -> b infixr 0 #
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.
(>>) :: Monad m => m a -> m b -> m b infixl 1 #
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 -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an Either
Int
Int
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)
(<*>) :: Applicative f => f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
error :: HasCallStack => [Char] -> a #
error
stops execution and displays an error message.
flip :: (a -> b -> c) -> b -> a -> c #
takes its (first) two arguments in the reverse order of flip
ff
.
>>>
flip (++) "hello" "world"
"worldhello"
floor :: (RealFrac a, Integral b) => a -> b #
returns the greatest integer not greater than floor
xx
fromIntegral :: (Integral a, Num b) => a -> b #
general coercion from integral types
length :: Foldable t => t a -> Int #
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.
mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) #
Map each element of a structure to a monadic action, evaluate
these actions from left to right, and collect the results. For
a version that ignores the results see mapM_
.
mod :: Integral a => a -> a -> a infixl 7 #
integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
pure :: Applicative f => a -> f a #
Lift a value.
read :: Read a => String -> a #
The read
function reads input from a string, which must be
completely consumed by the input process. read
fails with an error
if the
parse is unsuccessful, and it is therefore discouraged from being used in
real applications. Use readMaybe
or readEither
for safe alternatives.
>>>
read "123" :: Int
123
>>>
read "hello" :: Int
*** Exception: Prelude.read: no parse
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.
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) #
Evaluate each monadic action in the structure from left to
right, and collect the results. For a version that ignores the
results see sequence_
.
sequence_ :: (Foldable t, Monad m) => t (m a) -> m () #
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
.
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.
undefined :: HasCallStack => a #
data SomeException #
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
.
Instances
Show SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # | |
Exception SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type |
:: IO a | computation to run first ("acquire resource") |
-> (a -> IO b) | computation to run last ("release resource") |
-> (a -> IO c) | computation to run in-between |
-> IO c |
When you want to acquire a resource, do some work with it, and
then release the resource, it is a good idea to use bracket
,
because bracket
will install the necessary exception handler to
release the resource in the event that an exception is raised
during the computation. If an exception is raised, then bracket
will
re-raise the exception (after performing the release).
A common example is opening a file:
bracket (openFile "filename" ReadMode) (hClose) (\fileHandle -> do { ... })
The arguments to bracket
are in this order so that we can partially apply
it, e.g.:
withFile name mode = bracket (openFile name mode) hClose
bracket_ :: IO a -> IO b -> IO c -> IO c #
A variant of bracket
where the return value from the first computation
is not required.
:: Exception e | |
=> IO a | The computation to run |
-> (e -> IO a) | Handler to invoke if an exception is raised |
-> IO a |
This is the simplest of the exception-catching functions. It takes a single argument, runs it, and if an exception is raised the "handler" is executed, with the value of the exception passed as an argument. Otherwise, the result is returned as normal. For example:
catch (readFile f) (\e -> do let err = show (e :: IOException) hPutStr stderr ("Warning: Couldn't open " ++ f ++ ": " ++ err) return "")
Note that we have to give a type signature to e
, or the program
will not typecheck as the type is ambiguous. While it is possible
to catch exceptions of any type, see the section "Catching all
exceptions" (in Control.Exception) for an explanation of the problems with doing so.
For catching exceptions in pure (non-IO
) expressions, see the
function evaluate
.
Note that due to Haskell's unspecified evaluation order, an
expression may throw one of several possible exceptions: consider
the expression (error "urk") + (1 `div` 0)
. Does
the expression throw
ErrorCall "urk"
, or DivideByZero
?
The answer is "it might throw either"; the choice is
non-deterministic. If you are catching any type of exception then you
might catch either. If you are calling catch
with type
IO Int -> (ArithException -> IO Int) -> IO Int
then the handler may
get run with DivideByZero
as an argument, or an ErrorCall "urk"
exception may be propogated further up. If you call it again, you
might get a the opposite behaviour. This is ok, because catch
is an
IO
computation.
throw :: Exception e => e -> a #
Throw an exception. Exceptions may be thrown from purely
functional code, but may only be caught within the IO
monad.
throwIO :: Exception e => e -> IO a #
A variant of throw
that can only be used within the IO
monad.
Although throwIO
has a type that is an instance of the type of throw
, the
two functions are subtly different:
throw e `seq` x ===> throw e throwIO e `seq` x ===> x
The first example will cause the exception e
to be raised,
whereas the second one won't. In fact, throwIO
will only cause
an exception to be raised when it is used within the IO
monad.
The throwIO
variant should be used in preference to throw
to
raise an exception within the IO
monad because it guarantees
ordering with respect to other IO
operations, whereas throw
does not.
try :: Exception e => IO a -> IO (Either e a) #
Similar to catch
, but returns an Either
result which is
(
if no exception of type Right
a)e
was raised, or (
if an exception of type Left
ex)e
was raised and its value is ex
.
If any other type of exception is raised than it will be propogated
up to the next enclosing exception handler.
try a = catch (Right `liftM` a) (return . Left)
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) #
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.
runST :: (forall s. ST s a) -> a #
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.
lift :: (MonadTrans t, Monad m) => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.
A type that can be converted from JSON, with the possibility of failure.
In many cases, you can get the compiler to generate parsing code for you (see below). To begin, let's cover writing an instance by hand.
There are various reasons a conversion could fail. For example, an
Object
could be missing a required key, an Array
could be of
the wrong size, or a value could be of an incompatible type.
The basic ways to signal a failed conversion are as follows:
fail
yields a custom error message: it is the recommended way of reporting a failure;empty
(ormzero
) is uninformative: use it when the error is meant to be caught by some(
;<|>
)typeMismatch
can be used to report a failure when the encountered value is not of the expected JSON type;unexpected
is an appropriate alternative when more than one type may be expected, or to keep the expected type implicit.
prependFailure
(or modifyFailure
) add more information to a parser's
error messages.
An example type and instance using typeMismatch
and prependFailure
:
-- Allow ourselves to writeText
literals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instanceFromJSON
Coord whereparseJSON
(Object
v) = Coord<$>
v.:
"x"<*>
v.:
"y" -- We do not expect a non-Object
value here. -- We could useempty
to fail, buttypeMismatch
-- gives a much more informative error message.parseJSON
invalid =prependFailure
"parsing Coord failed, " (typeMismatch
"Object" invalid)
For this common case of only being concerned with a single
type of JSON value, the functions withObject
, withScientific
, etc.
are provided. Their use is to be preferred when possible, since
they are more terse. Using withObject
, we can rewrite the above instance
(assuming the same language extension and data type) as:
instanceFromJSON
Coord whereparseJSON
=withObject
"Coord" $ \v -> Coord<$>
v.:
"x"<*>
v.:
"y"
Instead of manually writing your FromJSON
instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
parseJSON
.
To use the second, simply add a deriving
clause to your
datatype and declare a Generic
FromJSON
instance for your datatype without giving
a definition for parseJSON
.
For example, the previous example can be simplified to just:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics data Coord = Coord { x :: Double, y :: Double } derivingGeneric
instanceFromJSON
Coord
The default implementation will be equivalent to
parseJSON =
; if you need different
options, you can customize the generic decoding by defining:genericParseJSON
defaultOptions
customOptions =defaultOptions
{fieldLabelModifier
=map
toUpper
} instanceFromJSON
Coord whereparseJSON
=genericParseJSON
customOptions
Instances
A type that can be converted to JSON.
Instances in general must specify toJSON
and should (but don't need
to) specify toEncoding
.
An example type and instance:
-- Allow ourselves to writeText
literals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instanceToJSON
Coord wheretoJSON
(Coord x y) =object
["x".=
x, "y".=
y]toEncoding
(Coord x y) =pairs
("x".=
x<>
"y".=
y)
Instead of manually writing your ToJSON
instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
toJSON
.
To use the second, simply add a deriving
clause to your
datatype and declare a Generic
ToJSON
instance. If you require nothing other than
defaultOptions
, it is sufficient to write (and this is the only
alternative where the default toJSON
implementation is sufficient):
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics data Coord = Coord { x :: Double, y :: Double } derivingGeneric
instanceToJSON
Coord wheretoEncoding
=genericToEncoding
defaultOptions
If on the other hand you wish to customize the generic decoding, you have to implement both methods:
customOptions =defaultOptions
{fieldLabelModifier
=map
toUpper
} instanceToJSON
Coord wheretoJSON
=genericToJSON
customOptionstoEncoding
=genericToEncoding
customOptions
Previous versions of this library only had the toJSON
method. Adding
toEncoding
had two reasons:
- toEncoding is more efficient for the common case that the output of
toJSON
is directly serialized to aByteString
. Further, expressing either method in terms of the other would be non-optimal. - The choice of defaults allows a smooth transition for existing users:
Existing instances that do not define
toEncoding
still compile and have the correct semantics. This is ensured by making the default implementation oftoEncoding
usetoJSON
. This produces correct results, but since it performs an intermediate conversion to aValue
, it will be less efficient than directly emitting anEncoding
. (this also means that specifying nothing more thaninstance ToJSON Coord
would be sufficient as a generically decoding instance, but there probably exists no good reason to not specifytoEncoding
in new instances.)
Instances
A JSON value represented as a Haskell value.
Instances
Eq Value | |
Data Value | |
Defined in Data.Aeson.Types.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Value -> c Value # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Value # dataTypeOf :: Value -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Value) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Value) # gmapT :: (forall b. Data b => b -> b) -> Value -> Value # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r # gmapQ :: (forall d. Data d => d -> u) -> Value -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Value -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Value -> m Value # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value # | |
Read Value | |
Show Value | |
IsString Value | |
Defined in Data.Aeson.Types.Internal fromString :: String -> Value # | |
Generic Value | |
Lift Value | |
Hashable Value | |
Defined in Data.Aeson.Types.Internal | |
ToJSON Value | |
Defined in Data.Aeson.Types.ToJSON | |
KeyValue Object | Constructs a singleton |
KeyValue Pair | |
FromJSON Value | |
NFData Value | |
Defined in Data.Aeson.Types.Internal | |
FromString Encoding | |
Defined in Data.Aeson.Types.ToJSON fromString :: String -> Encoding | |
FromString Value | |
Defined in Data.Aeson.Types.ToJSON fromString :: String -> Value | |
GToJSON Encoding arity (U1 :: Type -> Type) | |
GToJSON Value arity (V1 :: Type -> Type) | |
GToJSON Value arity (U1 :: Type -> Type) | |
ToJSON1 f => GToJSON Encoding One (Rec1 f) | |
ToJSON1 f => GToJSON Value One (Rec1 f) | |
ToJSON a => GToJSON Encoding arity (K1 i a :: Type -> Type) | |
(EncodeProduct arity a, EncodeProduct arity b) => GToJSON Encoding arity (a :*: b) | |
ToJSON a => GToJSON Value arity (K1 i a :: Type -> Type) | |
(WriteProduct arity a, WriteProduct arity b, ProductSize a, ProductSize b) => GToJSON Value arity (a :*: b) | |
(ToJSON1 f, GToJSON Encoding One g) => GToJSON Encoding One (f :.: g) | |
(ToJSON1 f, GToJSON Value One g) => GToJSON Value One (f :.: g) | |
FromPairs Value (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
v ~ Value => KeyValuePair v (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
(GToJSON Encoding arity a, ConsToJSON Encoding arity a, Constructor c) => SumToJSON' TwoElemArray Encoding arity (C1 c a) | |
Defined in Data.Aeson.Types.ToJSON | |
(GToJSON Value arity a, ConsToJSON Value arity a, Constructor c) => SumToJSON' TwoElemArray Value arity (C1 c a) | |
Defined in Data.Aeson.Types.ToJSON | |
type Rep Value | |
Defined in Data.Aeson.Types.Internal type Rep Value = D1 (MetaData "Value" "Data.Aeson.Types.Internal" "aeson-1.4.3.0-CKhfOL9YUanCoDzOlq0iJC" False) ((C1 (MetaCons "Object" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Object)) :+: (C1 (MetaCons "Array" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Array)) :+: C1 (MetaCons "String" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text)))) :+: (C1 (MetaCons "Number" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Scientific)) :+: (C1 (MetaCons "Bool" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Bool)) :+: C1 (MetaCons "Null" PrefixI False) (U1 :: Type -> Type)))) |
genericParseJSON :: (Generic a, GFromJSON Zero (Rep a)) => Options -> Value -> Parser a #
A configurable generic JSON decoder. This function applied to
defaultOptions
is used as the default for parseJSON
when the
type is an instance of Generic
.
genericToJSON :: (Generic a, GToJSON Value Zero (Rep a)) => Options -> a -> Value #
A configurable generic JSON creator. This function applied to
defaultOptions
is used as the default for toJSON
when the type
is an instance of Generic
.
encodePretty :: ToJSON a => a -> ByteString #
data ByteString #
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.
Instances
packCString :: CString -> IO ByteString #
O(n). Construct a new ByteString
from a CString
. The
resulting ByteString
is an immutable copy of the original
CString
, and is managed on the Haskell heap. The original
CString
must be null terminated.
packCStringLen :: CStringLen -> IO ByteString #
O(n). Construct a new ByteString
from a CStringLen
. The
resulting ByteString
is an immutable copy of the original CStringLen
.
The ByteString
is a normal Haskell value and will be managed on the
Haskell heap.
useAsCString :: ByteString -> (CString -> IO a) -> IO a #
O(n) construction Use a ByteString
with a function requiring a
null-terminated CString
. The CString
is a copy and will be freed
automatically; it must not be stored or used after the
subcomputation finishes.
useAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a #
O(n) construction Use a ByteString
with a function requiring a CStringLen
.
As for useAsCString
this function makes a copy of the original ByteString
.
It must not be stored or used after the subcomputation finishes.
isRight :: Either a b -> Bool #
Return True
if the given value is a Right
-value, False
otherwise.
Examples
Basic usage:
>>>
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
Since: base-4.7.0.0
fromRight' :: Either a b -> b #
Extracts the element out of a Right
and
throws an error if its argument take the form
.Left
_
Using Control.Lens
:
fromRight'
x ≡ x^?!_Right
>>>
fromRight' (Right 12)
12
foldl' :: Foldable t => (b -> a -> 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
foldr' :: Foldable t => (a -> b -> b) -> b -> t a -> b #
Right-associative fold of a structure, but with strict application of the operator.
A map from keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
Instances
KeyValue Object | Constructs a singleton |
Eq2 HashMap | |
Ord2 HashMap | |
Defined in Data.HashMap.Base | |
Show2 HashMap | |
Hashable2 HashMap | |
Defined in Data.HashMap.Base | |
Functor (HashMap k) | |
Foldable (HashMap k) | |
Defined in Data.HashMap.Base fold :: Monoid m => HashMap k m -> m # foldMap :: Monoid m => (a -> m) -> HashMap k a -> m # foldr :: (a -> b -> b) -> b -> HashMap k a -> b # foldr' :: (a -> b -> b) -> b -> HashMap k a -> b # foldl :: (b -> a -> b) -> b -> HashMap k a -> b # foldl' :: (b -> a -> b) -> b -> HashMap k a -> b # foldr1 :: (a -> a -> a) -> HashMap k a -> a # foldl1 :: (a -> a -> a) -> HashMap k a -> a # toList :: HashMap k a -> [a] # length :: HashMap k a -> Int # elem :: Eq a => a -> HashMap k a -> Bool # maximum :: Ord a => HashMap k a -> a # minimum :: Ord a => HashMap k a -> a # | |
Traversable (HashMap k) | |
ToJSONKey k => ToJSON1 (HashMap k) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> HashMap k a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [HashMap k a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> HashMap k a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [HashMap k a] -> Encoding # | |
(FromJSONKey k, Eq k, Hashable k) => FromJSON1 (HashMap k) | |
Eq k => Eq1 (HashMap k) | |
Ord k => Ord1 (HashMap k) | |
Defined in Data.HashMap.Base | |
(Eq k, Hashable k, Read k) => Read1 (HashMap k) | |
Defined in Data.HashMap.Base | |
Show k => Show1 (HashMap k) | |
Hashable k => Hashable1 (HashMap k) | |
Defined in Data.HashMap.Base | |
(Eq k, Hashable k) => IsList (HashMap k v) | |
(Eq k, Eq v) => Eq (HashMap k v) | |
(Data k, Data v, Eq k, Hashable k) => Data (HashMap k v) | |
Defined in Data.HashMap.Base gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> HashMap k v -> c (HashMap k v) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (HashMap k v) # toConstr :: HashMap k v -> Constr # dataTypeOf :: HashMap k v -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (HashMap k v)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (HashMap k v)) # gmapT :: (forall b. Data b => b -> b) -> HashMap k v -> HashMap k v # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> HashMap k v -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> HashMap k v -> r # gmapQ :: (forall d. Data d => d -> u) -> HashMap k v -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> HashMap k v -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> HashMap k v -> m (HashMap k v) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> HashMap k v -> m (HashMap k v) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> HashMap k v -> m (HashMap k v) # | |
(Ord k, Ord v) => Ord (HashMap k v) | The order is total. Note: Because the hash is not guaranteed to be stable across library
versions, OSes, or architectures, neither is an actual order of elements in
|
Defined in Data.HashMap.Base | |
(Eq k, Hashable k, Read k, Read e) => Read (HashMap k e) | |
(Show k, Show v) => Show (HashMap k v) | |
(Eq k, Hashable k) => Semigroup (HashMap k v) | |
(Eq k, Hashable k) => Monoid (HashMap k v) | |
(Hashable k, Hashable v) => Hashable (HashMap k v) | |
Defined in Data.HashMap.Base | |
(ToJSON v, ToJSONKey k) => ToJSON (HashMap k v) | |
Defined in Data.Aeson.Types.ToJSON | |
(FromJSON v, FromJSONKey k, Eq k, Hashable k) => FromJSON (HashMap k v) | |
(NFData k, NFData v) => NFData (HashMap k v) | |
Defined in Data.HashMap.Base | |
type Item (HashMap k v) | |
Defined in Data.HashMap.Base |
lookup :: (Eq k, Hashable k) => k -> HashMap k v -> Maybe v #
O(log n) Return the value to which the specified key is mapped,
or Nothing
if this map contains no mapping for the key.
64-bit signed integer type
Instances
mconcat :: Monoid a => [a] -> a #
Fold a list using the monoid.
For most types, the default definition for mconcat
will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
A space efficient, packed, unboxed Unicode text type.
Instances
Hashable Text | |
Defined in Data.Hashable.Class | |
ToJSON Text | |
Defined in Data.Aeson.Types.ToJSON | |
KeyValue Object | Constructs a singleton |
KeyValue Pair | |
ToJSONKey Text | |
Defined in Data.Aeson.Types.ToJSON | |
FromJSON Text | |
FromJSONKey Text | |
Defined in Data.Aeson.Types.FromJSON | |
Chunk Text | |
Defined in Data.Attoparsec.Internal.Types | |
FoldCase Text | |
Defined in Data.CaseInsensitive.Internal | |
Monad m => Stream Text m Char | |
FromPairs Value (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
v ~ Value => KeyValuePair v (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
type State Text | |
Defined in Data.Attoparsec.Internal.Types | |
type ChunkElem Text | |
Defined in Data.Attoparsec.Internal.Types | |
type Item Text | |
encodeUtf8 :: Text -> ByteString #
Encode text using UTF-8 encoding.
peekCStringLen :: CStringLen -> IO Text #
O(n) Decode a C string with explicit length, which is assumed
to have been encoded as UTF-8. If decoding fails, a
UnicodeException
is thrown.
Since: text-1.0.0.0
withCStringLen :: Text -> (CStringLen -> IO a) -> IO a #
Marshal a Text
into a C string encoded as UTF-8 in temporary
storage, with explicit length information. The encoded string may
contain NUL bytes, and is not followed by a trailing NUL byte.
The temporary storage is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this function returns.
Since: text-1.0.0.0
appendFile :: FilePath -> Text -> IO () #
Write a string the end of a file.
readFile :: FilePath -> IO Text #
The readFile
function reads a file and returns the contents of
the file as a string. The entire file is read strictly, as with
getContents
.
writeFile :: FilePath -> Text -> IO () #
Write a string to a file. The file is truncated to zero length before writing begins.
A Builder
is an efficient way to build lazy Text
values.
There are several functions for constructing builders, but only one
to inspect them: to extract any data, you have to turn them into
lazy Text
values using toLazyText
.
Internally, a builder constructs a lazy Text
by filling arrays
piece by piece. As each buffer is filled, it is 'popped' off, to
become a new chunk of the resulting lazy Text
. All this is
hidden from the user of the Builder
.
O(1). A Builder
taking a Text
, satisfying
toLazyText
(fromText
t) =fromChunks
[t]
fromLazyText :: Text -> Builder #
O(1). A Builder
taking a lazy Text
, satisfying
toLazyText
(fromLazyText
t) = t
fromString :: String -> Builder #
O(1). A Builder taking a String
, satisfying
toLazyText
(fromString
s) =fromChunks
[S.pack s]
toLazyText :: Builder -> Text #
O(n). Extract a lazy Text
from a Builder
with a default
buffer size. The construction work takes place if and when the
relevant part of the lazy Text
is demanded.
This is the simplest representation of UTC. It consists of the day number, and a time offset from midnight. Note that if a day has a leap second added to it, it will have 86401 seconds.
Instances
Eq UTCTime | |
Data UTCTime | |
Defined in Data.Time.Clock.Internal.UTCTime gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> UTCTime -> c UTCTime # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c UTCTime # toConstr :: UTCTime -> Constr # dataTypeOf :: UTCTime -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c UTCTime) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UTCTime) # gmapT :: (forall b. Data b => b -> b) -> UTCTime -> UTCTime # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UTCTime -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UTCTime -> r # gmapQ :: (forall d. Data d => d -> u) -> UTCTime -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> UTCTime -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime # | |
Ord UTCTime | |
Defined in Data.Time.Clock.Internal.UTCTime | |
ToJSON UTCTime | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSONKey UTCTime | |
Defined in Data.Aeson.Types.ToJSON | |
FromJSON UTCTime | |
FromJSONKey UTCTime | |
NFData UTCTime | |
Defined in Data.Time.Clock.Internal.UTCTime | |
FormatTime UTCTime | |
Defined in Data.Time.Format formatCharacter :: Char -> Maybe (TimeLocale -> Maybe NumericPadOption -> Maybe Int -> UTCTime -> String) # | |
ParseTime UTCTime | |
Defined in Data.Time.Format.Parse |
getCurrentTime :: IO UTCTime #
Get the current UTCTime
from the system clock.
type POSIXTime = NominalDiffTime #
POSIX time is the nominal time since 1970-01-01 00:00 UTC
To convert from a CTime
or EpochTime
, use realToFrac
.
The class Typeable
allows a concrete representation of a type to
be calculated.
typeRep#
Boxed vectors, supporting efficient slicing.
Instances
Monad Vector | |
Functor Vector | |
MonadFail Vector | |
Defined in Data.Vector | |
Applicative Vector | |
Foldable Vector | |
Defined in Data.Vector fold :: Monoid m => Vector m -> m # foldMap :: Monoid m => (a -> m) -> Vector a -> m # foldr :: (a -> b -> b) -> b -> Vector a -> b # foldr' :: (a -> b -> b) -> b -> Vector a -> b # foldl :: (b -> a -> b) -> b -> Vector a -> b # foldl' :: (b -> a -> b) -> b -> Vector a -> b # foldr1 :: (a -> a -> a) -> Vector a -> a # foldl1 :: (a -> a -> a) -> Vector a -> a # elem :: Eq a => a -> Vector a -> Bool # maximum :: Ord a => Vector a -> a # minimum :: Ord a => Vector a -> a # | |
Traversable Vector | |
ToJSON1 Vector | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Vector a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Vector a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Vector a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Vector a] -> Encoding # | |
FromJSON1 Vector | |
Alternative Vector | |
MonadPlus Vector | |
Eq1 Vector | |
Ord1 Vector | |
Defined in Data.Vector | |
Read1 Vector | |
Defined in Data.Vector | |
Show1 Vector | |
MonadZip Vector | |
Vector Vector a | |
Defined in Data.Vector basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) a -> m (Vector a) # basicUnsafeThaw :: PrimMonad m => Vector a -> m (Mutable Vector (PrimState m) a) # basicLength :: Vector a -> Int # basicUnsafeSlice :: Int -> Int -> Vector a -> Vector a # basicUnsafeIndexM :: Monad m => Vector a -> Int -> m a # basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) a -> Vector a -> m () # | |
IsList (Vector a) | |
Eq a => Eq (Vector a) | |
Data a => Data (Vector a) | |
Defined in Data.Vector gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Vector a -> c (Vector a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Vector a) # toConstr :: Vector a -> Constr # dataTypeOf :: Vector a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Vector a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Vector a)) # gmapT :: (forall b. Data b => b -> b) -> Vector a -> Vector a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Vector a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Vector a -> r # gmapQ :: (forall d. Data d => d -> u) -> Vector a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Vector a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Vector a -> m (Vector a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Vector a -> m (Vector a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Vector a -> m (Vector a) # | |
Ord a => Ord (Vector a) | |
Defined in Data.Vector | |
Read a => Read (Vector a) | |
Show a => Show (Vector a) | |
Semigroup (Vector a) | |
Monoid (Vector a) | |
ToJSON a => ToJSON (Vector a) | |
Defined in Data.Aeson.Types.ToJSON | |
FromJSON a => FromJSON (Vector a) | |
NFData a => NFData (Vector a) | |
Defined in Data.Vector | |
type Mutable Vector | |
Defined in Data.Vector | |
type Item (Vector a) | |
Defined in Data.Vector |
ifoldl' :: (a -> Int -> b -> a) -> a -> Vector b -> a #
O(n) Left fold with strict accumulator (function applied to each element and its index)
Instances
8-bit unsigned integer type
Instances
16-bit unsigned integer type
Instances
32-bit unsigned integer type
Instances
64-bit unsigned integer type
Instances
The trace
function outputs the trace message given as its first argument,
before returning the second argument as its result.
For example, this returns the value of f x
but first outputs the message.
>>>
let x = 123; f = show
>>>
trace ("calling f with x = " ++ show x) (f x)
"calling f with x = 123 123"
The trace
function should only be used for debugging, or for monitoring
execution. The function is not referentially transparent: its type indicates
that it is a pure function but it has the side effect of outputting the
trace message.
A value of type
represents a pointer to an object, or an
array of objects, which may be marshalled to or from Haskell values
of type Ptr
aa
.
The type a
will often be an instance of class
Storable
which provides the marshalling operations.
However this is not essential, and you can provide your own operations
to access the pointer. For example you might write small foreign
functions to get or set the fields of a C struct
.
Instances
Generic1 (URec (Ptr ()) :: k -> Type) | |
Eq (Ptr a) | Since: base-2.1 |
Ord (Ptr a) | Since: base-2.1 |
Show (Ptr a) | Since: base-2.1 |
Hashable (Ptr a) | |
Defined in Data.Hashable.Class | |
Storable (Ptr a) | Since: base-2.1 |
Prim (Ptr a) | |
Defined in Data.Primitive.Types alignment# :: Ptr a -> Int# # indexByteArray# :: ByteArray# -> Int# -> Ptr a # readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, Ptr a#) # writeByteArray# :: MutableByteArray# s -> Int# -> Ptr a -> State# s -> State# s # setByteArray# :: MutableByteArray# s -> Int# -> Int# -> Ptr a -> State# s -> State# s # indexOffAddr# :: Addr# -> Int# -> Ptr a # readOffAddr# :: Addr# -> Int# -> State# s -> (#State# s, Ptr a#) # writeOffAddr# :: Addr# -> Int# -> Ptr a -> State# s -> State# s # setOffAddr# :: Addr# -> Int# -> Int# -> Ptr a -> State# s -> State# s # | |
Functor (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
Foldable (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => URec (Ptr ()) m -> m # foldMap :: Monoid m => (a -> m) -> URec (Ptr ()) a -> m # foldr :: (a -> b -> b) -> b -> URec (Ptr ()) a -> b # foldr' :: (a -> b -> b) -> b -> URec (Ptr ()) a -> b # foldl :: (b -> a -> b) -> b -> URec (Ptr ()) a -> b # foldl' :: (b -> a -> b) -> b -> URec (Ptr ()) a -> b # foldr1 :: (a -> a -> a) -> URec (Ptr ()) a -> a # foldl1 :: (a -> a -> a) -> URec (Ptr ()) a -> a # toList :: URec (Ptr ()) a -> [a] # null :: URec (Ptr ()) a -> Bool # length :: URec (Ptr ()) a -> Int # elem :: Eq a => a -> URec (Ptr ()) a -> Bool # maximum :: Ord a => URec (Ptr ()) a -> a # minimum :: Ord a => URec (Ptr ()) a -> a # | |
Traversable (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Traversable | |
Eq (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Ord (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Defined in GHC.Generics compare :: URec (Ptr ()) p -> URec (Ptr ()) p -> Ordering # (<) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (<=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # max :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # min :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # | |
Generic (URec (Ptr ()) p) | |
data URec (Ptr ()) (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 |
type Rep1 (URec (Ptr ()) :: k -> Type) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
type Rep (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Defined in GHC.Generics |
newForeignPtr_ :: Ptr a -> IO (ForeignPtr a) #
Turns a plain memory reference into a foreign pointer that may be
associated with finalizers by using addForeignPtrFinalizer
.
peek :: Storable a => Ptr a -> IO a #
Read a value from the given memory location.
Note that the peek and poke functions might require properly
aligned addresses to function correctly. This is architecture
dependent; thus, portable code should ensure that when peeking or
poking values of some type a
, the alignment
constraint for a
, as given by the function
alignment
is fulfilled.
poke :: Storable a => Ptr a -> a -> IO () #
Write the given value to the given memory location. Alignment
restrictions might apply; see peek
.
ptrToIntPtr :: Ptr a -> IntPtr #
casts a Ptr
to an IntPtr
type CStringLen = (Ptr CChar, Int) #
A string with explicit length information in bytes instead of a terminating NUL (allowing NUL characters in the middle of the string).
Haskell type representing the C char
type.
Instances
Haskell type representing the C int
type.
Instances
Haskell type representing the C long
type.
Instances
Haskell type representing the C short
type.
Instances
Haskell type representing the C size_t
type.
Instances
Haskell type representing the C unsigned char
type.
Instances
Haskell type representing the C unsigned int
type.
Instances
Haskell type representing the C unsigned long
type.
Instances
Haskell type representing the C unsigned short
type.
Instances
copyBytes :: Ptr a -> Ptr a -> Int -> IO () #
Copies the given number of bytes from the second area (source) into the first (destination); the copied areas may not overlap
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
, for some
Ptr
aa
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
.
sizeOf, alignment, (peek | peekElemOff | peekByteOff), (poke | pokeElemOff | pokeByteOff)
Instances
alignment :: Storable a => a -> Int #
Computes the alignment constraint of the argument. An
alignment constraint x
is fulfilled by any address divisible
by x
. The value of the argument is not used.
peekByteOff :: Storable a => Ptr b -> Int -> IO a #
Read a value from a memory location given by a base address and offset. The following equality holds:
peekByteOff addr off = peek (addr `plusPtr` off)
pokeByteOff :: Storable a => Ptr b -> Int -> a -> IO () #
Write a value to a memory location given by a base address and offset. The following equality holds:
pokeByteOff addr off x = poke (addr `plusPtr` off) x
sizeOf :: Storable a => a -> Int #
Computes the storage requirements (in bytes) of the argument. The value of the argument is not used.
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
Keeps track of open connections for keep-alive.
If possible, you should share a single Manager
between multiple threads and requests.
Since 0.1.0
Instances
HasHttpManager Manager | |
Defined in Network.HTTP.Client.Types getHttpManager :: Manager -> Manager # |
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_ :: String -> Request #
Same as parseRequest
, but parse errors cause an impure exception.
Mostly useful for static strings which are known to be correctly
formatted.
withResponse :: Request -> Manager -> (Response BodyReader -> IO a) -> IO a #
Perform a Request
using a connection acquired from the given Manager
,
and then provide the Response
to the given function. This function is
fully exception safe, guaranteeing that the response will be closed when the
inner function exits. It is defined as:
withResponse req man f = bracket (responseOpen req man) responseClose f
It is recommended that you use this function in place of explicit calls to
responseOpen
and responseClose
.
You will need to use functions such as brRead
to consume the response
body.
Since 0.1.0
type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived #
The WAI application.
Note that, since WAI 3.0, this type is structured in continuation passing
style to allow for proper safe resource handling. This was handled in the
past via other means (e.g., ResourceT
). As a demonstration:
app :: Application app req respond = bracket_ (putStrLn "Allocating scarce resource") (putStrLn "Cleaning up") (respond $ responseLBS status200 [] "Hello World")
Information on the request sent by the client. This abstracts away the details of the underlying implementation.
data RequestBodyLength #
The size of the request body. In the case of chunked bodies, the size will not be known.
Since 1.4.0
Instances
Show RequestBodyLength | |
Defined in Network.Wai.Internal showsPrec :: Int -> RequestBodyLength -> ShowS # show :: RequestBodyLength -> String # showList :: [RequestBodyLength] -> ShowS # |
lazyRequestBody :: Request -> IO ByteString #
Get the request body as a lazy ByteString. This uses lazy I/O under the surface, and therefore all typical warnings regarding lazy I/O apply.
Since 1.4.1
queryString :: Request -> Query #
Parsed query string information.
rawPathInfo :: Request -> ByteString #
Extra path information sent by the client. The meaning varies slightly depending on backend; in a standalone server setting, this is most likely all information after the domain name. In a CGI application, this would be the information following the path to the CGI executable itself.
Middlewares and routing tools should not modify this raw value, as it may
be used for such things as creating redirect destinations by applications.
Instead, if you are writing a middleware or routing framework, modify the
pathInfo
instead. This is the approach taken by systems like Yesod
subsites.
Note: At the time of writing this documentation, there is at least one
system (Network.Wai.UrlMap
from wai-extra
) that does not follow the
above recommendation. Therefore, it is recommended that you test the
behavior of your application when using rawPathInfo
and any form of
library that might modify the Request
.
requestBodyLength :: Request -> RequestBodyLength #
The size of the request body. In the case of a chunked request body, this may be unknown.
Since 1.4.0
requestHeaders :: Request -> RequestHeaders #
A list of headers (a pair of key and value) in an HTTP request.
requestMethod :: Request -> Method #
Request method such as GET.
responseLBS :: Status -> ResponseHeaders -> ByteString -> Response #
Creating Response
from ByteString
. This is a wrapper for
responseBuilder
.
(<|>) :: ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a infixr 1 #
This combinator implements choice. The parser p <|> q
first
applies p
. If it succeeds, the value of p
is returned. If p
fails without consuming any input, parser q
is tried. This
combinator is defined equal to the mplus
member of the MonadPlus
class and the (<|>
) member of Alternative
.
The parser is called predictive since q
is only tried when
parser p
didn't consume any input (i.e.. the look ahead is 1).
This non-backtracking behaviour allows for both an efficient
implementation of the parser combinators and the generation of good
error messages.
(<?>) :: ParsecT s u m a -> String -> ParsecT s u m a infix 0 #
The parser p <?> msg
behaves as parser p
, but whenever the
parser p
fails without consuming any input, it replaces expect
error messages with the expect error message msg
.
This is normally used at the end of a set alternatives where we want
to return an error message in terms of a higher level construct
rather than returning all possible characters. For example, if the
expr
parser from the try
example would fail, the error
message is: '...: expecting expression'. Without the (<?>)
combinator, the message would be like '...: expecting "let" or
letter', which is less friendly.
dateFormat :: Text -> UTCTime -> Text Source #
Formats a date into a Text string using specified formatting string
Arguments:
format :: Text
: Format stringdate :: UTCTime
: Date to format
Return value: String containing a date in a specified format
dateFormatISO8601 :: UTCTime -> Text Source #
Formats a date into a Text string using ISO8601 formatting string
Format: %Y-%m-%d %H:%M:%S
Output example: 2018-11-25 00:00:01
Arguments:
date :: UTCTime
: Date to format
Return value: String containing a date in ISO8601 format
dateParseISO8601 :: Text -> Either DateParseISO8601Error UTCTime Source #
Parses Text string using ISO8601 format
Expected input example: 2018-11-25 00:00:01
Arguments:
text :: Text
: Text string containing a date in ISO8601 format
Return value: Parsed date or error message
errorShow :: Typeable e => e -> Text -> String Source #
Formats error message to be used with Show
Arguments:
exc :: Typeable
: Error record or exceptionmsg :: Text
: Error message
Return value: String containing the type name of error and a message
ffiWithPtr :: Storable a => a -> (Ptr a -> IO b) -> IO b Source #
Passes specified Storable
value as a pointer (to that value) to the specified IO action
Arguments:
val :: Storable a
: Input valuefun :: Ptr a -> IO b
: IO action to run
Return value: Value returned from IO action
ffiWithPtrPtr :: (Ptr (Ptr a) -> IO b) -> IO b Source #
Passes a pointer to a NULL pointer of a Storable
type to the specified IO action
Arguments:
fun :: Ptr (Ptr a) -> IO b
: IO action to run
Return value: Value returned from IO action
ffiWithUTF8 :: Text -> (CString -> IO a) -> IO a Source #
Passes specified Text
string as a NUL-terminated UTF-8 string to the specified IO action
Arguments:
text :: Text
: Input stringfun :: CString -> IO a
: IO action to run
Return value: Value returned from IO action
ffiWithUTF16 :: Text -> (Ptr Word16 -> IO a) -> IO a Source #
Passes specified Text
string as a NUL-terminated UTF-16 string to the specified IO action
Arguments:
text :: Text
: Input stringfun :: Ptr Word16 -> IO a
: IO action to run
Return value: Value returned from IO action
fsCopyDirectory :: Text -> Text -> IO () Source #
Copies a directory recursively
Throws an exception if source directory does not exist or if destination path already exists
Arguments:
src :: Text
: Source directorydest :: Text
: Destination path
httpContentTypeJSON :: Header Source #
Content-Type
header for application/json
type
httpRequestBodyJSON :: forall a. FromJSON a => Request -> IO a Source #
Reads a body of the specified HTTP request and parses it as a JSON value
Data type should be specified with a type annotation:
Example:
dt <- httpRequestBodyJSON req :: IO Foo
Data must be an instance of FromJSON
Throws an exception if request body doesn't contain valid JSON.
Arguments:
req :: Request
: HTTP request
Return value: Request body parsed as a JSON value
httpRequestBodyText :: Request -> IO Text Source #
Reads a body of the specified HTTP request as a Text
string
Arguments:
req :: Request
: HTTP request
Return value: Request body as a Text
string
httpRequestPath :: Request -> Text Source #
URL path string of the specified HTTP request
Arguments:
req :: Request
: HTTP request
Return value: URL path string
httpRequestHeaders :: Request -> Vector (Text, Text) Source #
Headers of the specified HTTP request as a Vector
of (name, value)
pairs
Arguments:
req :: Request
: HTTP request
Return value: Request headers as a Vector
of (name, value)
pairs
httpRequestHeadersMap :: Request -> HashMap Text Text Source #
Headers of the specified HTTP request as a name -> value
map
Arguments:
req :: Request
: HTTP request
Return value: Request headers as a name -> value
map
httpResponseBody :: Text -> Response BodyReader -> Int -> IO ByteString Source #
Read a body of HTTP response as a lazy ByteString
Throws an exception if specified threshold is exceeded.
Arguments:
label :: Text
: Label used for error reporting on overly-large responsesresp :: Response BodyReader
: HTTP responsethreshold :: Int
Max response body length in bytes
Return value: Response body as a lazy ByteString
httpResponseBodyJSON :: forall a. FromJSON a => Text -> Response BodyReader -> Int -> IO a Source #
Read a body of HTTP response as a JSON value
Data type should be specified with a type annotation:
Example:
dt <- httpResponseBodyJSON label resp 1024 :: IO Foo
Data must be an instance of FromJSON
Throws an exception if response body doesn't contain valid JSON.
Arguments:
label :: Text
: Label used for error reporting on overly-large responsesresp :: Response BodyReader
: HTTP responsethreshold :: Int
Max response body length in bytes
Return value: Response body as a JSON value
httpResponseBodyText :: Text -> Response BodyReader -> Int -> IO Text Source #
Read a body of HTTP response as a Text
string
Arguments:
label :: Text
: Label used for error reporting on overly-large responsesresp :: Response BodyReader
: HTTP responsethreshold :: Int
Max response body length in bytes
Return value: Response body as a Text
string
httpResponseHeaders :: Response a -> Vector (Text, Text) Source #
Headers of the specified HTTP response as a Vector
of (name, value)
pairs
Arguments:
req :: Response
: HTTP request
Return value: Response headers as a Vector
of (name, value)
pairs
httpResponseHeadersMap :: Response a -> HashMap Text Text Source #
Headers of the specified HTTP response as a name -> value
map
Arguments:
req :: Response
: HTTP request
Return value: Response headers as a name -> value
map
ioWithFileBytes :: Text -> (ByteString -> IO a) -> IO a Source #
Reads contents of a specified file as a lazy ByteString
(with streaming)
and provides it to the specified callback
Throws IOWithFileBytesException
if specified file cannot be read
Arguments:
path :: Text
: path to filefun :: (Data.ByteString.Lazy.ByteString -> IO a)
: callback to process the file data
Return value: Result of the callback invocation
ioWithFileText :: Text -> (Text -> IO a) -> IO a Source #
Reads contents of a specified file as a lazy Text
(with streaming)
and provides it to the specified callback
File contents are decoded as UTF-8
Throws IOWithFileBytesException
if specified file cannot be read
Arguments:
path :: Text
: path to filefun :: (Data.Text.Lazy.Text -> IO a)
: callback to process the file data
Return value: Result of the callback invocation
jsonDecodeFile :: forall a. FromJSON a => Text -> IO a Source #
Parses contents of a specified JSON file into a typed data
Data type should be specified with a type annotation:
Example:
dt <- jsonDecodeFile "path/to/foo.json" :: IO Foo
Data must be an instance of FromJSON
File contents are decoded as UTF-8
Throws an exception if file cannot be read or data cannot be decoded
Arguments:
path :: Text
: Path to JSON file
Return value: Decoded data
jsonDecodeText :: forall a. FromJSON a => Text -> Either JSONDecodeError a Source #
Parses a JSON Text
string into a typed data
Data type should be specified with a type annotation:
Example:
let Right (dt :: Foo) = jsonDecodeText text
Data must be an instance of FromJSON
Returns an error if data cannot be decoded
Arguments:
text :: Text
: JSONText
string to parse
Return value: Decoded data or decoding error
jsonEncodeText :: ToJSON a => a -> Text Source #
Encodes a data into a JSON Text
string
Data must be an instance of ToJSON
Arguments:
data :: ToJSON
: some data that supports JSON serialization with Aeson
Return value: JSON Text
string
jsonGet :: forall a. FromJSON a => Value -> Text -> Either JSONGetError a Source #
Extract the field value from the specified JSON object
Returns an error, if specified JSON Value
is not a JSON object,
if it does't contain a specified field, if field type is different
from the one specified in type annotation
Data type should be specified with a type annotation:
let obj = object [ "foo" .= (42 :: Int) , "bar" .= ("baz" :: Text) ] let Right (fooval :: Int) = jsonGet obj "foo" let Right (barval :: Text) = jsonGet obj "bar"
Arguments:
val :: Aeson.Value
: JSON value, must be a JSON objectfield :: Text
: Field name
Return value: Field value or an error
jsonUnwrapUnaryOptions :: Options Source #
JSON options with unwrapUnaryRecords
flag flipped to True
mapFromVector :: (Eq k, Hashable k) => Vector v -> (Int -> v -> k) -> HashMap k v Source #
Creates a HashMap
from a Vector
Creates a HashMap
and fills it using the Vector
elements as
values and elements with key function as keys.
If key function returns duplicate keys for some elements, previous entry is replaced with a new one.
Arguments:
vec :: Vector v
: InputVector
keyfun :: (Int -> v -> k)
: Key function that takes an element index and element and returns the map key
Return value: HashMap
filled with elements from input Vector
parsecLineContains :: Text -> Parser Text Source #
Finds a line containing a specified substring
Uses LF
as a line separator
Resulting line doesn't contain a line separator
Arguments:
needle :: Text
: Substring to find
Return value: Line that contains a specified substring
parsecLinePrefix :: Text -> Parser Text Source #
Finds a line with a specified prefix
Uses LF
as a line separator
Whitespace is stripped from the start of each line before checking for prefix
Resulting line doesn't contain a line separator
Arguments:
prefix :: Text
: Prefix to find
Return value: Line with the specified prefix
parsecLineNoPrefix :: Text -> Parser Text Source #
Finds a line that does not have a specified prefix
Uses LF
as a line separator
Whitespace is stripped from the start of each line before checking for prefix
Resulting line doesn't contain a line separator
Arguments:
prefix :: Text
: Prefix that should be skipped
Return value: First line that does not have a specified prefix
parsecSkipLines :: Int -> Parser () Source #
Skips a specified number of lines
Uses LF
as a line separator
Does not consume additional whitespace after the last line skipped (or between the lines)
Arguments:
count :: Int
: Number of lines to skip
parsecSkipManyTill :: Text -> Parser () Source #
Skips all input until the specified substring is found
Warning: all look-ahead data is kept in memory
Arguments:
needle :: Text
: Substring to find
Return value: First line that does not have a specified prefix
parsecTry :: Parser a -> Parser a Source #
The parser parsecTry p
behaves like parser p, except that it pretends
that it hasn't consumed any input when an error occurs
This is a re-export of Text.Parsec.try under a different name to not conflict with Control.Exception.try
Arguments:
parser :: Parser a
: Parser to wrap intotry
Return value: Resulting value from the specified parser
parsecWhitespace :: Parser () Source #
Skips one or more whitespace characters
Note: Lexemes from Text.Parsec.Token.TokenParser can be used instead
parsecParseFile :: Parser a -> Text -> IO a Source #
Lazily reads contents from a specified file and parses it using the specified parser
File contents are decoded as UTF-8
Throws an exception on file IO error or parsing error
Arguments:
parser :: Parser a
: Parser to use for the contents of the filepath :: ParseError
: Path to a file to parse
Return value: Resulting value from the specified parser
parsecParseText :: Parser a -> Text -> Either ParsecParseTextError a Source #
Parser a specified strict Text
string using a specified parser
Note: parser is typed on a lazy Text
input (so it can also be used with parsecParseFile
)
Returns an error on parsing error
Arguments:
parser :: Parser a
: Parser to use for the contents of the filetext :: Text
:Text
string to parse
Return value: Resulting value from the specified parser or parsing error
pathIsAbsolute :: Text -> Bool Source #
Checks whether specified path is absolute
Only checks the path string itself, doesn't use FS API.
Arguments:
path :: Text
: FS path to check
Return value: True
if path is absolute, False
otherwise
pathConcat :: Text -> Text -> Text Source #
Concatenates two paths
Specified postfix must be non-absolute
Arguments:
prefix :: Text
: Path prefix, may be absolutepostfix :: Text
: Path postfix, must not be absolute
Return value: Concatenated path
pathPrepend :: Text -> Text -> Text Source #
Prepends an absolute prefix to the relative path
Does nothing, if path is already absolute
Arguments:
prefix :: Text
: Path prefix, must be absolutepostfix :: Text
: Path postfix, may be absolute
Return value: Path with a specified prefix prepended, if path is relative, specified path unchanged otherwise
processSpawnAndWait :: Text -> Vector Text -> Text -> IO Int Source #
Spawns a new process and waits for it to exit
Arguments:
executable :: Text
: Path to executable binaryargs :: Vector Text
: Arguments to pass to executableout :: Text
Path to a file, where std output (bothstdout
andstderr
) will be written
Return value: Process exit code
textDecodeUtf8 :: ByteString -> Text Source #
Decodes ByteString
into Text
using UTF-8
encoding
Invalid byte sequences are replaced with U+FFFD
Arguments:
bytes :: ByteString
: Byte string
Return value: Text
string
textFormat :: Text -> Vector Text -> Text Source #
Formats specified template with specified parameters Vector
Template must use {}
string for placeholders.
If length of parameters Vector
is less than a number of holes in template, then
remaining parameters are filled with empty strings. If parameters vector is too long,
excessive parameters are ignored.
Template preparation is relatively expensive, consider using textFormatParts
for
frequently used templates.
Arguments:
template :: Text
: string partsparams :: Vector Text
parameters to intersperse into the parts
Return value: Vector Text
vector containing the parts of the input string
textFormatParts :: Vector Text -> Vector Text -> Text Source #
Concatenates specified Vector
of string parts interspersing it with specified parameters
If length of parameters Vector
is less than a number of parts - 1, then
remaining parameters are filled with empty strings. If parameters vector is too long,
excessive parameters are ignored.
Arguments:
parts :: Vector Text
: string partsparams :: Vector Text
parameters to intersperse into the parts
Return value: Vector Text
vector containing the parts of the input string