sharkdp / purescript-flare

A special-purpose UI library for Purescript
286 stars 17 forks source link

Why UI is not an instance of Monad? #37

Open nilp0inter opened 3 years ago

nilp0inter commented 3 years ago

I am new to PS, so please forgive me if I am asking a silly question.

Given that UI is already an instance of Functor with a candidate implementation for bind, namely innerFlare. Why UI is not a Monad instance?

rintcius commented 3 years ago

I looked at that a while ago. If I remember correctly it kept adding elements instead of keeping the elements constant. The rendered output still looked ok though since the outdated elements were hidden and the current ones visible.

I may be missing something but it seems to me that once the outdated elements and the current one are merged then you'd have a proper Monad instance.

sharkdp commented 3 years ago

See also: https://github.com/sharkdp/purescript-flare/pull/27#issue-143866131

nilp0inter commented 3 years ago

So, if I understood it correctly. Although innerFlare is a candidate for bind and the generated code works, it is not performant. And the best route for UI to have a monadic interface would be to write a version of bind that results in cleaner code.

Am I right?

sharkdp commented 3 years ago

I have to admit that it has been to long since I worked with this code. I can not answer your questions without taking a deeper look myself. Maybe @rintcius can help?

rintcius commented 3 years ago

I also can't remember much more than what I wrote above. Maybe it's possible to solve this with just a new bind implementation, but maybe some things in the javascript code part needs to be changed too (I remember I was looking at the latter).

You can easily see the problem using innerFlare though, by just adding the monad instance, writing a little example and watch what happens with the DOM.