HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to HaskellVariables (let)Data TypesOperatorsStringsListsConditions (if / then / else)Iteration (map / sum)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Value & Type
🔢 Numbers & Math
✍️ String
📚 List
head / !! / lengthmap / sum / [1..n]
🔀 Condition
🧩 Function
Haskell›REFERENCE›List
📚

List

head, !!, length, ++, and map.

CommandDescription
head / !! / lengthList access.
map / sum / [1..n]Transformation and aggregation (instead of loops).

head / !! / length

Try it yourself →

List access.

Syntax

head xs   //   xs !! i   //   length xs

Description

head returns the first element, xs !! i returns the i-th element (0-indexed). length returns the number of elements. Lists are printed without spaces: [1,2,3].

Example

main = do
  let xs = [10, 20, 30]
  print (head xs)
  print (xs !! 1)
  print (length xs)

Expected output

10
20
3

When to use?

Accessing data collections.

map / sum / [1..n]

Try it yourself →

Transformation and aggregation (instead of loops).

Syntax

map f xs   //   sum xs   //   [1..n]

Description

There are no loops in Haskell. map transforms each element, sum adds them up. [1..n] is a range (inclusive of n). IO is applied to each element with mapM_.

Example

main = do
  print (map (\x -> x * x) [1, 2, 3])
  print (sum [1..100])

Expected output

[1,4,9]
5050

When to use?

List processing: transforming, summing, filtering.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code