1

Lets say I'd like to map the Java code:

package mypackage;

class A {
    public String[] values() {
       return new String[]{"one", "two"};
    }
}

To its Frege counterpart:

data AA = pure native mypackage.A where
    native values :: AA -> [String]

At the moment Frege complains with:

error: incompatible types: String[] cannot be converted to TList

How can I map a Java array to Frege ?

Ingo
  • 36,037
  • 5
  • 53
  • 100
Janus Lynd
  • 209
  • 1
  • 8
  • 4
    Not only Frege complains—the Java code is invalid as well. Ironically for the same reason. Arrays and Lists are different types… – Holger Oct 29 '15 at 23:15
  • My mistake. I didn't copy/paste. I really meant an array. Thanks Ingo for fixing the example :) – Janus Lynd Oct 30 '15 at 07:09

1 Answers1

3

The message is actually from the Java compiler.

The Frege type that corresponds to a Java array

Foo[]

is

JArray Bar

where Bar is the Frege type that corresponds to Foo.

So, in your case it should be

JArray String

Note that this is an immutable array from the Frege point of view. If you want a mutable array, use

Mutable s (JArray String)

but, of course, it can only be used in the ST monad.

Here is the link to the relevant online doc: http://www.frege-lang.org/doc/frege/prelude/PreludeArrays.html Because this is part of Prelude, you don't need to import anything to use it.

Ingo
  • 36,037
  • 5
  • 53
  • 100