Advertisement
ptrelford

Minimal F# to Java compiler

Dec 15th, 2013
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.42 KB | None | 0 0
  1. open Microsoft.FSharp.Quotations.DerivedPatterns
  2.  
  3. let rec toJava = function
  4.    | Int32 x -> sprintf "%d" x
  5.    | SpecificCall <@@ (+) @@> (None, _, [lhs;rhs]) -> sprintf "(%s+%s)" (toJava lhs) (toJava rhs)
  6.    | _ -> failwith "Not supported"
  7.  
  8. let toClass expr =
  9.     sprintf """
  10. public class Generated {
  11.   public static void main(String []args){
  12.      System.out.println(%s);
  13.   }
  14. }""" (toJava expr)
  15.  
  16. toClass <@ 1 + 1 @>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement