conal / reification-rules

GHC Core reification via rules
Other
6 stars 1 forks source link

Automatically generate instances for record types or arbitrary ADTs. #4

Open TikhonJelvis opened 8 years ago

TikhonJelvis commented 8 years ago

Since we support pairs, we ought to support arbitrary product types including records. Having custom records leads to much better code than tuples.

This can probably be done with Template Haskell or some sort of generic programming library. (I don't have direct experience with either approach, so I'm not sure what's easier.)

conal commented 8 years ago

Thanks for the reqeuest.

Yes, of course I wouldn't want people to write in terms of tuples. Or any other unpleasant coding compromises to help the compiler. Currently, it's fairly easy to write custom HasRep instances, and I agree that automating those instances would be preferable, say via Template Haskell or having the compiler synthesize them on the fly. And not just records but all regular (non-nested) algebraic data types.

TikhonJelvis commented 8 years ago

Would it be possible to somehow hang on to the field names for debugging/visualization purposes? (This only makes sense for records, not other types.)

conal commented 8 years ago

I bet it would be possible indeed. Since I'm running inside GHC, I have access to all kinds of compile-time information. I really appreciate these suggestions!

TikhonJelvis commented 8 years ago

Long-term, it would be cool to work towards something like "Self-explaining computations". That feels like something this representation is rather well-suited for.

conal commented 8 years ago

Fun idea! There's no end of wonderful things we can do!

TikhonJelvis commented 8 years ago

By the way, I can try implementing this myself and sending you a pull request. It might take a little while because I'm not familiar with your existing code or the Template Haskell/Generics facilities though.

conal commented 8 years ago

Please do. Let me know if you'd like some pointers along the way.

conal commented 8 years ago

Oops. I had forgotten that I'd much rather generate HasRep dictionaries automatically during compilation. Otherwise, we'll have to create a bunch of HasRep instances in the library, even if fully defaulted. That list would be big, pulling in lots of dependencies, and still not complete. Currently, I have a random assortment of instances for various single-constructor types, generated by a macro.

conal commented 8 years ago

@TikhonJelvis I'd still love to see what you did with generics for HasRep. If it's what I think, it'd be an improvement over my current implementation, and it may take a while to move dictionary synthesis into the compiler.

TikhonJelvis commented 8 years ago

Okay. I'll clean it up a bit and give you a pull request.