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 ...
Get Effective Haskell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.