The words
function in Haskell is a built-in function that takes a String
and separates it by whitespace characters.
words :: String -> [String]
The words
function takes a String
input as a parameter.
The words
function returns a list of type [String]
. Each element in the list is a String
.
Let’s look at the code below:
wordsList = "One\nTwo\tThree Four Five"w = words wordsListmain = print w
In the above code, we provide a String
where words are separated by tabs
, spaces
, and newline
characters.
The words
function returns each word as a list and removes the whitespaces between them.