Continuing the discussion from Reactimate - A new AFRP library - #14 by turion
I believe the right terminology is “terminal” and “initial” (see this stackoverflow answer). The current MSF
type is a direct fixed point (a la Fix):
data FixMSF m a b = FixMSF (a -> m (b, FixMSF m a b))
It could indeed be faster to write it as a greatest fixed point of a terminal coalgebra (a la Nu):
data NuMSF m a b = forall c. NuMSF (c -> a -> m (b, c)) c
You could also instead take the least fixed point of an initial algebra (a la Mu):
data MuMSF m a b = MuMSF (forall c. ((a -> m (b, c)) -> c) -> c)
In all of these types you might be able to recognize a common base functor:
data MSFBase m a b f = MSFBase (a -> m (b, f))
Both the Nu
and the Mu
encodings should get you automatic fusion if all goes well and GHC is smart enough. If you’re doing a lot of zip-like functions then you probably do want the Nu
representation (which is also what the work on stream fusion uses). Whereas the fuision that is now in base (foldr/build) uses the Mu
representation.