## Examples of Pointwise - Pointfree transformations

### Abs.hs - original

```module Main (main) where

module Abs where

{- imports will be added for the PointlessP librasies -}

-- the whole expression will be selected for translation: `\x -> x`
fun = \x y z -> x
>
```

### Abs.hs - resulting

```module Abs where

{- imports will be added for the PointlessP librasies -}

import PointlessP.Combinators
import PointlessP.Functors
import PointlessP.Isomorphisms
import PointlessP.RecursionPatterns

-- the whole expression will be selected for translation: `\x -> x`
fun = app .
(((curry (curry (curry ((snd . fst) . fst)))) .
bang) /\
id)
```

### Ite.hs - original

```
module Ite where

{- imports will be added for the PointlessP librasies -}

-- the whole expression will be selected for translation.
notZero = \x -> if (== 0) x then False else True
```

### Ite.hs - resulting

```module Ite where

{- imports will be added for the PointlessP librasies -}

import PointlessP.Combinators
import PointlessP.Functors
import PointlessP.Isomorphisms
import PointlessP.RecursionPatterns

-- the whole expression will be selected for translation.
notZero = app .
(((curry
(app .
((curry
((((inN (_L :: Bool)) . (Right . bang)) \/
((inN (_L :: Bool)) . (Left . bang))) .
distr)) /\
((ouT (_L :: Bool)) .
(app .
((curry
((((inN (_L :: Bool)) . (Left . bang)) \/
((inN (_L :: Bool)) .
(Right . bang))) .
distr)) /\
((ouT (_L :: Int)) . snd))))))) .
bang) /\
id)
```

### Case.hs - original

```module Case where

{- imports will be added for the PointlessP librasies -}

-- the hole expression will be selected for translation.
coswap = \x -> case x of Left y -> Right y
Right y -> Left y
```

### Case.hs - resulting

```module Case where

{- imports will be added for the PointlessP librasies -}

import PointlessP.Combinators
import PointlessP.Functors
import PointlessP.Isomorphisms
import PointlessP.RecursionPatterns

-- the hole expression will be selected for translation.
coswap = app .
(((curry
(app .
((curry (((Right . snd) \/ (Left . snd)) . distr)) /\
snd))) .
bang) /\
id)
```

### RecNat.hs - original

```module RecNat where

{- imports will be added for the PointlessP librasies -}

recNat :: Int -> (Int -> a -> a) -> a -> a
recNat 0 f z = z
recNat n f z = f (n-1) (recNat (n-1) f z)
--   recNat (n+1) f z = f n (recNat n f z)

-- the whole expression will be selected for translation.
-- note that recNat can be converted into a paramorphism because
--  the 2nd and 3rd arguments don't have free variables
double = \n -> recNat n (\pred rec -> succ (succ rec)) 0
```

### RecNat.hs - resulting

```module RecNat where

import PointlessP.Combinators
import PointlessP.Functors
import PointlessP.Isomorphisms
import PointlessP.RecursionPatterns

{- imports will be added for the PointlessP librasies -}

recNat :: Int -> (Int -> a -> a) -> a -> a
recNat 0 f z = z
recNat n f z = f (n-1) (recNat (n-1) f z)
--   recNat (n+1) f z = f n (recNat n f z)

-- the whole expression will be selected for translation.
-- note that recNat can be converted into a paramorphism because
--  the 2nd and 3rd arguments don't have free variables
double = app .
(((curry
((para (_L :: Int)
(app .
(((curry
(app .
((curry
((((inN (_L :: Int)) . (Left . bang)) \/
(app .
((app .
((curry
(curry
((inN (_L :: Int)) .
(Right .
((inN (_L :: Int)) .
(Right .
snd)))))) /\
(snd . snd))) /\
(fst . snd)))) .
distr)) /\
snd))) .
bang) /\
id))) .
snd)) .
bang) /\
id)
```

### InfixOp.hs - original

```module InfixOp where

import PointlessP.Combinators

{- imports will be added for the PointlessP librasies -}

(.+.) _ n m  = n + m

subt _ n m = n - m

-- the whole expression will be selected for translation.
--    it calculates f x y = 2x-2y.
--    Note that all the free variables (of the selected expression) will
--     have a different type after the transformation.
calculate = \x y -> subt ((x .+. x) `subt` y) y
```

### InfixOp.hs - resulting

```module InfixOp where

import PointlessP.Combinators
import PointlessP.Functors
import PointlessP.Isomorphisms
import PointlessP.RecursionPatterns

{- imports will be added for the PointlessP librasies -}

(.+.) _ n m  = n + m

subt _ n m = n - m

-- the whole expression will be selected for translation.
--    it calculates f x y = 2x-2y.
--    Note that all the free variables (of the selected expression) will
--     have a different type after the transformation.
calculate = app .
(((curry
(curry
(app .
((app .
(((subt . fst) . fst) /\
(app .
((app .
(((subt . fst) . fst) /\
(app .
((app .
((((.+.) . fst) .
fst) /\
(snd . fst))) /\
(snd . fst))))) /\
snd)))) /\
snd)))) .
bang) /\
id)
```

### InOut.hs - original

```module InOut where

import PointlessP.Functors
import PointlessP.Combinators

{- imports will be added for the PointlessP librasies -}

-- the whole expression will be selected for translation.
tail' = \lst -> case (ouT (_L::[a]) lst) of
Left x -> inN (_L::[a]) (Left _L)
-- if the list is emptu, return the empty list
Right x -> x
-- otherwise return the tail
```

### InOut.hs - resulting

```module InOut where

import PointlessP.Functors
import PointlessP.Combinators
import PointlessP.Isomorphisms
import PointlessP.RecursionPatterns

{- imports will be added for the PointlessP librasies -}

-- the whole expression will be selected for translation.
tail' = app .
(((curry
(app .
((curry
((((inN (_L :: [a])) . (Left . bang)) \/ snd) .
distr)) /\
((ouT (_L :: [a])) . snd)))) .
bang) /\
id)
-- otherwise return the tail
```

### Let.hs - original

```module Let where

import PointlessP.Functors

{- imports will be added for the PointlessP librasies -}

-- the whole expression will be selected for translation.
isort =
let leq = \x y -> if (==0) x then True
else if y==0 then False
else leq (pred x) (pred y)

in let insert = \x lst ->
if null lst then [x]
else if (leq x (head lst))
then x : lst
else (head lst) : (insert x (tail lst))

in let isort = \lst -> if (null lst)
then []
else insert (head lst) (isort (tail lst))

in isort

```

### Let.hs - resulting

```module Let where

import PointlessP.Functors
import PointlessP.Combinators
import PointlessP.Isomorphisms
import PointlessP.RecursionPatterns

{- imports will be added for the PointlessP librasies -}

-- the whole expression will be selected for translation.
isort =
app .
(((app .
((curry
(app .
((curry
(app .
((curry snd) /\
(fix .
(curry
(curry
(app .
((curry
((((inN (_L :: [a])) .
(Left .
bang)) \/
(app .
((app .
((((snd .
fst) .
fst) .
fst) /\
(app .
((curry
((((((((undefined .
fst) .
fst) .
fst) .
fst) .
fst) .
fst) \/
(fst .
snd)) .
distr)) /\
((ouT (_L :: [a])) .
(snd .
fst)))))) /\
(app .
(((snd .
fst) .
fst) /\
(app .
((curry
((((inN (_L :: [a])) .
(Left .
bang)) \/
(snd .
snd)) .
distr)) /\
((ouT (_L :: [a])) .
(snd .
fst))))))))) .
distr)) /\
((ouT (_L :: Bool)) .
(app .
((curry
((((inN (_L :: Bool)) .
(Left .
bang)) \/
((inN (_L :: Bool)) .
(Right .
bang))) .
distr)) /\
((ouT (_L :: [a])) .
snd)))))))))))) /\
(fix .
(curry
(curry
(curry
(app .
((curry
((((inN (_L :: [a])) .
(Right .
(((snd .
fst) .
fst) /\
((inN (_L :: [a])) .
(Left .
bang))))) \/
(app .
((curry
((((inN (_L :: [a])) .
(Right .
((((snd .
fst) .
fst) .
fst) /\
((snd .
fst) .
fst)))) \/
((inN (_L :: [a])) .
(Right .
((app .
((curry
(((((((((undefined .
fst) .
fst) .
fst) .
fst) .
fst) .
fst) .
fst) \/
(fst .
snd)) .
distr)) /\
((ouT (_L :: [a])) .
((snd .
fst) .
fst)))) /\
(app .
((app .
(((((snd .
fst) .
fst) .
fst) .
fst) /\
(((snd .
fst) .
fst) .
fst))) /\
(app .
((curry
((((inN (_L :: [a])) .
(Left .
bang)) \/
(snd .
snd)) .
distr)) /\
((ouT (_L :: [a])) .
((snd .
fst) .
fst)))))))))) .
distr)) /\
((ouT (_L :: Bool)) .
(app .
((app .
(((((snd .
fst) .
fst) .
fst) .
fst) /\
((snd .
fst) .
fst))) /\
(app .
((curry
((((((((undefined .
fst) .
fst) .
fst) .
fst) .
fst) .
fst) \/
(fst .
snd)) .
distr)) /\
((ouT (_L :: [a])) .
(snd .
fst)))))))))) .
distr)) /\
((ouT (_L :: Bool)) .
(app .
((curry
((((inN (_L :: Bool)) .
(Left .
bang)) \/
((inN (_L :: Bool)) .
(Right .
bang))) .
distr)) /\
((ouT (_L :: [a])) .
snd))))))))))))) /\
(fix .
(curry
(curry
(curry
(app .
((curry
((((inN (_L :: Bool)) .
(Left . bang)) \/
(app .
((curry
((((inN (_L :: Bool)) .
(Right .
bang)) \/
(app .
((app .
(((((snd .
fst) .
fst) .
fst) .
fst) /\
(app .
((curry
((((inN (_L :: Int)) .
(Left .
bang)) \/
snd) .
distr)) /\
((ouT (_L :: Int)) .
(((snd .
fst) .
fst) .
fst)))))) /\
(app .
((curry
((((inN (_L :: Int)) .
(Left .
bang)) \/
snd) .
distr)) /\
((ouT (_L :: Int)) .
((snd .
fst) .
fst))))))) .
distr)) /\
((ouT (_L :: Bool)) .
(app .
((curry
((((inN (_L :: Bool)) .
(Left .
bang)) \/
((inN (_L :: Bool)) .
(Right .
bang))) .
distr)) /\
((ouT (_L :: Int)) .
(snd .
fst)))))))) .
distr)) /\
((ouT (_L :: Bool)) .
(app .
((curry
((((inN (_L :: Bool)) .
(Left .
bang)) \/
((inN (_L :: Bool)) .
(Right .
bang))) .
distr)) /\
((ouT (_L :: Int)) .
(snd .
fst))))))))))))) .
bang) /\
id)

```