You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Lists are the fundamental data structure in functional programming. In Haskell, almost all data processing involves manipulating lists using recursion, pattern matching, and higher-order functions like map, filter, and fold.
A list in Haskell is a sequence of elements of the same type, enclosed in square brackets:
numbers = [1, 2, 3, 4, 5] -- List of integers
names = ["Alice", "Bob", "Carol"] -- List of strings
empty = [] -- Empty list
single = [42] -- List with one element
Every list has a type written as [a], where a is the type of the elements:
[1, 2, 3] :: [Int]
["hello", "world"] :: [String]
[True, False, True] :: [Bool]
All elements must be the same type — you cannot mix integers and strings.
In Haskell, a String is simply a list of Char:
"hello" == ['h', 'e', 'l', 'l', 'o'] -- True
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.