purescript-flare icon indicating copy to clipboard operation
purescript-flare copied to clipboard

Why UI is not an instance of Monad?

Open nilp0inter opened this issue 3 years ago • 5 comments

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?

nilp0inter avatar Apr 26 '21 20:04 nilp0inter

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.

rintcius avatar Apr 26 '21 21:04 rintcius

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

sharkdp avatar Apr 27 '21 06:04 sharkdp

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?

nilp0inter avatar May 02 '21 17:05 nilp0inter

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?

sharkdp avatar May 09 '21 09:05 sharkdp

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.

rintcius avatar May 09 '21 19:05 rintcius