Frege / frege

Frege is a Haskell for the JVM. It brings purely functional programing to the Java platform.
https://github.com/Frege/frege/wiki/_pages
Other
3.64k stars 145 forks source link

Native function cannot return non-exceptional IO (Either) #41

Closed mmhelloworld closed 11 years ago

mmhelloworld commented 11 years ago

Given a Java class:

import frege.prelude.PreludeBase.TEither;

public class Bar {
  public static TEither bar(final String s) {
    return TEither.DRight.mk(0);
  }
}

The Frege module below fails compilation with "String is not a valid exception":

module Foo where

native bar Bar.bar :: String -> IO (Either String Int)
Ingo60 commented 11 years ago

True, this was never meant to work. But I think we could make it work if needs be. In the mean time you can do:

data MyEither a b = Myeither { un :: Either a b}
native bar Bar.bar :: String -> IO (MyEither String Int)

do
    n <- bar "frob"
    either theLeft theRight n.un

The java code needs no change.

mmhelloworld commented 11 years ago

That would do for now. Thanks!

Ingo60 commented 11 years ago

I suggest we leave it at that for now. Interaction with java methods that return frege types should be rare enough to deal with it using a "newtype".