haskellrecursionoptimizationfixpoint-combinatorscatamorphism# Can one express catamorphism through Data.Function.fix?

I have this lovely `fixana`

function here that performs about 5 times faster than her sister `ana`

. *(i have a criterion report to back me on this)*

```
ana alg = Fix . fmap (ana alg) . alg
fixana alg = fix $ \f -> Fix . fmap f . alg
```

Can I express their cousin `cata`

in the same fashion?

```
cata f = f . fmap (cata f) . unFix
```

It seems to me that I cannot, but I have been humbled by my S.O. fellows quite a few times in the past.

Solution

Actually, this has nothing to do with catamorphisms.

Whenever a function is defined as

```
f = (... f ...) -- some expression involving f
```

one can rewrite it using `fix`

as

```
f = fix $ \g -> (... g ...)
```

In the posted code we have a slight variant

```
f x = (... (f x) ...)
```

We can regard the above as `f`

being defined recursively. However, it's simpler if we regard `f x`

(rather than `f`

) being defined recursively.

```
f x = fix $ \g -> (... g ...)
```

This should be more efficient than the plain translation

```
f = fix $ \g x -> (... (g x) ...)
```

since we don't need to call `g`

over and over again with the same argument `x`

.

- Why do I get "Unexpected reply type" from notify-send when using this Haskell notification server?
- Haskell fails to infer the return type of a monad after using the sequence operator
- Don't understand notation of morphisms in Monoid definition
- Foldln in haskell
- Is this property of a functor stronger than a monad?
- How to Instantiate a Custom Data Type with Record Syntax and Multiple Constructors
- How do I make a minimal working example for the a DBus server?
- Is it safe to downgrade Haskell stack version?
- Haskell, list of natural number
- unfamiliar syntax in Haskell / Clash function type signature
- foldM with monad State does not type check
- Why does my Runge-Kutta implementation oscillate to 0?
- How do I get the desired behavior in my TCP server?
- Why does the Haskell PVP describe new functions as non-breaking?
- How do I correctly use toLower in Haskell?
- Every Lens' is a Traversal'... how?
- How do I crate a value of type a{sv} for a call to org.freedesktop.Notifications.Notify via DBus?
- Web Scraping With Haskell
- Double exclamation marks in Haskell
- Haskell Servant POST FormUrlEncoded for (Vector String) field
- Confusion about list types in Haskell
- Idiomatic way to define new vs persisted types in Haskell
- Why does Cabal, unlike GHC, not automatically enable GeneralizedNewtypeDeriving if I explicitly enabled DerivingStrategies?
- What is the proper way of wrapping an Int (not a general type) in another type if type safety is the only motive?
- Parsing inside `between` with Megaparsec
- takeWhile implementation in JavaScript - Looking for better ideas
- How to setup MINGW environment variables for Haskell language server in vscode?
- mysql-haskell no invoke of Right case of try function
- Run cleanup function in multiple Haskell child threads when POSIX Signal sent (SIGTERM etc)
- Gloss animations jerky and hope to add `-O2` to GHCi