What is the easiest way to pass a list of integers from java to frege function?

Suppose I have a Frege module

module Util where

total :: [Int] -> Int
total xs = fold (+) 0 xs

If "total" was written in Java, I could call through

Util.total(Arrays.asList(1,2,3));

What is the best way to call a Frege implementation from Java?

+1
source share
1 answer

You can use the good old array int [], the corresponding frege type will be JArray Int. Since arrays can be created from lists in both Java and frege, they are good for such tasks.

Please use repl to get an idea of ​​how to convert an array to a list so you can pass it to your function.

rgd. , ArrayIterator Data.Iterators, ListView. , , ListView

total xs = fold (+) 0 xs.toList

java -

ArrayIterator.from (... code to create array here ...)

frege ,

(ArrayIterator.from (... code to create array here ...)).toList

, : foldArray.

+2

Source: https://habr.com/ru/post/1620965/


All Articles