How to map Java overloaded constructors to Frege functions -
java (unfortunately) supports constructors , methods overload. example, hashmap has 4 constructors. in frege can't do:
data map = native java.util.map data hashmap = native java.util.hashmap native new :: () -> stmutable s hashmap native new :: int -> stmutable s hashmap native new :: int -> float -> stmutable s hashmap native new :: mutable s map -> stmutable s hashmap
this doesn't compile because can't bind 4 times "new". possible have 4 "java constructors" in frege datatype?
overloaded constructors , methods can defined using |
:
data hashmap k v = native java.util.hashmap native new :: mutable s (map k v) -> stmutable s (hashmap k v) | () -> stmutable s (hashmap k v) | int -> stmutable s (hashmap k v) | int -> float -> stmutable s (hashmap k v)
you can use https://github.com/frege/native-gen starting point generate frege code java class. above code generated using project.
i said starting point because cannot automated. can't determine purity of method , nulls native methods. hence can take generated code , modify purity or make return type maybe a
if know method may return null
.
Comments
Post a Comment