Prelude

The Prelude: a standard module. The Prelude is imported by default into all Haskell modules unless either there is an explicit import statement for it, or the NoImplicitPrelude extension is enabled.
Mostly for compatibility across different base Prelude changes.
Custom GHC Prelude This module serves as a replacement for the Prelude module and abstracts over differences between the bootstrapping GHC version, and may also provide a common default vocabulary.
General purpose utilities The names in this module clash heavily with the Haskell Prelude, so I recommend the following import scheme:
import Pipes
import qualified Pipes.Prelude as P  -- or use any other qualifier you prefer
Note that String-based IO is inefficient. The String-based utilities in this module exist only for simple demonstrations without incurring a dependency on the text package. Also, stdinLn and stdoutLn remove and add newlines, respectively. This behavior is intended to simplify examples. The corresponding stdin and stdout utilities from pipes-bytestring and pipes-text preserve newlines.
The names exported by this module are closely modeled on those in Prelude and Data.List, but also on Pipes.Prelude, Pipes.Group and Pipes.Parse. The module may be said to give independent expression to the conception of Producer / Source / Generator manipulation articulated in the latter two modules. Because we dispense with piping and conduiting, the distinction between all of these modules collapses. Some things are lost but much is gained: on the one hand, everything comes much closer to ordinary beginning Haskell programming and, on the other, acquires the plasticity of programming directly with a general free monad type. The leading type, Stream (Of a) m r is chosen to permit an api that is as close as possible to that of Data.List and the Prelude. Import qualified thus:
import Streaming
import qualified Streaming.Prelude as S
For the examples below, one sometimes needs
import Streaming.Prelude (each, yield, next, mapped, stdoutLn, stdinLn)
import Data.Function ((&))
Other libraries that come up in passing are
import qualified Control.Foldl as L -- cabal install foldl
import qualified Pipes as P
import qualified Pipes.Prelude as P
import qualified System.IO as IO
Here are some correspondences between the types employed here and elsewhere:
streaming             |            pipes               |       conduit       |  io-streams
-------------------------------------------------------------------------------------------------------------------
Stream (Of a) m ()                  | Producer a m ()                | Source m a          | InputStream a
| ListT m a                      | ConduitM () o m ()  | Generator r ()
-------------------------------------------------------------------------------------------------------------------
Stream (Of a) m r                   | Producer a m r                 | ConduitM () o m r   | Generator a r
-------------------------------------------------------------------------------------------------------------------
Stream (Of a) m (Stream (Of a) m r) | Producer a m (Producer a m r)  |
--------------------------------------------------------------------------------------------------------------------
Stream (Stream (Of a) m) r          | FreeT (Producer a m) m r       |
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
ByteString m ()                     | Producer ByteString m ()       | Source m ByteString  | InputStream ByteString
--------------------------------------------------------------------------------------------------------------------
A module to re-export most of the functionality of the diagrams core and standard library.
Simple resource management functions
This module provides a large suite of utilities that resemble Unix utilities. Many of these commands are just existing Haskell commands renamed to match their Unix counterparts:
>>> :set -XOverloadedStrings

>>> cd "/tmp"

>>> pwd
FilePath "/tmp"
Some commands are Shells that emit streams of values. view prints all values in a Shell stream:
>>> view (ls "/usr")
FilePath "/usr/lib"
FilePath "/usr/src"
FilePath "/usr/sbin"
FilePath "/usr/include"
FilePath "/usr/share"
FilePath "/usr/games"
FilePath "/usr/local"
FilePath "/usr/bin"

>>> view (find (suffix "Browser.py") "/usr/lib")
FilePath "/usr/lib/python3.4/idlelib/ClassBrowser.py"
FilePath "/usr/lib/python3.4/idlelib/RemoteObjectBrowser.py"
FilePath "/usr/lib/python3.4/idlelib/PathBrowser.py"
FilePath "/usr/lib/python3.4/idlelib/ObjectBrowser.py"
Use fold to reduce the output of a Shell stream:
>>> import qualified Control.Foldl as Fold

>>> fold (ls "/usr") Fold.length
8

