Open TikhonJelvis opened 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.
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.)
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!
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.
Fun idea! There's no end of wonderful things we can do!
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.
Please do. Let me know if you'd like some pointers along the way.
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.
@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.
Okay. I'll clean it up a bit and give you a pull request.
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.)