HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleshelly-1.12.1.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)
Contents
  1. Entering Sh
  2. List functions
  3. Running external commands
  4. Modifying and querying environment
  5. Environment directory
  6. Printing
  7. Querying filesystem
  8. Filename helpers
  9. Manipulating filesystem
  10. reading/writing Files
  11. exiting the program
  12. Exceptions
  13. convert between Text and FilePath
  14. Utilities
  15. Re-exported for your convenience
  16. internal functions for writing extensions
  17. find functions
Synopsis
  • Packageshelly-1.12.1.1
  • Exports111
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourcePipe.hs

Entering Sh

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.1 · Shelly.Pipe
  • Functor ShDefined in shelly-1.12.1.1 · Shelly.Pipe
  • Applicative ShDefined in shelly-1.12.1.1 · Shelly.Pipe
  • Alternative ShDefined in shelly-1.12.1.1 · Shelly.Pipe
  • MonadPlus ShDefined in shelly-1.12.1.1 · Shelly.Pipe
  • MonadIO ShDefined in shelly-1.12.1.1 · Shelly.Pipe
  • ShellCommand (Sh Text)Defined in shelly-1.12.1.1 · Shelly.Pipe
  • s ~ () => ShellCommand (Sh s)Defined in shelly-1.12.1.1 · Shelly.Pipe

List functions

valueroll :: Sh [a] -> Sh a

Pack list of results. It performs concat inside Sh.

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

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

Running external commands

Modifying and querying environment

Environment directory

Printing

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

Filename helpers

Manipulating filesystem

reading/writing Files

exiting the program

Exceptions

convert between Text and FilePath

Utilities

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

An infix synonym for fmap.

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

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

Whereas Prelude.$ 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)

Re-exported for your convenience

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.1 · Shelly

internal functions for writing extensions

valueput :: State -> Sh ()
#

find functions