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

ModuleBNFC-2.9.5Haskell2010

BNFC.Utils

  • 2 types
  • 42 values
  • PackageBNFC-2.9.5
  • Exports44
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceUtils.hs
valueunlessNull :: Monoid m => [a] -> ([a] -> m) -> m
#

Invoke continuation for non-empty list.

valueunlessNull' :: Monoid m => [a] -> (a -> [a] -> m) -> m
#

Invoke continuation for non-empty list.

valueapplyWhen :: Bool -> (a -> a) -> a -> a
#

when for the monoid of endofunctions 'a -> a'.

valuefor :: [a] -> (a -> b) -> [b]
#

Non-monadic forM.

value(>.>) :: (a -> b) -> (b -> c) -> a -> c
#

Diagrammatic composition.

valuecurry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
#

Converts an uncurried function to a curried function.

valueuncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
#

Converts a curried function to a function on a triple.

valuesingleton :: a -> [a]
#

Give a telling name to the electric monkey.

valueheadWithDefault :: a -> [a] -> a
#

Get the first element of a list, fallback for empty list.

valuemapHead :: (a -> a) -> [a] -> [a]
#

Apply a function to the head of a list.

valuespanEnd :: (a -> Bool) -> [a] -> ([a], [a])
#

spanEnd p l == reverse (span p (reverse l)).

Invariant: l == front ++ end where (end, front) = spanEnd p l

(From package ghc, module Util.)

valueduplicatesOn :: (Foldable t, Ord b) => (a -> b) -> t a -> [List1 a]
#

Returns lists of elements whose normal form appears more than once.

Example2 expressions
duplicatesOn id  [5,1,2,5,1][1 :| [1],5 :| [5]]duplicatesOn abs [5,-5,1][5 :| [-5]]
valuegroupOn :: Eq b => (a -> b) -> [a] -> [List1 a]
#

Group consecutive elements that have the same normalform.

valueuniqOn :: Eq b => (a -> b) -> [a] -> [a]
#

Keep only the first of consecutive elements that have the same normalform.

Get a numeric suffix if it exists.

Example3 expressions
hasNumericSuffix "hello world"NothinghasNumericSuffix "a1b2"Just ("a1b",2)hasNumericSuffix "1234"Just ("",1234)
valuepad :: Int -> String -> String
#

Pad a string on the right by spaces to reach the desired length.

valuemkName :: [String] -> NameStyle -> String -> String
#

Generate a name in the given case style taking into account the reserved word of the language. Note that despite the fact that those name are mainly to be used in code rendering (type Doc), we return a String here to allow further manipulation of the name (like disambiguation) which is not possible in the Doc type.

Examples:

Example1 expression
mkName [] LowerCase "FooBAR""foobar"
Example1 expression
mkName [] UpperCase "FooBAR""FOOBAR"
Example1 expression
mkName [] SnakeCase "FooBAR""foo_bar"
Example1 expression
mkName [] CamelCase "FooBAR""FooBAR"
Example1 expression
mkName [] CamelCase "Foo_bar""FooBar"
Example1 expression
mkName [] MixedCase "FooBAR""fooBAR"
Example1 expression
mkName ["foobar"] LowerCase "FooBAR""foobar_"
Example1 expression
mkName ["foobar", "foobar_"] LowerCase "FooBAR""foobar__"
valuemkNames :: [String] -> NameStyle -> [String] -> [String]
#

Same as above but accept a list as argument and make sure that the names generated are uniques.

Example1 expression
mkNames ["c"] LowerCase ["A", "b_", "a_", "c"]["a1","b","a2","c_"]
valuereplace
  1. :: Eq a
  2. => a

    Value to replace

  3. -> a

    Value to replace it with

  4. -> [a]
  5. -> [a]
#

Replace all occurences of a value by another value

valuewriteFileRep :: FilePath -> String -> IO ()
#

Write a file, after making a backup of an existing file with the same name. If an old version of the file exist and the new version is the same, keep the old file and don't create a .bak file. / New version by TH, 2010-09-23

valuecstring :: String -> Doc
#

A function that renders a c-like string with escaped characters. Note that although it's called cstring, this can be used with most (all) backend as they seem to mostly share escaping conventions. The c in the name is barely an homage for C being the oldest language in the lot.

Example1 expression
cstring "foobar""foobar"
Example1 expression
cstring "foobar\"""foobar\""