Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

haskell
words
communitycreator

What is the words function in Haskell?

Muhammad Ashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The words function in Haskell is a built-in function that takes a String and separates it by whitespace characters.

Syntax

words :: String -> [String]

Parameters

The words function takes a String input as a parameter.

Return value

The words function returns a list of type [String]. Each element in the list is a String.

Code

Let’s look at the code below:

wordsList = "One\nTwo\tThree Four Five"
w = words wordsList
main = print w
Separating a string

Explanation

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.

RELATED TAGS

haskell
words
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring