Needless to say, the standard construction in Haskell
newtype Fix f = Fix { getFix :: f (Fix f) }
cata :: (Functor f) => (f a -> a) -> Fix f -> a
cata f = f . fmap (cata f) . getFix
is awesome and extremely useful.
Trying to define a similar thing in Agda (I'll put it just for completeness sake)
data Fix (f : Set -> Set) : Set where
mkFix : f (Fix f) -> Fix f
fails because f
is not necessarily strictly positive. This makes sense -- I could easily get a contradiction from this construction by picking appropriately.
My question is: is there any hope of encoding recursion schemes in Agda? Has it been done? What would be required?