Created
March 31, 2013 06:24
-
-
Save mmhelloworld/5279754 to your computer and use it in GitHub Desktop.
Test Frege-Java interop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package javacallingfrege; | |
| import frege.prelude.PreludeBase.TList; | |
| import frege.prelude.PreludeText; | |
| import fregeforjava.Foo; | |
| public class Main { | |
| public static void main(final String[] args) { | |
| // Get the instance of D1 for class 'A' | |
| final Foo.CA aInst = Foo.IA_D1.it; | |
| // invoke data constructor to create a D1 | |
| final Foo.TD1 d1 = Foo.TD1.mk("Hello", 6); | |
| // Call f1 | |
| final boolean f1Res = (Boolean) aInst.ƒf1().apply(d1).result().call(); | |
| // Call f2 | |
| final TList f2Res = (TList) aInst.ƒf2().apply(d1).apply(3).result() | |
| .call(); | |
| System.out.println("f1: " + f1Res); | |
| // Get the show instance for D1 | |
| final Foo.IShow_D1 d1ShowInst = Foo.IShow_D1.it; | |
| // invoke the 'List' show instance along with passing the element's show | |
| // instance too; in this case, elements are of our type D1 so passing | |
| // our D1 show instance | |
| final String showF2Res = PreludeText.IShow__lbrack_rbrack.show( | |
| d1ShowInst, f2Res); | |
| System.out.println("f2: " + showF2Res); | |
| final Foo.TD1 functRes = (Foo.TD1) Foo.funct(true, d1, d1); | |
| // Again invoke show to display the function result | |
| System.out.println("funct: " + Foo.IShow_D1.show(functRes)); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment