{- GENERATED by Isabelle! -}
{- Title: Tools/Haskell/Library.hs
Author: Makarius
LICENSE: BSD 3-clause (Isabelle)
Basic library of Isabelle idioms.
-}
module Isabelle.Library
((|>), (|->), (#>), (#->), fold, fold_rev, single, quote, trim_line)
where
{- functions -}
(|>) :: a -> (a -> b) -> b
x |> f = f x
(|->) :: (a, b) -> (a -> b -> c) -> c
(x, y) |-> f = f x y
(#>) :: (a -> b) -> (b -> c) -> a -> c
(f #> g) x = x |> f |> g
(#->) :: (a -> (c, b)) -> (c -> b -> d) -> a -> d
(f #-> g) x = x |> f |-> g
{- lists -}
fold :: (a -> b -> b) -> [a] -> b -> b
fold _ [] y = y
fold f (x : xs) y = fold f xs (f x y)
fold_rev :: (a -> b -> b) -> [a] -> b -> b
fold_rev _ [] y = y
fold_rev f (x : xs) y = f x (fold_rev f xs y)
single :: a -> [a]
single x = [x]
{- strings -}
quote :: String -> String
quote s = "\"" ++ s ++ "\""
trim_line :: String -> String
trim_line line =
case reverse line of
'\n' : '\r' : rest -> reverse rest
'\n' : rest -> reverse rest
_ -> line