Adding Fixed Point Data Types to base

Andrew Martin andrew.thaddeus at
Sun Oct 16 14:21:44 UTC 2016

I would like to propose export Fix, Free, and Cofree from a new module
in base (maybe something like Data.Functor.Recursion, the name is
unimportant). The definitions of Free and Cofree would be as there are
in the `free` package in Control.Monad.Free and Control.Monad.Cofree.
The `free` package would then reexport these types in their respective
modules rather than redefining them. All of the other utilities
functions from these packages would not be moved to `base`; they would
remain in `free`. Fix would be defined as:

    newtype Fix f = Fix { unFix :: f (Fix f) }

The advantage this offers is that Free and Cofree would be able to
enjoy a greater number of typeclass instances provided libraries
across the ecosystem. As it stands, adding the somewhat heavy `free`
dependency is not a good choice for libraries like `aeson`,
`mustache`, and `hashable`. In the case of Fix, the ecosystem
currently lacks a canonical library that provides it
(recursion-schemes and data-fix both offer the same definition though,
and various tutorials all define it the same way). It could benefit
from the new instances as well.

The disadvantage is the usual disadvantage: Adding any data type to
base is a future commitment to that data type, and compile times for
base go up a little, and there is work to be done to move it into base
to begin with.

I would gladly help with any of the work that needs to be done to make
this happen. I believe that Fix and Free (and Cofree to a lesser
extent) have proved themselves over years of use in the ecosystem. I
would appreciate any feedback or thoughts that others have on this
topic. Thanks.

-Andrew Thaddeus Martin

More information about the Libraries mailing list