{-# LANGUAGE NoImplicitPrelude #-}
module AOPPrelude
  ( -- Standard combinators
    (.), const, id
  , outl, outr, swap
  , assocl, assocr
  , dupl, dupr
  , pair, cross, cond
  , curry, uncurry
    -- Boolean functions
  , false, true
  , (&&)
  , (||)
  , not
  , otherwise
    -- Relations
  , leq, less, eql, neq, gtr, geq
  , meet, join, wok
    -- Numerical functions
  , zero, succ, pred
  , plus, minus, times, divide
  , negative, positive
    -- List-processing functions
  , (++)
  , null
  , nil, wrap, cons, cat, concat, snoc
  , head, tail, split
  , last, init
  , inits, tails, splits
  , cpp, cpl, cpr, cplist
  , minlist, bmin
  , maxlist, bmax
  , thinlist
  , length, sum, trans, list, filter
  , catalist
  , cata1list
  , cata2list
  , loop
  , merge
  , zip
  , unzip
    -- Word and line processing functions
  , words
  , lines
  , unwords
  , unlines
    -- Essentials and built-in primitives
  , ord, chr
  , (==), (/=), (<=), (<), (>=), (>)
  , (+), (-), (/), div, mod, (*)
  , negate, primPrint, strict, error
  , show
  , flip
    -- Re-exports
  , String
  , Eq
  , Ord
  , Num
  , Fractional
  , Show
  , Integer
  , Natural
  , module GHC.Types
  ) where
---------------------------------------------------------------------
-- Prelude for `Algebra of Programming' -----------------------------
-- Original created 14 Sept, 1995, by Richard Bird ------------------
---------------------------------------------------------------------

-- Operator precedence table: ---------------------------------------
import GHC.Base ((==), (/=), (<), (<=), (>=), (>), ($!), String)
import GHC.Err (error)
import GHC.Num ((+), (-), (*), negate, Num)
import GHC.Real ((/), div, mod, Fractional)
import GHC.Show (Show, show)
import GHC.Classes hiding (not, (&&), (||))
import GHC.Integer (Integer)
import GHC.Types

import Numeric.Natural (Natural)
import Data.Char (ord, chr)
import System.IO (print)

infixr 9 .
infixr 5 ++
infixr 3 &&
infixr 2 ||

-- Standard combinators: --------------------------------------------
(.) :: (b -> c) -> (a -> b) -> a -> c
(b -> c
f . :: forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
g) a
x = b -> c
f (a -> b
g a
x)
const :: a -> b -> a
const :: forall a b. a -> b -> a
const a
k b
a = a
k
id :: a -> a
id :: forall a. a -> a
id a
a      = a
a

outl :: (a, b) -> a
outl :: forall a b. (a, b) -> a
outl (a
a, b
_) = a
a
outr :: (a, b) -> b
outr :: forall a b. (a, b) -> b
outr (a
_, b
b) = b
b
swap :: (a, b) -> (b, a)
swap :: forall a b. (a, b) -> (b, a)
swap (a
a, b
b) = (b
b, a
a)

assocl :: (a, (b, c)) -> ((a, b), c)
assocl :: forall a b c. (a, (b, c)) -> ((a, b), c)
assocl (a
a, (b
b, c
c)) = ((a
a, b
b), c
c)
assocr :: ((a, b), c) -> (a, (b, c))
assocr :: forall a b c. ((a, b), c) -> (a, (b, c))
assocr ((a
a, b
b), c
c) = (a
a, (b
b, c
c))

dupl :: (a, (b, c)) -> ((a, b), (a, c))
dupl :: forall a b c. (a, (b, c)) -> ((a, b), (a, c))
dupl (a
a, (b
b, c
c)) = ((a
a, b
b), (a
a, c
c))
dupr :: ((a, b), c) -> ((a, c), (b, c))
dupr :: forall a b c. ((a, b), c) -> ((a, c), (b, c))
dupr ((a
a, b
b), c
c) = ((a
a, c
c), (b
b, c
c))

pair :: (a -> b, a -> c) -> a -> (b, c)
pair :: forall a b c. (a -> b, a -> c) -> a -> (b, c)
pair (a -> b
f, a -> c
g) a
a       = (a -> b
f a
a, a -> c
g a
a)
cross :: (a -> c, b -> d) -> (a, b) -> (c, d)
cross :: forall a c b d. (a -> c, b -> d) -> (a, b) -> (c, d)
cross (a -> c
f, b -> d
g) (a
a, b
b) = (a -> c
f a
a, b -> d
g b
b)
cond :: (a -> Bool) -> (a -> b, a -> b) -> a -> b
cond :: forall a b. (a -> Bool) -> (a -> b, a -> b) -> a -> b
cond a -> Bool
p (a -> b
f, a -> b
g) a
a     = if a -> Bool
p a
a then a -> b
f a
a else a -> b
g a
a

curry :: ((a, b) -> c) -> a -> b -> c
curry :: forall a b c. ((a, b) -> c) -> a -> b -> c
curry (a, b) -> c
f a
a b
b      = (a, b) -> c
f (a
a, b
b)
uncurry :: (a -> b -> c) -> (a, b) -> c
uncurry :: forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> c
f (a
a, b
b) = a -> b -> c
f a
a b
b

-- Boolean functions: -----------------------------------------------
false :: a -> Bool
false :: forall a. a -> Bool
false = forall a b. a -> b -> a
const Bool
False
true  :: a -> Bool
true :: forall a. a -> Bool
true  = forall a b. a -> b -> a
const Bool
True

(&&) :: Bool -> Bool -> Bool
Bool
False && :: Bool -> Bool -> Bool
&& Bool
_ = Bool
False
Bool
True  && Bool
x = Bool
x

(||) :: Bool -> Bool -> Bool
Bool
False || :: Bool -> Bool -> Bool
|| Bool
x = Bool
x
Bool
True  || Bool
_ = Bool
True

not :: Bool -> Bool
not :: Bool -> Bool
not Bool
True   = Bool
False
not Bool
False  = Bool
True

otherwise :: Bool
otherwise :: Bool
otherwise  = Bool
True

-- Relations: -------------------------------------------------------
leq :: Ord a => (a, a) -> Bool
leq :: forall a. Ord a => (a, a) -> Bool
leq  = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Ord a => a -> a -> Bool
(<=)
less :: Ord a => (a, a) -> Bool
less :: forall a. Ord a => (a, a) -> Bool
less = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Ord a => a -> a -> Bool
(<)
eql :: Ord a => (a, a) -> Bool
eql :: forall a. Ord a => (a, a) -> Bool
eql  = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Eq a => a -> a -> Bool
(==)
neq :: Ord a => (a, a) -> Bool
neq :: forall a. Ord a => (a, a) -> Bool
neq  = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Eq a => a -> a -> Bool
(/=)
gtr :: Ord a => (a, a) -> Bool
gtr :: forall a. Ord a => (a, a) -> Bool
gtr  = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Ord a => a -> a -> Bool
(>)
geq :: Ord a => (a, a) -> Bool
geq :: forall a. Ord a => (a, a) -> Bool
geq  = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Ord a => a -> a -> Bool
(>=)

meet :: (a -> Bool, a -> Bool) -> a -> Bool
meet :: forall a. (a -> Bool, a -> Bool) -> a -> Bool
meet (a -> Bool
r, a -> Bool
s) = forall a b. (a -> Bool) -> (a -> b, a -> b) -> a -> b
cond a -> Bool
r (a -> Bool
s, forall a. a -> Bool
false)
join :: (a -> Bool, a -> Bool) -> a -> Bool
join :: forall a. (a -> Bool, a -> Bool) -> a -> Bool
join (a -> Bool
r, a -> Bool
s) = forall a b. (a -> Bool) -> (a -> b, a -> b) -> a -> b
cond a -> Bool
r (forall a. a -> Bool
true, a -> Bool
s)
wok :: ((b, a) -> c) -> (a, b) -> c
wok :: forall b a c. ((b, a) -> c) -> (a, b) -> c
wok (b, a) -> c
r       = (b, a) -> c
r forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> (b, a)
swap

-- Numerical functions: ---------------------------------------------
zero   :: Num a => t -> a
zero :: forall a t. Num a => t -> a
zero   = forall a b. a -> b -> a
const a
0
succ   :: Num a => a -> a
succ :: forall a. Num a => a -> a
succ   = (forall a. Num a => a -> a -> a
+a
1)
pred   :: Num a => a -> a
pred :: forall a. Num a => a -> a
pred a
n = a
n forall a. Num a => a -> a -> a
- a
1

plus   :: Num a => (a, a) -> a
plus :: forall a. Num a => (a, a) -> a
plus   = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Num a => a -> a -> a
(+)
minus  :: Num a => (a, a) -> a
minus :: forall a. Num a => (a, a) -> a
minus  = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-)
times  :: Num a => (a, a) -> a
times :: forall a. Num a => (a, a) -> a
times  = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Num a => a -> a -> a
(*)
divide :: Fractional a => (a, a) -> a
divide :: forall a. Fractional a => (a, a) -> a
divide = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Fractional a => a -> a -> a
(/)

negative :: (Ord a, Num a) => a -> Bool
negative :: forall a. (Ord a, Num a) => a -> Bool
negative = (forall a. Ord a => a -> a -> Bool
< a
0)
positive :: (Ord a, Num a) => a -> Bool
positive :: forall a. (Ord a, Num a) => a -> Bool
positive = (forall a. Ord a => a -> a -> Bool
> a
0)

-- List-processing functions: ---------------------------------------
(++) :: [a] -> [a] -> [a]
[] ++ :: forall a. [a] -> [a] -> [a]
++ [a]
y    = [a]
y
(a
a:[a]
x) ++ [a]
y = a
a forall a. a -> [a] -> [a]
: ([a]
x forall a. [a] -> [a] -> [a]
++ [a]
y)

null :: [a] -> Bool
null :: forall a. [a] -> Bool
null []    = Bool
True
null (a
_:[a]
_) = Bool
False

nil :: t -> [a]
nil :: forall t a. t -> [a]
nil    = forall a b. a -> b -> a
const []
wrap :: a -> [a]
wrap :: forall a. a -> [a]
wrap   = forall a. (a, [a]) -> [a]
cons forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b, a -> c) -> a -> (b, c)
pair (forall a. a -> a
id, forall t a. t -> [a]
nil)
cons :: (a, [a]) -> [a]
cons :: forall a. (a, [a]) -> [a]
cons   = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (:)
cat :: ([a], [a]) -> [a]
cat :: forall a. ([a], [a]) -> [a]
cat    = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. [a] -> [a] -> [a]
(++)
concat :: [[a]] -> [a]
concat :: forall a. [[a]] -> [a]
concat = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist ([], forall a. ([a], [a]) -> [a]
cat)
snoc :: ([a], a) -> [a]
snoc :: forall a. ([a], a) -> [a]
snoc   = forall a. ([a], [a]) -> [a]
cat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a c b d. (a -> c, b -> d) -> (a, b) -> (c, d)
cross (forall a. a -> a
id, forall a. a -> [a]
wrap)

head :: [a] -> a
head :: forall a. [a] -> a
head (a
a:[a]
_) = a
a
tail :: [a] -> [a]
tail :: forall a. [a] -> [a]
tail (a
_:[a]
x) = [a]
x
split :: [a] -> (a, [a])
split :: forall a. [a] -> (a, [a])
split      = forall a b c. (a -> b, a -> c) -> a -> (b, c)
pair (forall a. [a] -> a
head, forall a. [a] -> [a]
tail)

last :: [a] -> a
last :: forall a. [a] -> a
last = forall a b. (a -> b, (a, b) -> b) -> [a] -> b
cata1list (forall a. a -> a
id, forall a b. (a, b) -> b
outr)
init :: [a] -> [a]
init :: forall a. [a] -> [a]
init = forall a b. (a -> b, (a, b) -> b) -> [a] -> b
cata1list (forall t a. t -> [a]
nil, forall a. (a, [a]) -> [a]
cons)

inits :: [a] -> [[a]]
inits :: forall a. [a] -> [[a]]
inits = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist ([[]], forall {a}. (a, [[a]]) -> [[a]]
extend)
  where extend :: (a, [[a]]) -> [[a]]
extend (a
a, [[a]]
xs) = [] forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
list (a
aforall a. a -> [a] -> [a]
:) [[a]]
xs
tails :: [a] -> [[a]]
tails :: forall a. [a] -> [[a]]
tails = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist ([[]], forall {a}. (a, [[a]]) -> [[a]]
extend)
  where extend :: (a, [[a]]) -> [[a]]
extend (a
a, [a]
x:[[a]]
xs) = (a
aforall a. a -> [a] -> [a]
:[a]
x)forall a. a -> [a] -> [a]
:[a]
xforall a. a -> [a] -> [a]
:[[a]]
xs
splits :: [a] -> [([a], [a])]
splits :: forall a. [a] -> [([a], [a])]
splits = forall a b. ([a], [b]) -> [(a, b)]
zip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b, a -> c) -> a -> (b, c)
pair (forall a. [a] -> [[a]]
inits, forall a. [a] -> [[a]]
tails)

cpp :: ([a], [b]) -> [(a, b)]
cpp :: forall a b. ([a], [b]) -> [(a, b)]
cpp ([a]
x, [b]
y) = [(a
a, b
b) | a
a <- [a]
x, b
b <- [b]
y]
cpl :: ([a], b) -> [(a, b)]
cpl :: forall a b. ([a], b) -> [(a, b)]
cpl ([a]
x, b
b) = [(a
a, b
b) | a
a <- [a]
x]
cpr :: (a, [b]) -> [(a, b)]
cpr :: forall a b. (a, [b]) -> [(a, b)]
cpr (a
a, [b]
y) = [(a
a, b
b) | b
b <- [b]
y]
cplist :: [[a]] -> [[a]]
cplist :: forall a. [[a]] -> [[a]]
cplist     = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist ([[]], forall a b. (a -> b) -> [a] -> [b]
list forall a. (a, [a]) -> [a]
cons forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. ([a], [b]) -> [(a, b)]
cpp)

minlist :: ((a, a) -> Bool) -> [a] -> a
minlist :: forall a. ((a, a) -> Bool) -> [a] -> a
minlist (a, a) -> Bool
r = forall a b. (a -> b, (a, b) -> b) -> [a] -> b
cata1list (forall a. a -> a
id, forall a. ((a, a) -> Bool) -> (a, a) -> a
bmin (a, a) -> Bool
r)
bmin :: ((a, a) -> Bool) -> (a, a) -> a
bmin :: forall a. ((a, a) -> Bool) -> (a, a) -> a
bmin (a, a) -> Bool
r    = forall a b. (a -> Bool) -> (a -> b, a -> b) -> a -> b
cond (a, a) -> Bool
r (forall a b. (a, b) -> a
outl, forall a b. (a, b) -> b
outr)

maxlist :: ((a, a) -> Bool) -> [a] -> a
maxlist :: forall a. ((a, a) -> Bool) -> [a] -> a
maxlist (a, a) -> Bool
r = forall a b. (a -> b, (a, b) -> b) -> [a] -> b
cata1list (forall a. a -> a
id, forall a. ((a, a) -> Bool) -> (a, a) -> a
bmax (a, a) -> Bool
r)
bmax :: ((a, a) -> Bool) -> (a, a) -> a
bmax :: forall a. ((a, a) -> Bool) -> (a, a) -> a
bmax (a, a) -> Bool
r    = forall a b. (a -> Bool) -> (a -> b, a -> b) -> a -> b
cond ((a, a) -> Bool
r forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> (b, a)
swap) (forall a b. (a, b) -> a
outl, forall a b. (a, b) -> b
outr)

thinlist :: ((a, a) -> Bool) -> [a] -> [a]
thinlist :: forall a. ((a, a) -> Bool) -> [a] -> [a]
thinlist (a, a) -> Bool
r = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist ([], forall {a}. ((a, a) -> Bool) -> (a, [a]) -> [a]
bump (a, a) -> Bool
r)
  where bump :: ((a, a) -> Bool) -> (a, [a]) -> [a]
bump (a, a) -> Bool
r (a
a, [])  = [a
a]
        bump (a, a) -> Bool
r (a
a, a
b:[a]
x) | (a, a) -> Bool
r (a
a, a
b)  = a
aforall a. a -> [a] -> [a]
:[a]
x
                        | (a, a) -> Bool
r (a
b, a
a)  = a
bforall a. a -> [a] -> [a]
:[a]
x
                        | Bool
otherwise = a
aforall a. a -> [a] -> [a]
:a
bforall a. a -> [a] -> [a]
:[a]
x

length :: Num a => [t] -> a
length :: forall a t. Num a => [t] -> a
length   = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist (a
0, forall a. Num a => a -> a
succ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
outr)
sum :: Num a => [a] -> a
sum :: forall a. Num a => [a] -> a
sum      = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist (a
0, forall a. Num a => (a, a) -> a
plus)
trans :: [[a]] -> [[a]]
trans :: forall a. [[a]] -> [[a]]
trans    = forall a b. (a -> b, (a, b) -> b) -> [a] -> b
cata1list (forall a b. (a -> b) -> [a] -> [b]
list forall a. a -> [a]
wrap, forall a b. (a -> b) -> [a] -> [b]
list forall a. (a, [a]) -> [a]
cons forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. ([a], [b]) -> [(a, b)]
zip)
list :: (a -> b) -> [a] -> [b]
list :: forall a b. (a -> b) -> [a] -> [b]
list a -> b
f   = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist ([], forall a. (a, [a]) -> [a]
cons forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a c b d. (a -> c, b -> d) -> (a, b) -> (c, d)
cross (a -> b
f, forall a. a -> a
id))
filter :: (a -> Bool) -> [a] -> [a]
filter :: forall a. (a -> Bool) -> [a] -> [a]
filter a -> Bool
p = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist ([], forall a b. (a -> Bool) -> (a -> b, a -> b) -> a -> b
cond (a -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
outl) (forall a. (a, [a]) -> [a]
cons, forall a b. (a, b) -> b
outr))

catalist :: (b, (a, b) -> b) -> [a] -> b
catalist :: forall b a. (b, (a, b) -> b) -> [a] -> b
catalist (b
c, (a, b) -> b
f) []    = b
c
catalist (b
c, (a, b) -> b
f) (a
a:[a]
x) = (a, b) -> b
f (a
a, forall b a. (b, (a, b) -> b) -> [a] -> b
catalist (b
c, (a, b) -> b
f) [a]
x)

cata1list :: (a -> b, (a, b) -> b) -> [a] -> b
cata1list :: forall a b. (a -> b, (a, b) -> b) -> [a] -> b
cata1list (a -> b
f, (a, b) -> b
g) [a
a]   = a -> b
f a
a
cata1list (a -> b
f, (a, b) -> b
g) (a
a:[a]
x) = (a, b) -> b
g (a
a, forall a b. (a -> b, (a, b) -> b) -> [a] -> b
cata1list (a -> b
f, (a, b) -> b
g) [a]
x)

cata2list :: ((a, a) -> b, (a, b) -> b) -> [a] -> b
cata2list :: forall a b. ((a, a) -> b, (a, b) -> b) -> [a] -> b
cata2list ((a, a) -> b
f, (a, b) -> b
g) [a
a,a
b] = (a, a) -> b
f (a
a, a
b)
cata2list ((a, a) -> b
f, (a, b) -> b
g) (a
a:[a]
x) = (a, b) -> b
g (a
a, forall a b. ((a, a) -> b, (a, b) -> b) -> [a] -> b
cata2list ((a, a) -> b
f, (a, b) -> b
g) [a]
x)

loop :: ((a, b) -> a) -> (a, [b]) -> a
loop :: forall a b. ((a, b) -> a) -> (a, [b]) -> a
loop (a, b) -> a
f (a
a, [])  = a
a
loop (a, b) -> a
f (a
a, b
b:[b]
x) = forall a b. ((a, b) -> a) -> (a, [b]) -> a
loop (a, b) -> a
f ((a, b) -> a
f (a
a, b
b), [b]
x)

merge :: ((a, a) -> Bool) -> ([a], [a]) -> [a]
merge :: forall a. ((a, a) -> Bool) -> ([a], [a]) -> [a]
merge (a, a) -> Bool
_ ([], [a]
y)    = [a]
y
merge (a, a) -> Bool
_ ([a]
x, [])    = [a]
x
merge (a, a) -> Bool
r (a
a:[a]
x, a
b:[a]
y) | (a, a) -> Bool
r (a
a, a
b)  = a
a forall a. a -> [a] -> [a]
: forall a. ((a, a) -> Bool) -> ([a], [a]) -> [a]
merge (a, a) -> Bool
r ([a]
x, a
bforall a. a -> [a] -> [a]
:[a]
y)
                   | Bool
otherwise = a
b forall a. a -> [a] -> [a]
: forall a. ((a, a) -> Bool) -> ([a], [a]) -> [a]
merge (a, a) -> Bool
r (a
aforall a. a -> [a] -> [a]
:[a]
x, [a]
y)

zip :: ([a], [b]) -> [(a, b)]
zip :: forall a b. ([a], [b]) -> [(a, b)]
zip ([a]
x, [])    = []
zip ([], [b]
y)    = []
zip (a
a:[a]
x, b
b:[b]
y) = (a
a, b
b) forall a. a -> [a] -> [a]
: forall a b. ([a], [b]) -> [(a, b)]
zip ([a]
x, [b]
y)

unzip :: [(a, b)] -> ([a], [b])
unzip :: forall a b. [(a, b)] -> ([a], [b])
unzip = forall a b c. (a -> b, a -> c) -> a -> (b, c)
pair (forall a b. (a -> b) -> [a] -> [b]
list forall a b. (a, b) -> a
outl, forall a b. (a -> b) -> [a] -> [b]
list forall a b. (a, b) -> b
outr)

-- Word and line processing functions: ------------------------------
words :: String -> [String]
words :: String -> [String]
words = forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Bool
null) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b a. (b, (a, b) -> b) -> [a] -> b
catalist ([[]], forall a b. (a -> Bool) -> (a -> b, a -> b) -> a -> b
cond forall {b}. (Char, b) -> Bool
ok (forall {a}. (a, [[a]]) -> [[a]]
glue, forall {a} {a}. (a, [[a]]) -> [[a]]
new))
  where ok :: (Char, b) -> Bool
ok (Char
a, b
xs)     = Char
a forall a. Eq a => a -> a -> Bool
/= Char
' ' Bool -> Bool -> Bool
&& Char
a forall a. Eq a => a -> a -> Bool
/= Char
'\n'
        glue :: (a, [[a]]) -> [[a]]
glue (a
a, [a]
x:[[a]]
xs) = (a
aforall a. a -> [a] -> [a]
:[a]
x)forall a. a -> [a] -> [a]
:[[a]]
xs
        new :: (a, [[a]]) -> [[a]]
new (a
a, [[a]]
xs)    = []forall a. a -> [a] -> [a]
:[[a]]
xs

lines :: String -> [String]
lines :: String -> [String]
lines = forall b a. (b, (a, b) -> b) -> [a] -> b
catalist ([[]], forall a b. (a -> Bool) -> (a -> b, a -> b) -> a -> b
cond forall {b}. (Char, b) -> Bool
ok (forall {a}. (a, [[a]]) -> [[a]]
glue, forall {a} {a}. (a, [[a]]) -> [[a]]
new))
  where ok :: (Char, b) -> Bool
ok (Char
a, b
xs)     = Char
a forall a. Eq a => a -> a -> Bool
/= Char
'\n'
        glue :: (a, [[a]]) -> [[a]]
glue (a
a, [a]
x:[[a]]
xs) = (a
aforall a. a -> [a] -> [a]
:[a]
x)forall a. a -> [a] -> [a]
:[[a]]
xs
        new :: (a, [[a]]) -> [[a]]
new (a
a,[[a]]
xs)     = []forall a. a -> [a] -> [a]
:[[a]]
xs

unwords :: [String] -> String
unwords :: [String] -> String
unwords = forall a b. (a -> b, (a, b) -> b) -> [a] -> b
cata1list (forall a. a -> a
id, (String, String) -> String
join)
  where join :: (String, String) -> String
join (String
x, String
y) = String
x forall a. [a] -> [a] -> [a]
++ String
" " forall a. [a] -> [a] -> [a]
++ String
y

unlines :: [String] -> String
unlines :: [String] -> String
unlines = forall a b. (a -> b, (a, b) -> b) -> [a] -> b
cata1list (forall a. a -> a
id, (String, String) -> String
join)
  where join :: (String, String) -> String
join (String
x, String
y) = String
x forall a. [a] -> [a] -> [a]
++ String
"\n" forall a. [a] -> [a] -> [a]
++ String
y

-- Essentials and built-in primitives: -------------------------------
primPrint :: Show a => a -> IO ()
primPrint :: forall a. Show a => a -> IO ()
primPrint = forall a. Show a => a -> IO ()
print

strict :: (a -> b) -> a -> b
strict :: forall a b. (a -> b) -> a -> b
strict = forall a b. (a -> b) -> a -> b
($!)

flip :: (a -> b -> c) -> b -> a -> c
flip :: forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> b -> c
f b
a a
b = a -> b -> c
f a
b b
a

-- End of Algebra of Programming prelude ----------------------------