Skip to content

Instantly share code, notes, and snippets.

@LSLeary
Last active May 23, 2022 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LSLeary/f6ab06b3a7b0a78104f385c5b8f540ae to your computer and use it in GitHub Desktop.
Save LSLeary/f6ab06b3a7b0a78104f385c5b8f540ae to your computer and use it in GitHub Desktop.
{-# LANGUAGE PolyKinds, RankNTypes, TypeOperators #-}
module IFix where
newtype IFix f t = IFix (f (IFix f) t)
type f ~> g = forall x. f x -> g x
class NFunctor f where
nmap :: g ~> h -> f g ~> f h
cata :: NFunctor f => f g ~> g -> IFix f ~> g
cata alg (IFix f) = alg (nmap (cata alg) f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment