Gabriella439 / pipes

Compositional pipelines
BSD 3-Clause "New" or "Revised" License
488 stars 72 forks source link

Factor out boilerplate in composition/instance functions #164

Closed infinity0 closed 3 years ago

infinity0 commented 8 years ago

This makes the code easier to understand, since one can now more quickly ignore the boilerplate without inspecting it "in case" it might be different. It also makes the instance functions less dependent on some internal details of Proxy.

I marked all of the functions as INLINABLE so there should be no runtime cost. (INLINE may be better, but I'm not familiar with Haskell internals to be able to judge this by myself.)

Ideally we would write fixm,fixl,fixr as one function, but I couldn't figure out how to satisfy the type checker in this way.

infinity0 commented 8 years ago

I just ran cabal bench and there's no noticeable difference with or without this patch - some results are a little bit slower, some are a little bit quicker.

Gabriella439 commented 8 years ago

The main reason that I'm reluctant to merge this is that the proofs in laws.md (Link) are written in terms of the old implementation and I've have to update them all accordingly. Also, the fact that fix{l,r,m} are partial functions makes me uneasy, too.

infinity0 commented 8 years ago

Understood, I'll see if I can apply this factoring to the laws when I next get some time.

fix{l,r,m} each would only be partial functions if go directly calls into it at any of the points that it directly calls into go. It should be easy for a given piece of code to avoid this though - probably easier than trying to prove laws about it, at any rate. (Ideally we'd have one unconditionally total function fix, but it's unclear that I can get Haskell to type-check this in the way that's needed.)