tcr / corollary

Cross-compiler from Haskell to Rust, plus parser-haskell.
74 stars 6 forks source link

Use ghc-mod for inferring function types #28

Open tcr opened 7 years ago

tcr commented 7 years ago

When parsing happy and alex outputted code, that is the generated Lexer and Parser code in gen/, we can see that a large number of functions have inferred type definitions, not explicit ones. The compiler currently turns these into Rust lambdas.

We could do some tricks to infer these types in the compiler, or hope Rust can handle the inference, but I think an easier win is to hook up the compilation stage to ghc-mod (if available), read out the types signatures of these functions, and use them to generate the resulting conversion.

Because the setup is more complex for ghc-mod and only is specifically used in function definitions, this should just be optional (if it fails to run ghc-mod or ghc-mod throws an error, it gets swallowed) so that it doesn't slow down development.

tcr commented 7 years ago

After assessing the code needed for Corrode, this actually would only benefit Lexer.hs and Parser.hs, which probably would be simple to whitelist. So I'm not going to work on this for now.