Writing Functions
Defining functions in Haskell may look strange, because of how lightweight the syntax is compared to other languages. In fact, the syntax for defining functions and variables in Haskell looks almost identical.
To define a new named function, give the function a name along with names for each of the parameters that you want to accept. To look at a concrete example, let’s rewrite our greeting program from earlier so that we can take a variable greeting and person to greet.
We’ll start by creating a new function, makeGreeting, that takes two arguments, salutation and person. We’ll use the <> operator to concatenate the two strings and add a space between them. The return value of the function is the concatenated string. Create ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access