diff --git a/docs/Applicative.md b/docs/Applicative.md index 80fc3d8f1..ef14d9b28 100644 --- a/docs/Applicative.md +++ b/docs/Applicative.md @@ -29,10 +29,6 @@ class Functor f => Applicative (f :: * -> *) where (<*) :: f a -> f b -> f a ``` -```haskell -(<$>) :: Functor f => (a -> b) -> f a -> f b -``` - ```haskell orAlt :: (Alternative f, Monoid a) => f a -> f a ``` diff --git a/docs/Debug.md b/docs/Debug.md index 0a1030ff5..37363798c 100644 --- a/docs/Debug.md +++ b/docs/Debug.md @@ -1,38 +1,96 @@ Debug ===== +Stubbing +-------- + +#### undefined + ```haskell undefined :: a ``` +An undefined expression standing in for an incomplete program, unevaluated type +witness, or unreachable code branch. + +*Example*: + +```haskell +> import Foreign.Storable +> print (sizeOf (undefined :: Int)) +8 +``` + +#### notImplemented + ```haskell notImplemented :: a ``` +An undefined expression standing in for a yet to completed program. + +*Example*: + +```haskell +main :: IO () +main = notImplemented +``` + +Tracing +------- + +#### trace + ```haskell trace :: Print b => b -> a -> a ``` +*Example*: + +#### traceM + ```haskell traceM :: (Monad m) => Text -> m () ``` +*Example*: + +#### traceId + ```haskell traceId :: Text -> Text ``` +*Example*: + +#### traceShowM + ```haskell traceShowM :: (P.Show a, Monad m) => a -> m () ``` +*Example*: + +#### traceShowId + ```haskell traceShowId :: P.Show a => a -> a ``` +*Example*: + +#### traceShow + ```haskell traceShow :: P.Show a => a -> b -> b ``` +*Example*: + +#### traceIO + ```haskell traceIO :: Print b => b -> a -> IO a ``` + +*Example*: diff --git a/docs/Exceptions.md b/docs/Exceptions.md index 6a33cef03..4817c97bd 100644 --- a/docs/Exceptions.md +++ b/docs/Exceptions.md @@ -61,7 +61,7 @@ throwSTM :: Exception e => e -> STM a throwError :: MonadError e m => e -> m a ``` -#### Panic +#### Fatal Errors ```haskell data FatalError = FatalError {msg :: Text} diff --git a/docs/Function.md b/docs/Function.md new file mode 100644 index 000000000..c28a7b4e2 --- /dev/null +++ b/docs/Function.md @@ -0,0 +1,98 @@ +Functions +========= + +Composition +----------- + +#### $ + +```haskell +($) :: (a -> b) -> a -> b +``` + +*Example*: + +#### . + +```haskell +(.) :: (b -> c) -> (a -> b) -> a -> c +``` + +*Example*: + +#### & + +```haskell +(&) :: a -> (a -> b) -> b +``` + +*Example*: + +#### flip + +```haskell +flip :: (a -> b -> c) -> b -> a -> c +``` + +*Example*: + +#### on + +```haskell +on :: (b -> b -> c) -> (a -> b) -> a -> a -> c +``` + +*Example*: + +#### const + +```haskell +const :: a -> b -> a +``` + +*Example*: + +#### fix + +```haskell +fix :: (a -> a) -> a +``` + +*Example*: + +#### identity + +```haskell +identity :: a -> a +``` + +The identity function maps any value to itself. + +*Example*: + +Strictness +----------- + +#### $! + +```haskell +($!) :: NFData a => (a -> b) -> a -> b +``` + +*Example*: + +#### $!! + +```haskell +($!!) :: NFData a => (a -> b) -> a -> b +``` + +*Example*: + +#### force + +```haskell +force :: NFData a => a -> a +``` + +*Example*: diff --git a/docs/Function.rst b/docs/Function.rst deleted file mode 100644 index 2f5f1ed70..000000000 --- a/docs/Function.rst +++ /dev/null @@ -1,83 +0,0 @@ -Functions -========= - -.. highlight:: haskell - -$ -*** - -:: - - ($) :: (a -> b) -> a -> b - -& -*** - -:: - - (&) :: a -> (a -> b) -> b - -. -*** - -:: - - (.) :: (b -> c) -> (a -> b) -> a -> c - - -flip -**** - -:: - - flip :: (a -> b -> c) -> b -> a -> c - - -on -*** - -:: - - on :: (b -> b -> c) -> (a -> b) -> a -> a -> c - -const -***** - -:: - - const :: a -> b -> a - -fix -*** - -:: - - fix :: (a -> a) -> a - -identity -******** - -:: - - identity :: a -> a - -$! -*** - -:: - - ($!) :: NFData a => (a -> b) -> a -> b - -$!! -*** - -:: - - ($!!) :: NFData a => (a -> b) -> a -> b - -force -***** - -:: - - force :: NFData a => a -> a diff --git a/docs/Monad.md b/docs/Monad.md index 4b7282f8e..9e0e3e6ee 100644 --- a/docs/Monad.md +++ b/docs/Monad.md @@ -9,7 +9,6 @@ class Applicative m => Monad (m :: * -> *) where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b return :: a -> m a - GHC.Base.fail :: GHC.Base.String -> m a ``` ```haskell diff --git a/docs/Strings.md b/docs/Strings.md index 2d218dd04..57ffd8776 100644 --- a/docs/Strings.md +++ b/docs/Strings.md @@ -1,14 +1,58 @@ Strings ======= +```haskell +import qualified Data.Text as T +import qualified Data.Text.Lazy as L +``` + Text -~~~~ +---- + +The Text type represents Unicode character strings, in a time and space-efficient manner. This package provides text processing capabilities that are optimized for performance critical use, both in terms of large data quantities and high speed. LText -~~~~ +----- Bytestring -~~~~~~~~~~ +---------- LBytestring -~~~~~~~~~~~ +----------- + +Conversion +---------- + +```haskell +class StringConv a b where + strConv :: Leniency -> a -> b + +data Leniency = Lenient | Strict +``` + +```haskell +toS :: StringConv a b => a -> b +``` + +```haskell +toSL :: StringConv a b => a -> b +``` + +*Example*: + +```haskell +a :: LByteString +a = "Einstein" + +b :: Text +b = "Feynmann" + +c :: ByteString +c = "Schrödinger" + +example1 :: ByteString +example1 = toS b + +example2 :: Bool +example2 = (a == toS b) && (toS b == c) +``` diff --git a/docs/Tuple.md b/docs/Tuple.md index 5ce5679d2..f9cbb5b73 100644 --- a/docs/Tuple.md +++ b/docs/Tuple.md @@ -1,84 +1,76 @@ Tuples ====== -.. highlight:: haskell +#### fst -fst -*** - -:: - - fst :: (a, b) -> a +```haskell +fst :: (a, b) -> a +``` Extract the first component of a pair. *Example*: -:: - - > fst (1,2) - 1 +```haskell +> fst (1,2) +``` -snd -*** +#### snd -:: - - snd :: (a, b) -> b +```haskell +snd :: (a, b) -> b +``` Extract the second component of a pair. *Example*: -:: - - > snd (1,2) - 2 +```haskell +> snd (1,2) +2 +``` -swap -**** +#### swap -:: - - swap :: (a, b) -> (b, a) +```haskell +swap :: (a, b) -> (b, a) +``` Swap the components of a pair. *Example*: -:: - - > swap (1,2) - (2,1) +```haskell +> swap (1,2) +(2,1) +``` -curry -***** +#### curry -:: - - curry :: ((a, b) -> c) -> a -> b -> c +```haskell +curry :: ((a, b) -> c) -> a -> b -> c +``` curry converts an uncurried function to a curried function. *Example*: -:: +```haskell +> curry fst 1 2 +1 +``` - > curry fst 1 2 - 1 +#### uncurry -uncurry -******* - -:: - - uncurry :: (a -> b -> c) -> (a, b) -> c +```haskell +uncurry :: (a -> b -> c) -> (a, b) -> c +``` uncurry converts a curried function to a function on pairs. *Example*: -:: - - > uncurry (+) (1,2) - 3 +```haskell +> uncurry (+) (1,2) +3 +``` diff --git a/docs/index.rst b/docs/index.rst index 87fc5185f..48f8161c2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -5,17 +5,17 @@ An alternative Prelude. .. toctree:: :maxdepth: 0 + Function + Strings + Bool + Numbers Printing Debug Files - Strings - Function Applicative Monad Maybe Either - Bool - Numbers Monoid Semigroup Bifunctor diff --git a/src/Protolude.hs b/src/Protolude.hs index 73ed2bd29..90c89de48 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -196,6 +196,7 @@ import Data.Typeable as X ( import Data.Type.Coercion as X ( Coercion(..) , coerceWith + , repr ) import Data.Type.Equality as X ( @@ -269,7 +270,17 @@ import Data.Bits as X hiding ( unsafeShiftL , unsafeShiftR ) -import Data.Word as X +import Data.Word as X ( + byteSwap16 + , byteSwap32 + , byteSwap64 + , Word + , Word16 + , Word32 + , Word64 + , Word8 + ) + import Data.Either as X import Data.Complex as X import Data.Char as X (chr) diff --git a/stack.yaml b/stack.yaml index 38583d04e..bb517b9f0 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-5.10 +resolver: lts-6.2 packages: - '.' extra-deps: