HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleshelly-1.12.1Haskell2010

Shelly.Pipe

This module is a wrapper for the module Shelly. The only difference is a main type Sh. In this module Sh contains a list of results. Actual definition of the type Sh is:

import qualified Shelly as S

newtype Sh a = Sh { unSh :: S.Sh [a] }

This definition can simplify some filesystem commands. A monad bind operator becomes a pipe operator and we can write

findExt ext = findWhen (pure . hasExt ext)

main :: IO ()
main = shs $ do
    mkdir "new"
    findExt "hs"  "." >>= flip cp "new"
    findExt "cpp" "." >>= rm_f
    liftIO $ putStrLn "done"

Documentation in this module mostly just reference documentation from the main Shelly module.

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExtendedDefaultRules #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Shelly
import Data.Text as T
default (T.Text)
  • 4 types
  • 106 values
  • Packageshelly-1.12.1
  • Exports111
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourcePipe.hs

Entering Sh

15 declarations
newtypenewtype Sh a
#

This type is a simple wrapper for a type Shelly.Sh. Sh contains a list of results.

Instances8Monad, Functor, Applicative, Alternative, MonadPlus, MonadIO, …
  • Monad ShDefined in shelly-1.12.1 · Shelly.Pipe
  • Functor ShDefined in shelly-1.12.1 · Shelly.Pipe
  • Applicative ShDefined in shelly-1.12.1 · Shelly.Pipe
  • Alternative ShDefined in shelly-1.12.1 · Shelly.Pipe
  • MonadPlus ShDefined in shelly-1.12.1 · Shelly.Pipe
  • MonadIO ShDefined in shelly-1.12.1 · Shelly.Pipe
  • ShellCommand (Sh Text)Defined in shelly-1.12.1 · Shelly.Pipe
  • s ~ () => ShellCommand (Sh s)Defined in shelly-1.12.1 · Shelly.Pipe
valueshs :: MonadIO m => Sh () -> m ()
#

Performs shelly and then an empty action return ().

List functions

3 declarations
valueroll :: Sh [a] -> Sh a
#

Pack list of results. It performs concat inside Sh.

valueunroll :: Sh a -> Sh [a]
#

Unpack list of results.

valueliftSh :: ([a] -> [b]) -> Sh a -> Sh b
#

Transform result as list. It can be useful for filtering.

Running external commands

15 declarations

Modifying and querying environment

6 declarations

Environment directory

3 declarations

Printing

9 declarations
valueecho :: Text -> Sh ()
#

Echo text to standard (error, when using _err variants) output. The _n variants do not print a final newline.

valueecho_n :: Text -> Sh ()
#

Echo text to standard (error, when using _err variants) output. The _n variants do not print a final newline.

valueecho_err :: Text -> Sh ()
#

Echo text to standard (error, when using _err variants) output. The _n variants do not print a final newline.

valueecho_n_err :: Text -> Sh ()
#

Echo text to standard (error, when using _err variants) output. The _n variants do not print a final newline.

Querying filesystem

7 declarations

Filename helpers

8 declarations
value(</>)
  1. :: (ToFilePath filepath1, ToFilePath filepath2)
  2. => filepath1
  3. -> filepath2
  4. -> FilePath
#

Uses System.FilePath, but can automatically convert a Text.

Manipulating filesystem

9 declarations

reading/writing Files

6 declarations

exiting the program

4 declarations

Exceptions

6 declarations

convert between Text and FilePath

3 declarations

Utilities

4 declarations
value(<$>) :: Functor f => (a -> b) -> f a -> f b
#

An infix synonym for fmap.

The name of this operator is an allusion to $. Note the similarities between their types:

 ($)  ::              (a -> b) ->   a ->   b
(<$>) :: Functor f => (a -> b) -> f a -> f b

Whereas $ is function application, <$> is function application lifted over a Functor.

Examples

Convert from a Maybe Int to a Maybe String using show:

Example1 expression
show <$> NothingNothing
Example1 expression
show <$> Just 3Just "3"

Convert from an Either Int Int to an Either Int String using show:

Example1 expression
show <$> Left 17Left 17
Example1 expression
show <$> Right 17Right "17"

Double each element of a list:

Example1 expression
(*2) <$> [1,2,3][2,4,6]

Apply even to the second element of a pair:

Example1 expression
even <$> (2,2)(2,True)
valuewhenM :: Monad m => m Bool -> m () -> m ()
#

A monadic-conditional version of the when guard.

Re-exported for your convenience

4 declarations
methodliftIO :: IO a -> m a
#

Lift a computation from the IO monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. IO is the base monad for the stack).

Example
import Control.Monad.Trans.State -- from the "transformers" library

printState :: Show s => StateT s IO ()
printState = do
  state <- get
  liftIO $ print state

Had we omitted liftIO, we would have ended up with this error:

• Couldn't match type ‘IO’ with ‘StateT s IO’
 Expected type: StateT s IO ()
   Actual type: IO ()

The important part here is the mismatch between StateT s IO () and IO ().

Luckily, we know of a function that takes an IO a and returns an (m a): liftIO, enabling us to run the program and see the expected results:

> evalStateT printState "hello"
"hello"

> evalStateT printState 3
3
valuewhen :: Applicative f => Bool -> f () -> f ()
#

Conditional execution of Applicative expressions. For example,

Examples
when debug (putStrLn "Debugging")

will output the string Debugging if the Boolean value debug is True, and otherwise do nothing.

Example1 expression
putStr "pi:" >> when False (print 3.14159)pi:
valueunless :: Applicative f => Bool -> f () -> f ()
#

The reverse of when.

Examples
Example1 expression
do x <- getLine       unless (x == "hi") (putStrLn "hi!")comingupwithexamplesisdifficulthi!
Example1 expression
unless (pi > exp 1) NothingJust ()
typetype FilePath = String
#

File and directory names are values of type String, whose precise meaning is operating system dependent. Files can be opened, yielding a handle which can then be used to operate on the contents of that file.

Instances1ToFilePath
  • ToFilePath FilePathDefined in shelly-1.12.1 · Shelly

internal functions for writing extensions

2 declarations
valueput :: State -> Sh ()
#

find functions

7 declarations