| CARVIEW |
Select Language
HTTP/2 308
date: Fri, 16 Jan 2026 12:58:48 GMT
content-length: 0
location: /haskell/tutorial/data-structures/
access-control-allow-origin: *
referrer-policy: strict-origin-when-cross-origin
vary: accept-encoding
report-to: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=mb8eEvWeTzsLv3xZpuT2%2FS6XLpldm1DrodjnUZQq7KPRvjDMMgpUCu%2BnAe4XLiGZ37tKDr8hUdsP8cP8y8WosIDyNMRufSExz3JWgpbQXK0VzIQ%3D"}]}
nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
server: cloudflare
cf-cache-status: DYNAMIC
cf-ray: 9bedc957a90547d2-BOM
alt-svc: h3=":443"; ma=86400
HTTP/2 200
date: Fri, 16 Jan 2026 12:58:49 GMT
content-type: text/html; charset=utf-8
access-control-allow-origin: *
cache-control: public, max-age=0, must-revalidate
nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
vary: accept-encoding
report-to: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=nM5%2BXSpUrO3uVAqXjKEFMn95CjNN4e59G%2FvcRNBceojIhl3FUEXJk2nzZmk10ZH4YI0MXXzmgg3z2TMd6XOEkZzm5j0Go6kZvI%2FaFQdQCo4BwBM%3D"}]}
cf-cache-status: DYNAMIC
server: cloudflare
content-encoding: gzip
cf-ray: 9bedc957e92647d2-BOM
alt-svc: h3=":443"; ma=86400
Data Structures
Data Structures
You mean Haskell has things besides lists???
It's important to focus on data structures, since getting your data right is step 1 to great Haskell code.
Generic data structures
There are three basic flavors to the data structures
- Sequences: list, vector, ByteString, Text, and Seq (not covered)
- Order of values matters
- Can have multiple copies of the same value
- Maps: Map, HashMap, IntMap
- Map a key to a value
- Aka, dictionary
- Each key only appears once
- Sets: Set, HashSet, IntSet
- Map without values
- Like a sequence, but (1) order undefined and (2) no duplicates
API design
- Each of these families has very similar APIs (though not quite identical).
- Learning one will help you master the others.
- Yes, this means you already know most of the vector, ByteString, and Text APIs.
- The Map and Set APIs are also very similar.
- APIs are designed to be imported qualified (lots of conflicting names)
- Later: we'll look at mono-traversable for typeclasses to unify these APIs.
Laziness
- Lists are fully lazy
- Lazy
ByteStringandTextstill have strict chunks - Boxed vectors are spine strict
Maphas strict and lazy modules, different impacts on values- Unboxed and storable vectors are fullhy strict.
Impacts: undefined, infinite structures, performance, memory usage.
Some caveats
- Unlike the other sequences, ByteString and Text are monomorphic
- There are three common flavors of Vector, we'll cover the differences later
- IntMap and IntSet requires Int keys
- Some of the structures have constraints on keys or values
There are also ByteString and Text builders for efficient construction.
Quiz: Pick the data structure
- Names of all students in a class
- Names and grades of all students in a class
- All the prime numbers
- The first 1000 prime numbers
- Whitelist of allowed email addresses to access a resource
We'll come back to this quiz after we explore the data types in more detail.