Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support type parameters #151

Open
facundominguez opened this issue Jul 17, 2020 · 0 comments
Open

Support type parameters #151

facundominguez opened this issue Jul 17, 2020 · 0 comments

Comments

@facundominguez
Copy link
Member

facundominguez commented Jul 17, 2020

Is your feature request related to a problem? Please describe.

It is difficult to use quasiquotations that are type safe and can be reused with different types.

f :: (IsReferenceType a, Coercible a) => a -> IO a
f obj = [java| $obj |]

The above code is rejected because at compile time, inline-java doesn't know which Java type to give to $obj.
We can do casts instead:

f :: (IsReferenceType a, Coercible a) => a -> IO a
f (coerce -> JObject obj) = unsafeUncoerce . JObject <$> [java| $obj |]

which can fail at runtime if the user gets the types wrong.

Describe the solution you'd like

Ideally, we would have in Java code like

public <A> A f (A $obj) { return $obj; }

and our initial definition would be accepted

f :: (IsReferenceType a, Coercible a) => a -> IO a
f obj = [java| $obj |]

The code generated by inline-java would be responsible for making the appropriate casts.

There is some room to decide where type variables are allowed in a type. Here's an example where the type variable appears nested within a type.

f :: (IsReferenceType a, Coercible a) => a -> IO (J ('Iface "java.util.List" <> '[ Ty a ]))
f _ = [java| new ArrayList<A>() |]

And we also would have to consider if/how to deal with bounded type parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant