| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
CfnFlip.Prelude
Synopsis
- module Control.Monad.IO.Class
- module Prelude
- data ByteString
- data Text
- unless :: Applicative f => Bool -> f () -> f ()
- fromMaybe :: a -> Maybe a -> a
- when :: Applicative f => Bool -> f () -> f ()
- data Word8
- class (Typeable e, Show e) => Exception e
- throwIO :: (MonadIO m, Exception e) => e -> m a
- traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
- for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- pack :: String -> Text
- unpack :: Text -> String
- class MonadIO m => MonadUnliftIO (m :: Type -> Type)
- encodeUtf8 :: Text -> ByteString
- throwString :: (MonadIO m, HasCallStack) => String -> m a
- readFileBinary :: MonadIO m => FilePath -> m ByteString
- writeFileBinary :: MonadIO m => FilePath -> ByteString -> m ()
Documentation
module Control.Monad.IO.Class
module Prelude
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
A space efficient, packed, unboxed Unicode text type.
Instances
| FromJSON Text | |||||
Defined in Data.Aeson.Types.FromJSON | |||||
| FromJSONKey Text | |||||
Defined in Data.Aeson.Types.FromJSON | |||||
| ToJSON Text | |||||
| ToJSONKey Text | |||||
Defined in Data.Aeson.Types.ToJSON | |||||
| Chunk Text | |||||
Defined in Data.Attoparsec.Internal.Types Associated Types
| |||||
| GrowingAppend Text | |||||
Defined in Data.MonoTraversable | |||||
| MonoFoldable Text | |||||
Defined in Data.MonoTraversable Methods ofoldMap :: Monoid m => (Element Text -> m) -> Text -> m # ofoldr :: (Element Text -> b -> b) -> b -> Text -> b # ofoldl' :: (a -> Element Text -> a) -> a -> Text -> a # otoList :: Text -> [Element Text] # oall :: (Element Text -> Bool) -> Text -> Bool # oany :: (Element Text -> Bool) -> Text -> Bool # ocompareLength :: Integral i => Text -> i -> Ordering # otraverse_ :: Applicative f => (Element Text -> f b) -> Text -> f () # ofor_ :: Applicative f => Text -> (Element Text -> f b) -> f () # omapM_ :: Applicative m => (Element Text -> m ()) -> Text -> m () # oforM_ :: Applicative m => Text -> (Element Text -> m ()) -> m () # ofoldlM :: Monad m => (a -> Element Text -> m a) -> a -> Text -> m a # ofoldMap1Ex :: Semigroup m => (Element Text -> m) -> Text -> m # ofoldr1Ex :: (Element Text -> Element Text -> Element Text) -> Text -> Element Text # ofoldl1Ex' :: (Element Text -> Element Text -> Element Text) -> Text -> Element Text # headEx :: Text -> Element Text # lastEx :: Text -> Element Text # unsafeHead :: Text -> Element Text # unsafeLast :: Text -> Element Text # maximumByEx :: (Element Text -> Element Text -> Ordering) -> Text -> Element Text # minimumByEx :: (Element Text -> Element Text -> Ordering) -> Text -> Element Text # | |||||
| MonoFunctor Text | |||||
| MonoPointed Text | |||||
| MonoTraversable Text | |||||
| IsSequence Text | |||||
Defined in Data.Sequences Methods fromList :: [Element Text] -> Text # lengthIndex :: Text -> Index Text # break :: (Element Text -> Bool) -> Text -> (Text, Text) # span :: (Element Text -> Bool) -> Text -> (Text, Text) # dropWhile :: (Element Text -> Bool) -> Text -> Text # takeWhile :: (Element Text -> Bool) -> Text -> Text # splitAt :: Index Text -> Text -> (Text, Text) # unsafeSplitAt :: Index Text -> Text -> (Text, Text) # take :: Index Text -> Text -> Text # unsafeTake :: Index Text -> Text -> Text # drop :: Index Text -> Text -> Text # unsafeDrop :: Index Text -> Text -> Text # dropEnd :: Index Text -> Text -> Text # partition :: (Element Text -> Bool) -> Text -> (Text, Text) # uncons :: Text -> Maybe (Element Text, Text) # unsnoc :: Text -> Maybe (Text, Element Text) # filter :: (Element Text -> Bool) -> Text -> Text # filterM :: Monad m => (Element Text -> m Bool) -> Text -> m Text # replicate :: Index Text -> Element Text -> Text # replicateM :: Monad m => Index Text -> m (Element Text) -> m Text # groupBy :: (Element Text -> Element Text -> Bool) -> Text -> [Text] # groupAllOn :: Eq b => (Element Text -> b) -> Text -> [Text] # subsequences :: Text -> [Text] # permutations :: Text -> [Text] # tailMay :: Text -> Maybe Text # initMay :: Text -> Maybe Text # unsafeTail :: Text -> Text # unsafeInit :: Text -> Text # index :: Text -> Index Text -> Maybe (Element Text) # indexEx :: Text -> Index Text -> Element Text # unsafeIndex :: Text -> Index Text -> Element Text # | |||||
| SemiSequence Text | |||||
Defined in Data.Sequences | |||||
| Textual Text | |||||
| ToYaml Text | |||||
Defined in Data.Yaml.Builder Methods toYaml :: Text -> YamlBuilder # | |||||
| FromYaml Text | |||||
Defined in Data.Yaml.Parser Methods fromYaml :: YamlValue -> YamlParser Text # | |||||
| LazySequence Text Text | |||||
| Utf8 Text ByteString | |||||
Defined in Data.Sequences | |||||
| type ChunkElem Text | |||||
Defined in Data.Attoparsec.Internal.Types | |||||
| type State Text | |||||
Defined in Data.Attoparsec.Internal.Types | |||||
| type Item Text | |||||
| type Element Text | |||||
Defined in Data.MonoTraversable | |||||
| type Index Text | |||||
Defined in Data.Sequences | |||||
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when.
fromMaybe :: a -> Maybe a -> a #
The fromMaybe function takes a default value and a Maybe
value. If the Maybe is Nothing, it returns the default value;
otherwise, it returns the value contained in the Maybe.
Examples
Basic usage:
>>>fromMaybe "" (Just "Hello, World!")"Hello, World!"
>>>fromMaybe "" Nothing""
Read an integer from a string using readMaybe. If we fail to
parse an integer, we want to return 0 by default:
>>>import Text.Read ( readMaybe )>>>fromMaybe 0 (readMaybe "5")5>>>fromMaybe 0 (readMaybe "")0
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.
8-bit unsigned integer type
Instances
| FromJSON Word8 | |
Defined in Data.Aeson.Types.FromJSON | |
| FromJSONKey Word8 | |
Defined in Data.Aeson.Types.FromJSON | |
| ToJSON Word8 | |
| ToJSONKey Word8 | |
Defined in Data.Aeson.Types.ToJSON | |
| Data Word8 | Since: base-4.0.0.0 |
Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Word8 -> c Word8 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Word8 # dataTypeOf :: Word8 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Word8) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Word8) # gmapT :: (forall b. Data b => b -> b) -> Word8 -> Word8 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Word8 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Word8 -> r # gmapQ :: (forall d. Data d => d -> u) -> Word8 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Word8 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Word8 -> m Word8 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Word8 -> m Word8 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Word8 -> m Word8 # | |
| Storable Word8 | Since: base-2.1 |
| Bits Word8 | Since: base-2.1 |
Defined in GHC.Word Methods (.&.) :: Word8 -> Word8 -> Word8 # (.|.) :: Word8 -> Word8 -> Word8 # xor :: Word8 -> Word8 -> Word8 # complement :: Word8 -> Word8 # shift :: Word8 -> Int -> Word8 # rotate :: Word8 -> Int -> Word8 # setBit :: Word8 -> Int -> Word8 # clearBit :: Word8 -> Int -> Word8 # complementBit :: Word8 -> Int -> Word8 # testBit :: Word8 -> Int -> Bool # bitSizeMaybe :: Word8 -> Maybe Int # shiftL :: Word8 -> Int -> Word8 # unsafeShiftL :: Word8 -> Int -> Word8 # shiftR :: Word8 -> Int -> Word8 # unsafeShiftR :: Word8 -> Int -> Word8 # rotateL :: Word8 -> Int -> Word8 # | |
| FiniteBits Word8 | Since: base-4.6.0.0 |
Defined in GHC.Word Methods finiteBitSize :: Word8 -> Int # countLeadingZeros :: Word8 -> Int # countTrailingZeros :: Word8 -> Int # | |
| Bounded Word8 | Since: base-2.1 |
| Enum Word8 | Since: base-2.1 |
| Ix Word8 | Since: base-2.1 |
| Num Word8 | Since: base-2.1 |
| Read Word8 | Since: base-2.1 |
| Integral Word8 | Since: base-2.1 |
| Real Word8 | Since: base-2.1 |
Defined in GHC.Word Methods toRational :: Word8 -> Rational # | |
| Show Word8 | Since: base-2.1 |
| PrintfArg Word8 | Since: base-2.1 |
Defined in Text.Printf | |
| Eq Word8 | Since: base-2.1 |
| Ord Word8 | Since: base-2.1 |
| Uniform Word8 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Word8 # | |
| UniformRange Word8 | |
| ByteSource Word8 | |
Defined in Data.UUID.Types.Internal.Builder | |
| type ByteSink Word8 g | |
Defined in Data.UUID.Types.Internal.Builder type ByteSink Word8 g = Takes1Byte g | |
class (Typeable e, Show e) => Exception e #
Any type that you wish to throw or catch as an exception must be an
instance of the Exception class. The simplest case is a new exception
type directly below the root:
data MyException = ThisException | ThatException
deriving Show
instance Exception MyExceptionThe default method definitions in the Exception class do what we need
in this case. You can now throw and catch ThisException and
ThatException as exceptions:
*Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
Caught ThisException
In more complicated examples, you may wish to define a whole hierarchy of exceptions:
---------------------------------------------------------------------
-- Make the root exception type for all the exceptions in a compiler
data SomeCompilerException = forall e . Exception e => SomeCompilerException e
instance Show SomeCompilerException where
show (SomeCompilerException e) = show e
instance Exception SomeCompilerException
compilerExceptionToException :: Exception e => e -> SomeException
compilerExceptionToException = toException . SomeCompilerException
compilerExceptionFromException :: Exception e => SomeException -> Maybe e
compilerExceptionFromException x = do
SomeCompilerException a <- fromException x
cast a
---------------------------------------------------------------------
-- Make a subhierarchy for exceptions in the frontend of the compiler
data SomeFrontendException = forall e . Exception e => SomeFrontendException e
instance Show SomeFrontendException where
show (SomeFrontendException e) = show e
instance Exception SomeFrontendException where
toException = compilerExceptionToException
fromException = compilerExceptionFromException
frontendExceptionToException :: Exception e => e -> SomeException
frontendExceptionToException = toException . SomeFrontendException
frontendExceptionFromException :: Exception e => SomeException -> Maybe e
frontendExceptionFromException x = do
SomeFrontendException a <- fromException x
cast a
---------------------------------------------------------------------
-- Make an exception type for a particular frontend compiler exception
data MismatchedParentheses = MismatchedParentheses
deriving Show
instance Exception MismatchedParentheses where
toException = frontendExceptionToException
fromException = frontendExceptionFromExceptionWe can now catch a MismatchedParentheses exception as
MismatchedParentheses, SomeFrontendException or
SomeCompilerException, but not other types, e.g. IOException:
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException))
*** Exception: MismatchedParentheses
Instances
| Exception AesonException | |
Defined in Data.Aeson.Types.Internal Methods toException :: AesonException -> SomeException # | |
| Exception NestedAtomically | Since: base-4.0 |
Defined in Control.Exception.Base Methods toException :: NestedAtomically -> SomeException # | |
| Exception NoMatchingContinuationPrompt | Since: base-4.18 |
Defined in Control.Exception.Base | |
| Exception NoMethodError | Since: base-4.0 |
Defined in Control.Exception.Base Methods toException :: NoMethodError -> SomeException # fromException :: SomeException -> Maybe NoMethodError # displayException :: NoMethodError -> String # | |
| Exception NonTermination | Since: base-4.0 |
Defined in Control.Exception.Base Methods toException :: NonTermination -> SomeException # | |
| Exception PatternMatchFail | Since: base-4.0 |
Defined in Control.Exception.Base Methods toException :: PatternMatchFail -> SomeException # | |
| Exception RecConError | Since: base-4.0 |
Defined in Control.Exception.Base Methods toException :: RecConError -> SomeException # fromException :: SomeException -> Maybe RecConError # displayException :: RecConError -> String # | |
| Exception RecSelError | Since: base-4.0 |
Defined in Control.Exception.Base Methods toException :: RecSelError -> SomeException # fromException :: SomeException -> Maybe RecSelError # displayException :: RecSelError -> String # | |
| Exception RecUpdError | Since: base-4.0 |
Defined in Control.Exception.Base Methods toException :: RecUpdError -> SomeException # fromException :: SomeException -> Maybe RecUpdError # displayException :: RecUpdError -> String # | |
| Exception TypeError | Since: base-4.9.0.0 |
Defined in Control.Exception.Base Methods toException :: TypeError -> SomeException # fromException :: SomeException -> Maybe TypeError # displayException :: TypeError -> String # | |
| Exception Dynamic | Since: base-4.0.0.0 |
Defined in Data.Dynamic Methods toException :: Dynamic -> SomeException # fromException :: SomeException -> Maybe Dynamic # displayException :: Dynamic -> String # | |
| Exception Void | Since: base-4.8.0.0 |
Defined in GHC.Exception.Type Methods toException :: Void -> SomeException # fromException :: SomeException -> Maybe Void # displayException :: Void -> String # | |
| Exception ErrorCall | Since: base-4.0.0.0 |
Defined in GHC.Exception Methods toException :: ErrorCall -> SomeException # fromException :: SomeException -> Maybe ErrorCall # displayException :: ErrorCall -> String # | |
| Exception ArithException | Since: base-4.0.0.0 |
Defined in GHC.Exception.Type Methods toException :: ArithException -> SomeException # | |
| Exception SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type Methods toException :: SomeException -> SomeException # fromException :: SomeException -> Maybe SomeException # displayException :: SomeException -> String # | |
| Exception AllocationLimitExceeded | Since: base-4.8.0.0 |
Defined in GHC.IO.Exception | |
| Exception ArrayException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods toException :: ArrayException -> SomeException # | |
| Exception AssertionFailed | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods toException :: AssertionFailed -> SomeException # | |
| Exception AsyncException | Since: base-4.7.0.0 |
Defined in GHC.IO.Exception Methods toException :: AsyncException -> SomeException # | |
| Exception BlockedIndefinitelyOnMVar | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
| Exception BlockedIndefinitelyOnSTM | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
| Exception CompactionFailed | Since: base-4.10.0.0 |
Defined in GHC.IO.Exception Methods toException :: CompactionFailed -> SomeException # | |
| Exception Deadlock | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods toException :: Deadlock -> SomeException # fromException :: SomeException -> Maybe Deadlock # displayException :: Deadlock -> String # | |
| Exception ExitCode | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods toException :: ExitCode -> SomeException # fromException :: SomeException -> Maybe ExitCode # displayException :: ExitCode -> String # | |
| Exception FixIOException | Since: base-4.11.0.0 |
Defined in GHC.IO.Exception Methods toException :: FixIOException -> SomeException # | |
| Exception IOException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods toException :: IOException -> SomeException # fromException :: SomeException -> Maybe IOException # displayException :: IOException -> String # | |
| Exception SomeAsyncException | Since: base-4.7.0.0 |
Defined in GHC.IO.Exception Methods toException :: SomeAsyncException -> SomeException # fromException :: SomeException -> Maybe SomeAsyncException # | |
| Exception IOPortException | |
Defined in GHC.IOPort Methods toException :: IOPortException -> SomeException # fromException :: SomeException -> Maybe IOPortException # displayException :: IOPortException -> String # | |
| Exception Timeout | Since: base-4.7.0.0 |
Defined in System.Timeout Methods toException :: Timeout -> SomeException # fromException :: SomeException -> Maybe Timeout # displayException :: Timeout -> String # | |
| Exception SizeOverflowException | |
Defined in Data.ByteString.Internal.Type | |
| Exception InvalidYamlEvent Source # | |
Defined in CfnFlip.Libyaml Methods toException :: InvalidYamlEvent -> SomeException # | |
| Exception ToEventRawException | |
Defined in Text.Libyaml Methods toException :: ToEventRawException -> SomeException # fromException :: SomeException -> Maybe ToEventRawException # displayException :: ToEventRawException -> String # | |
| Exception YamlException | |
Defined in Text.Libyaml Methods toException :: YamlException -> SomeException # fromException :: SomeException -> Maybe YamlException # displayException :: YamlException -> String # | |
| Exception NullError | |
Defined in Data.NonNull Methods toException :: NullError -> SomeException # fromException :: SomeException -> Maybe NullError # displayException :: NullError -> String # | |
| Exception InvalidAccess | |
Defined in Control.Monad.Trans.Resource.Internal Methods toException :: InvalidAccess -> SomeException # fromException :: SomeException -> Maybe InvalidAccess # displayException :: InvalidAccess -> String # | |
| Exception ResourceCleanupException | |
| Exception UnicodeException | |
Defined in Data.Text.Encoding.Error Methods toException :: UnicodeException -> SomeException # | |
| Exception StringException | Since: unliftio-0.1.0.0 |
Defined in UnliftIO.Exception Methods toException :: StringException -> SomeException # | |
| Exception ConcException | |
Defined in UnliftIO.Internals.Async Methods toException :: ConcException -> SomeException # fromException :: SomeException -> Maybe ConcException # displayException :: ConcException -> String # | |
| Exception ParseException | |
Defined in Data.Yaml.Internal Methods toException :: ParseException -> SomeException # | |
| Exception YamlParseException | |
Defined in Data.Yaml.Parser Methods toException :: YamlParseException -> SomeException # fromException :: SomeException -> Maybe YamlParseException # | |
throwIO :: (MonadIO m, Exception e) => e -> m a #
Synchronously throw the given exception.
Note that, if you provide an exception value which is of an asynchronous
type, it will be wrapped up in SyncExceptionWrapper. See toSyncException.
Since: unliftio-0.1.0.0
traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f () #
Map each element of a structure to an Applicative action, evaluate these
actions from left to right, and ignore the results. For a version that
doesn't ignore the results see traverse.
traverse_ is just like mapM_, but generalised to Applicative actions.
Examples
Basic usage:
>>>traverse_ print ["Hello", "world", "!"]"Hello" "world" "!"
for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () #
for_ is traverse_ with its arguments flipped. For a version
that doesn't ignore the results see for. This
is forM_ generalised to Applicative actions.
for_ is just like forM_, but generalised to Applicative actions.
Examples
Basic usage:
>>>for_ [1..4] print1 2 3 4
class MonadIO m => MonadUnliftIO (m :: Type -> Type) #
Monads which allow their actions to be run in IO.
While MonadIO allows an IO action to be lifted into another
monad, this class captures the opposite concept: allowing you to
capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic
state, but may have monadic context. This essentially limits
MonadUnliftIO to ReaderT and IdentityT transformers on top of
IO.
Laws. For any function run provided by withRunInIO, it must meet the
monad transformer laws as reformulated for MonadUnliftIO:
run . return = return
run (m >>= f) = run m >>= run . f
Instances of MonadUnliftIO must also satisfy the following laws:
- Identity law
withRunInIO (\run -> run m) = m- Inverse law
withRunInIO (\_ -> m) = liftIO m
As an example of an invalid instance, a naive implementation of
MonadUnliftIO (StateT s m) might be
withRunInIO inner =
StateT $ \s ->
withRunInIO $ \run ->
inner (run . flip evalStateT s)
This breaks the identity law because the inner run m would throw away
any state changes in m.
Since: unliftio-core-0.1.0.0
Minimal complete definition
Instances
| MonadUnliftIO IO | |
Defined in Control.Monad.IO.Unlift | |
| MonadUnliftIO m => MonadUnliftIO (ResourceT m) | Since: resourcet-1.1.10 |
Defined in Control.Monad.Trans.Resource.Internal | |
| MonadUnliftIO m => MonadUnliftIO (IdentityT m) | |
Defined in Control.Monad.IO.Unlift | |
| MonadUnliftIO m => MonadUnliftIO (ReaderT r m) | |
Defined in Control.Monad.IO.Unlift | |
encodeUtf8 :: Text -> ByteString #
Encode text using UTF-8 encoding.
throwString :: (MonadIO m, HasCallStack) => String -> m a #
A convenience function for throwing a user error. This is useful for cases where it would be too high a burden to define your own exception type.
This throws an exception of type StringException. When GHC
supports it (base 4.9 and GHC 8.0 and onward), it includes a call
stack.
Since: unliftio-0.1.0.0
readFileBinary :: MonadIO m => FilePath -> m ByteString Source #
writeFileBinary :: MonadIO m => FilePath -> ByteString -> m () Source #