When defining complex functions in pointfree style, I often find myself switching to pointful style. Sometimes, I even convert to ANF and annotate the types to understand the steps.
After completing the function definition, I often convert back to pointfree style for conciseness. End of the story: To understand it again a couple of weeks later, I start expanding to annotated pointful again.
The small 10-lines library at the end of this post allows to define pointfree functions with intermediate type annotations.
Credits: Agda and EqReasoning for syntactical inspiration.
basically this is just syntactic sugar for the (almost equally verbose / concise):
The latter only uses functions from the Scala Predef and thus requires no “library”. Still, I have never encountered this style of writing annotated pointfree programs in the wild.
You can safely ignore the details of this example, it is just to show the syntax.
Compare with the type-annotated (almost ANF) pointful version:
And the (almost) pointfree “one-liner”:
In particular, notice how we need to introduce the auxiliary definition trans and refrain from fully using pointfree style in order to assist type inference.
Note: This post is automatically generated from a github gist. You may want to checkout the original sources and consider commenting there.