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 for coroutines? #11

Open
Sintrastes opened this issue Oct 3, 2021 · 6 comments
Open

Support for coroutines? #11

Sintrastes opened this issue Oct 3, 2021 · 6 comments

Comments

@Sintrastes
Copy link

Hello! First off, I'd just like to say: Thank you for this great project. As someone who loves Kotlin, but also occasionally wants to do some pure-script style things on Android, this is great!

I was just wondering: Are there any plans to support a representation of Kotlin-specific types like suspend functions on the pure-script side? I suppose this could be something like a AsyncEff or SuspendEff function on the purescript side that gets converted into a suspend fun in the backend.

@csicar
Copy link
Owner

csicar commented Oct 3, 2021

Thank you :)

Yes there are. I had even started implementing something like this. I wanted to map Aff in ps to coroutines in kotlin, but I got stuck at implementing a runtime for Aff.

@csicar
Copy link
Owner

csicar commented Oct 3, 2021

My attempts at implementing Aff using coroutines can be found here: https://github.com/csicar/pskt-foreigns/tree/coroutines

ATM I'm not looking at trying again, but I'd be happy to get PRs for it ;)

@Sintrastes
Copy link
Author

@csicar Am I understanding correctly by a runtime for Aff essentially you're just interpreting all of the "base" functions in Aff as suspend funs in Kotlin (or, actually I see in your code base it looks like you're using (A) -> Deffered<B> -- but as I understand it, that's an isomorphic representation with the semantics of Kotlin).

If so, what are the current open problems with this approach? No guarantees in terms of when I'd actually have the time to dig into it -- but I'd be happy to contribute time permitting.

@Sintrastes
Copy link
Author

As a somewhat related question: Have you thought at all about supporting interop with @Composable functions? I'm not sure exactly what the best approach there would be, or how that would look, but it'd be killer to use something like Halogen for organizing components with a compose backend to handle the actual tree diffs/rendering.

@csicar
Copy link
Owner

csicar commented Oct 14, 2021

Sorry for the late response.

Am I understanding correctly by a runtime for Aff essentially you're just interpreting all of the "base" functions in Aff as suspend funs in Kotlin

Yes, that's right.

If so, what are the current open problems with this approach?

I'm not sure there are any. The problem is just, that a understand neither Aff nor Coroutines well enough to be sure that their behaviour matches. I never really worked with Affs Fiber, so I didn't fully understand the semantics, which made it hard to implement the ffi.

If you'd like to have a try at implementing Aff for pskt, I'd suggest looking at the https://github.com/csicar/pskt-foreigns/edit/coroutines/Foreign.Effect.Aff.kt file and try to fill in the TODO()s. If you need help setting up a dev environment for working on that stuff, I'd be happy to help.

actually I see in your code base it looks like you're using (A) -> Deffered<B>

Yes, I think suspend fun and (A) -> Deferred<B> should be equivalent in Kotlin. I used the second form, because that didn't require modifying the pskt compiler ;)

@csicar
Copy link
Owner

csicar commented Oct 14, 2021

Have you thought at all about supporting interop with @composable functions?

Yes, very much. AFAIK Jetpack Compose unfortunately does not use a vdom, but instead does compile-time analysis of your code to insert update to the ui calls at the appropriate places. That could prove challenging to implement in the FFI.

There is also an early attempt at implementing a vdom for normal android widgets, which can be found here: https://github.com/csicar/purescript-android-todomvc/blob/master/ps/src/Main.purs

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

2 participants