BasePrelude

base-prelude-1.0.1.1: The most complete prelude formed solely from the "base" package

Safe Haskell | None
Language | Haskell2010

BasePrelude

Contents

- Reimplementations of functions presented in versions of "base" newer than 4.6
  - Data.Bool
  - Data.Function
  - Data.Functor
  - Data.List
  - Debug.Trace

Description

This module reexports most of the definitions from the "base" package, which are meant to be imported unqualified.

For details check out the source.

Synopsis

- bool :: a -> a -> Bool -> a
- (&) :: a -> (a -> b) -> b
- ($>) :: Functor f => f a -> b -> f b
- isSubsequenceOf :: Eq a => [a] -> [a] -> Bool
- sortOn :: Ord b => (a -> b) -> [a] -> [a]
- uncons :: [a] -> Maybe (a, [a])
- traceShowId :: Show a => a -> a
- traceM :: Monad m => String -> m ()
- traceShowM :: (Show a, Monad m) => a -> m ()

# Reimplementations of functions presented in versions of "base" newer than 4.6

## Data.Bool

bool :: a -> a -> Bool -> a #

Case analysis for the `Bool` type. `bool a b p` evaluates to `a` when `p` is `False`, and evaluates to `b` when `p` is `True`.

## Data.Function

(&) :: a -> (a -> b) -> b infixl 1 #

`&` is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator `$`, which allows `&` to be nested in `$`.

## Data.Functor

($>) :: Functor f => f a -> b -> f b infixl 4 #

Flipped version of `<$`.

## Data.List

isSubsequenceOf :: Eq a => [a] -> [a] -> Bool #

The `isSubsequenceOf` function takes two lists and returns `True` if the first list is a subsequence of the second list.

``isSubsequenceOf` x y` is equivalent to ``elem` x (`subsequences` y)`.

#### Examples

    >>> isSubsequenceOf "GHC" "The Glorious Haskell Compiler"
    True
    >>> isSubsequenceOf ['a','d'..'z'] ['a'..'z']
    True
    >>> isSubsequenceOf [1..10] [10,9..0]
    False

sortOn :: Ord b => (a -> b) -> [a] -> [a] #

Sort a list by comparing the results of a key function applied to each element. `sortOn f` is equivalent to `sortBy . comparing f`, but has the performance advantage of only evaluating `f` once for each element in the input list. This is called the decorate-sort-undecorate paradigm, or Schwartzian transform.

uncons :: [a] -> Maybe (a, [a]) #

Decompose a list into its head and tail. If the list is empty, returns `Nothing`. If the list is non-empty, returns ``Just` (x, xs)`, where `x` is the head of the list and `xs` its tail.

## Debug.Trace

traceShowId :: Show a => a -> a #

Like `traceShow` but returns the shown value instead of a third value.

traceM :: Monad m => String -> m () #

Like `trace` but returning unit in an arbitrary monad. Allows for convenient use in do-notation. Note that the application of `trace` is not an action in the monad, as `traceIO` is in the `IO` monad.

    ... = do
      x <- ...
      traceM $ "x: " ++ show x
      y <- ...
      traceM $ "y: " ++ show y

traceShowM :: (Show a, Monad m) => a -> m () #

Like `traceM`, but uses `show` on the argument to convert it to a `String`.

    ... = do
      x <- ...
      traceShowM $ x
      y <- ...
      traceShowM $ x + y