-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add a Java monad like in Eta #66
Comments
Please note that Idris has a stronger and richer type system than Eta, and that possible alternatives (for example, implementing a Java context/resource type for ST) should also be considered. |
That is very much true... Hadn't thought of it until you wrote it. |
By the way, a limited version of the record Java a ret where
constructor MkJava
runJava : a -> JVM_IO ret
Functor (Java a) where
map f (MkJava action) = MkJava ((map f) . action)
Applicative (Java a) where
pure = MkJava . const . pure
(<*>) (MkJava action1) (MkJava action2) =
MkJava
(\a => (action1 a) <*> action2 a)
Monad (Java a) where
(>>=) (MkJava action) f =
MkJava
(\a => do
ret <- action a
let (MkJava action2) = f ret
action2 a
)
javaWith : a -> Java a ret -> JVM_IO ret
javaWith = flip runJava
io : JVM_IO ret -> Java a ret
io action = MkJava (const action)
withObject : a -> Java a ret -> Java b ret
withObject obj j =
io $ javaWith obj j See it in action: |
'convert' doesn't solve holes, so might reject things that are solvable. This can be an issue when resolving interfaces, because we were using convert for arguments of the invertible holes that arise when trying to resolve them. Fixes #66.
I really found the eta solution for object methods interesting, and thought that it would be nice to have a java monad like that in idris-jvm.
The text was updated successfully, but these errors were encountered: