I have a function in haskell on paper as an example:
function2 a b c = (a * b) + c
and I'm required to write the example in point free notation. I'm really bad at working with point free style as I find it really confusing with no proper guide through it so i gave it a try:
function2 a b c = (a * b) + c
function2 a b c = ((*) a b) + c #operator sectioning
function2 a b c = (+) ((*) a b)c #operator sectioning once more
#I'm stuck here now
I wasnt sure what should come up next as that was the limit i could think of for this example. Would appreciate some help on this.
--Second example:
function3 a b = a `div` (g b)
function3 a b = `div` a (g b) --operator sectioning
function3 a b = (`div` a) (g b) --parentheses
function3 a b = ((`div` a g).)b --B combinator
function3 a = ((`div` a g).) --eta conversion
function3 a = ((.)(`div` a g)) --operator sectioning
function3 a = ((.)flip(`div` g a))
function3 a = ((.)flip(`div` g).a) --B combinator
function3 = ((.)flip(`div` g)) --eta conversion (complete)
You can apply the B combinator (i.e.
(f . g) x = f (g x)
) there:Indeed the types are the same:
We work by extricating the arguments one by one in the correct order, to end up with
so that the eta-contraction can be applied to get rid of the explicit arguments,
Our tools in this, which we get to apply in both directions, are
There's also
(f =<< g) x = f (g x) x = join (f . g) x
.Some more, useful patterns that emerge when we work with pointfree for a while are:
(update.) There's an error near the start in your second example, invalidating all the following steps after it:
So yeah, some of the steps were in the right direction.