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

Implement reactive polymorphism. #8

Open
Sintrastes opened this issue May 25, 2022 · 5 comments
Open

Implement reactive polymorphism. #8

Sintrastes opened this issue May 25, 2022 · 5 comments

Comments

@Sintrastes
Copy link
Owner

No description provided.

@Sintrastes
Copy link
Owner Author

Really this could be more generally any kind of "functorial" polymorphism.

@Sintrastes
Copy link
Owner Author

One question I have about this is: When would this be applicable?

Does this also apply to IO (and any other monad/functor), or would it only be for specified cases?

@Sintrastes
Copy link
Owner Author

It might make sense to use a special syntax for this. e.x. printLn !readLn makes it clear that we're saying "Print the result of readLn, rather than printLn readLn` ("Print the readLn function itself"), which doesn't make a whole lot of sense and should probably crash.

Thus, this might be a slightly different syntax, but essentially the same idea as idiom brackets from Idris.

It would also work pretty similarly to how .bind() works in arrow-kt.

@Sintrastes
Copy link
Owner Author

Sintrastes commented Feb 5, 2023

We may be able to make the $ sigil for string templates do the double-duty of also !-binding any monadic results, but that may be problematic, as there are examples such as the list monad where we may want to actually display the list (rather than binding the list).

So we may require something like "The count is $!count" for binding reactive state.

@Sintrastes
Copy link
Owner Author

Sintrastes commented Feb 5, 2023

Maybe to deal with ambiguities, we could also borrow a page from arrow-kt, and introduce a context with something like:

[monad-name] { block where ! can be used to bind }

So in the reactive UI example, this might look something like:

UI = Column {
    count <- state 0
    
    btn <- Button "Click me!"
    
    when btn.clicked {
        count := count + 1
    }
    
    Text $ State { "You clicked me $count times!" }
}

So maybe not as nice as I originally imagined for this, but I think this is less ambigious, and still less clunky than explicit binds/maps. This would also be more similar to idiom notation, as we have explicit blocks.

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