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.
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.
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.
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.
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?
Contributor
Yes, if you compose enough Builders you will get a stack overflow. The Category instance is just newtype derived from Function.
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
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.