Answer the question
In order to leave comments, you need to log in
How to understand how this function works in Haskell?
I'm watching a tutorial video on haskell: https://www.youtube.com/watch?v=43zCXDb5dQ4&t=1954s
There, at 33:02 minutes, it talks about the sumFstFst function, which takes several more functions as arguments, including the on, + , helper.
The function sumFstFst has no names of arguments in the declaration, after the name immediately comes the same and "instructions" what to do.
However, when SumFstSft p1 p2 is called, somehow the compiler understands that it must first apply helper to p1, then apply helper to p2, and pass the results to on along with the + function.
I can’t understand how this happens, on what basis the helper function is called 2 times and how it understands what needs to be processed, but we didn’t specify any arguments after sumFstFst was declared.
Explain, please.
Answer the question
In order to leave comments, you need to log in
Take a look at the on function
, it works like this takes a binary operator, then a function and two arguments to act
on on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
If the last argument occurs on the right also in the last place, then they can be omitted. This is called pointless style.
fun xyz = (...) z
and fun xy = (...)
are the same.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question