Safe Haskell | Safe |
---|---|
Language | Haskell98 |
This module is presents a prelude mostly like the post-Applicative-Monad world of base >= 4.8 / ghc >= 7.10, even on earlier versions. It's intended as an internal library for llvm-hs-pure and llvm-hs; it's exposed only to be shared between the two.
- module Prelude
- module Data.Data
- module GHC.Generics
- module Data.Int
- module Data.Word
- module Data.Functor
- module Data.Foldable
- module Data.Traversable
- module Control.Applicative
- module Control.Monad
- data ByteString :: *
- data ShortByteString :: *
- fromMaybe :: a -> Maybe a -> a
Documentation
module Prelude
module Data.Data
module GHC.Generics
module Data.Int
module Data.Word
module Data.Functor
module Data.Foldable
module Data.Traversable
module Control.Applicative
module Control.Monad
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.
Eq ByteString | |
Data ByteString | |
Ord ByteString | |
Read ByteString | |
Show ByteString | |
IsString ByteString | |
Semigroup ByteString | |
Monoid ByteString | |
NFData ByteString | |
Chunk ByteString | |
type State ByteString | |
type ChunkElem ByteString | |
data ShortByteString :: * #
A compact representation of a Word8
vector.
It has a lower memory overhead than a ByteString
and and does not
contribute to heap fragmentation. It can be converted to or from a
ByteString
(at the cost of copying the string data). It supports very few
other operations.
It is suitable for use as an internal representation for code that needs
to keep many short strings in memory, but it should not be used as an
interchange type. That is, it should not generally be used in public APIs.
The ByteString
type is usually more suitable for use in interfaces; it is
more flexible and it supports a wide range of operations.
fromMaybe :: a -> Maybe a -> a #
The fromMaybe
function takes a default value and and Maybe
value. If the Maybe
is Nothing
, it returns the default values;
otherwise, it returns the value contained in the Maybe
.
Examples
Basic usage:
>>>
fromMaybe "" (Just "Hello, World!")
"Hello, World!"
>>>
fromMaybe "" Nothing
""
Read an integer from a string using readMaybe
. If we fail to
parse an integer, we want to return 0
by default:
>>>
import Text.Read ( readMaybe )
>>>
fromMaybe 0 (readMaybe "5")
5>>>
fromMaybe 0 (readMaybe "")
0