[Haskell-cafe] What is your favourite Haskell "aha" moment?
jo at durchholz.org
Thu Jul 12 06:01:19 UTC 2018
Am 11.07.2018 um 14:10 schrieb Simon Peyton Jones via Haskell-Cafe:
> Another thing that I think comes over easily is the ability to abstract:
> generalising sum and product to fold by abstracting out a functional
You can expound more on that: People don't have to write loops anymore
(with their fencepost issues etc.). It's like a "for" loop, but written
using in-language facilities instead of having to live with what the
language designer does.
This means you can roll your own loop constructs.
Consider iterating over the elements of a data structure such as List,
Tree, etc. Most languages offer an Iterable interface, which tends to be
somewhat messy to implement.
With a higher-order function, you can just write down the loop, *once*,
and the loop body will be provided by a function parameter, and voilà!
you have your loop construct.
More information about the Haskell-Cafe