Skyb0rg007 / recursion-schemes-ix

Recursion schemes over indexed Functors
https://skyb0rg007.github.io/recursion-schemes-ix/
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Deriving indexed functor #1

Open dylan-thinnes opened 3 years ago

dylan-thinnes commented 3 years ago

Hello!

This is a great library! I've been using it a little bit for my own ASTs - really cool, and definitely easier to use than multirec.

I've been unifying the constructors for my mutually-recursive data types under a single GADT, for example with a super-simplified AST:

data Exp = App Exp Exp | Abs Pat Exp | Var String
data Pat = Wildcard | Var String | ConP String [Pat]

-- becomes...
data Index = ExpI | PatI
data MF (f :: Index -> *) (ix :: Index) where
    AppMF :: f ExpI -> f ExpI -> MF f ExpI
    AbsMF :: f PatI -> f ExpI -> MF f ExpI
    ...
    ConPMF :: String -> [f PatI] -> MF f PatI

Obviously, this is pretty time consuming to write for any reasonably large AST, so I've written a small templatehaskell snippet that takes a simple mutually recursive datatype and produces the GADT for it.

So, a few questions:

I only use template-haskell, so that shouldn't bloat your deps - however, TemplateHaskell being a moving target could be a maintenance burden you don't want. If that's the case, I'm willing to just put this stuff in a different library, though I still think it would be worth it to link people back to it from the README here.

Skyb0rg007 commented 3 years ago

That would be great! Go ahead and submit a pull request and I can merge it.

dylan-thinnes commented 3 years ago

Hey, I'm not sure if you've seen the PR I've made - it's as of yet still needing some work on deriveITraversable and general code-cleaning, but your feedback would be valuable!