haskellrecursioncatamorphism# Is Data.List.Extra's list function the catamorphism of list?

Haskell's base library contains several functions which are the lowercase versions of their respective data types, like `bool`

, `maybe`

and `either`

. In the source code of Data.Bool.Extra, the `bool`

function is clearly expressed as the data type's catamorphism:

```
bool = curry cata
```

Now, using the catamorphism as defined in *Recursion Schemes by Example*, it seems like the above-mentioned base library functions are all the catamorphisms of their data type, e.g. for Maybe:

```
-- base library definition
maybe n _ Nothing = n
maybe _ f (Just x) = f x
-- definition with cata
newtype Fix f = Fix {unFix :: f (Fix f)}
cata :: Functor f => (f a -> a) -> Fix f -> a
cata alg = alg . fmap (cata alg) . unFix
maybe n f m = cata alg where
alg Nothing = n
alg (Just x) = f x
```

However, Data.List.Extra's `list`

function is just mentioned in the comments as a "Non-recursive transform over a list, like 'maybe'", but as it is non-recursive in contrast to its data type, it apparently is not any recursion scheme of list either, or is it? Is that why it's not defined in the base library? Does the function have any other nice theoretical properties?

Solution

The catamorphism for `[]`

is `foldr`

.

The `list`

function from the `extra`

package is a conversion to Scott encoding, in the way that a catamorphism is a conversion to Church encoding. Since Scott encodings are non-recursive, they can't really correspond to any recursion scheme.

- Comparing lists in Haskell
- Is there a non-identity monad morphism M ~> M that is monadically natural in M?
- Problem with loading module ‘Distribution.Simple’
- Improving efficiency in Stirling numbers calculation
- Does sequencing an infinite list of IO actions by definition result in a never-ending action? Or is there a way to bail out?
- How to call pgQuery from postgresql-query?
- How to avoid whitespace after a tag (link) in Hamlet templates?
- Understanding type-directed resolution in Haskell with existential types
- Why is seq bad?
- Understanding bind function in Haskell
- How to create route that will trigger on any path in Servant?
- How do I use a global state in WAI middleware?
- nixos 23.11 cabal install mysql-simple problem - "Missing (or bad) C libraries"
- Is there a way to kill all forked threads in a GHCi session without restarting it?
- Why can an invalid list expression such as 2:1 be assigned to a variable, but not printed?
- Iterate over a type level list and call a function based on each type in the list
- How does this solution of Project Euler Problem 27 in the Haskell Wiki work?
- Why `Monad` is required to use `pure`?
- Can't do partial function definitions in GHCi
- recommended way to convert Double -> Float in Haskell
- Haskell profiling understanding cost centre summary for anonymous lambda
- Why is Haskell fully declarative?
- GHC Generating Redundant Core Operations
- Question about Event firing in reflex-frp
- Using Haskell's "Maybe", type declarations
- How can I elegantly invert a Map's keys and values?
- Why there is no output for wrapped IO in Haskell?
- What are the definitions of Weather and Memory in xmobar repo?
- Serializing a Data.Text value to a ByteString without unnecessary \NUL bytes
- Using Haskell with VS Code