>>> fold (find (suffix "Browser.py") "/usr/lib") Fold.head
Just (FilePath "/usr/lib/python3.4/idlelib/ClassBrowser.py")
Create files using output:
>>> output "foo.txt" ("123" <|> "456" <|> "ABC")

>>> realpath "foo.txt"
FilePath "/tmp/foo.txt"
Read in files using input:
>>> stdout (input "foo.txt")
123
456
ABC
Format strings in a type safe way using format:
>>> dir <- pwd

>>> format ("I am in the "%fp%" directory") dir
"I am in the /tmp directory"
Commands like grep, sed and find accept arbitrary Patterns
>>> stdout (grep ("123" <|> "ABC") (input "foo.txt"))
123
ABC

>>> let exclaim = fmap (<> "!") (plus digit)

>>> stdout (sed exclaim (input "foo.txt"))
123!
456!
ABC
Note that grep and find differ from their Unix counterparts by requiring that the Pattern matches the entire line or file name by default. However, you can optionally match the prefix, suffix, or interior of a line:
>>> stdout (grep (has    "2") (input "foo.txt"))
123

>>> stdout (grep (prefix "1") (input "foo.txt"))
123

>>> stdout (grep (suffix "3") (input "foo.txt"))
123
You can also build up more sophisticated Shell programs using sh in conjunction with do notation:
{-# LANGUAGE OverloadedStrings #-}

import Turtle

main = sh example

example = do
-- Read in file names from "files1.txt" and "files2.txt"
file <- fmap fromText (input "files1.txt" <|> input "files2.txt")

-- Stream each file to standard output only if the file exists
True <- liftIO (testfile file)
line <- input file
liftIO (echo line)
See Turtle.Tutorial for an extended tutorial explaining how to use this library in greater detail.
All Fold related combinators including the streamly-core Streamly.Data.Fold module, concurrency, unordered container operations.
For upgrading to streamly-0.9.0+ please read the Streamly-0.9.0 upgrade guide. Also, see the Streamly.Data.Stream.MkType module for direct replacement of stream types that have been removed in 0.9.0. All Stream related combinators including the streamly-core Streamly.Data.Stream module, concurrency, time and lifted exception operations. For more pre-release operations also see Streamly.Internal.Data.Stream.Prelude module.
Deprecated: Please use Streamly.Data.Stream.Prelude from streamly package and Streamly.Data.Fold from streamly-core package instead.
This module does two things:
  • Acts as a compatibility layer, like base-compat.
  • Provides commonly used imports.
A prelude composed by overlaying numhask on Prelude, together with a few minor tweaks needed for RebindableSyntax.
This module defines the explicitly clocked counterparts of the functions defined in Clash.Prelude.
Clash is a functional hardware description language that borrows both its syntax and semantics from the functional programming language Haskell. The merits of using a functional language to describe hardware comes from the fact that combinational circuits can be directly modeled as mathematical functions and that functional languages lend themselves very well at describing and (de-)composing mathematical functions. This package provides:
  • Prelude library containing datatypes and functions for circuit design
To use the library: For now, Clash.Prelude is also the best starting point for exploring the library. A preliminary version of a tutorial can be found in Clash.Tutorial. Some circuit examples can be found in Clash.Examples.
Generic deriving for standard classes in base

Warning

This is an internal module: it is not subject to any versioning policy, breaking changes can happen at any time. If something here seems useful, please report it or create a pull request to export it from an external module.
This module may change between minor releases. Do not rely on its contents.

Summary

This module supplies a convenient set of imports for working with the dimensional package, including aliases for common Quantitys and Dimensions, and a comprehensive set of SI units and units accepted for use with the SI. It re-exports the Prelude, hiding arithmetic functions whose names collide with the dimensionally-typed versions supplied by this package.
Support for using Haxl as a DSL. This module provides most of the standard Prelude, plus a selection of stuff that makes Haxl client code cleaner and more concise. We intend Haxl client code to:
  • Import Haxl.Prelude
  • Use RebindableSyntax. This implies NoImplicitPrelude, and allows if-then-else to be used with a monadic condition.
  • Use OverloadedStrings (we use Text a lot)