safareli ยท GitHub

@safareli

Copy link Copy Markdown

Contributor

TODO

  • add more tests
  • add benchmarks
  • add comments to code

@safareli

Copy link Copy Markdown

Contributor Author

I got this idea just today and couldn't hold to build and open PR ๐Ÿ—ก

It's sort of composition of work done in Eff http://github.com/purescript/purescript-eff/pull/31 and the post I wrote a while ago about Stack safe Function composition.

/cc @natefaubion @paf31

It's worth noting that whenever it's known that composition is happening for function type, compiler is doing optimization so this FFI function will not be called at all, that's why I use Semigroupoid constraint in test to force use of the FFI function.

@safareli

@safareli

@paf31

Copy link Copy Markdown

Contributor

Sorry, but in my opinion this is totally unsuitable for Prelude. As I said on the eff PR, I think it's interesting, and a worthwhile addition in the form of a separate library, but it's just not the right sort of approach for the core libraries.

@hdgarrood

Copy link Copy Markdown

Contributor

I'm with @paf31 on this, I think, especially since this only seems to have an effect in rare cases (I don't remember the last time I wrote a function with a Semigroupoid constraint). This approach seems risky to me from a maintenance perspective too; I imagine it might be quite easy to accidentally break this in the future if this code path is only rarely being hit.

@safareli

Copy link Copy Markdown

Contributor Author

Fair points ๐Ÿ™Œ

@safareli

@matthewleon

Copy link Copy Markdown

Contributor

@safareli did you end up doing anything with this in terms of making a separate lib? I think there could be some really handy uses.

@paf31

Copy link Copy Markdown

Contributor

I don't think this will work for Builder.

@safareli

Copy link Copy Markdown

Contributor Author

Nope, how you think this could be used as separate lib?

@matthewleon

Copy link Copy Markdown

Contributor

@matthewleon

Copy link Copy Markdown

Contributor

I don't think this will work for Builder.

Builder as it exists now, no... But if someone wrote a separate stack safe Builder lib which used this under the hood, shouldn't that work out?

@safareli

Copy link Copy Markdown

Contributor Author

Did you get the stack overflow by using Builder?

@matthewleon

Copy link Copy Markdown

Contributor

Yes, if you compose enough Builders you will get a stack overflow. The Category instance is just newtype derived from Function.

@matthewleon

Copy link Copy Markdown

Contributor

(or rather, the Semigroupoid instance)

@safareli

Copy link Copy Markdown

Contributor Author

Sure, it's less likely to happen, so was curious if you had practical case where it happened.
I will try to create a lib then

@matthewleon

Copy link Copy Markdown

Contributor

Don't worry too much about it, as I have another solution for my situation. I just think this particular solution is quite interesting, and probably could be applied in other situations, too.

@safareli

Copy link Copy Markdown

Contributor Author

Read the original on github.com โ†—