简体   繁体   中英

Mapping Java Array to Frege

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM