I have several ideas of extensions for Haskell, that can be implemented by translating extended language to normal one (the extensions will provide some pragmas and keywords). What is the better way to implement them? It should be build over GHC.
One of ideas is to add keyword for "functional classes", the classes, that will be automatically defined by functions. For example, with this hypothetical extension, standard Num class can be defined like this:
class (funclass(+) a,funclass(-) a, ...) => Num a
As I see it, there are three ways you might do this:
Implement a preprocessor which reads extended Haskell source code, translates it into normal Haskell, and saves that back to disk. You can then compile the translated Haskell code as normal.
Implement some code with Template Haskell that will do the translation for you. (In particular, some kind of quasi-quoter may be appropriate.)
Modify GHC itself. (This obviously requires recompiling GHC, and then checking you haven't accidentally broken any existing functionality.) I would suggest that this is probably a hell of a lot of work.
I was about to mention that you could write a GHC plugin - however, such plugins do not allow you to define new syntax. (Though they do allow you to define new compiler pragmas, which would then be translated into normal Haskell.) If you can get this approach to work, it means you get to avoid recompiling GHC. You would just be writing a small, self-contained plugin. But Template Haskell will probably do the job more easily.
As to whether your proposed extension is a good idea... I don't think it is, but you are of course welcome to experiment with using it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With