3
votes

This makes sense:

test :: [[Int]]
test = [[]]

main = print test

But why does this compile (and run)?

test :: [[Int]]
test = []

main = print test
2

2 Answers

9
votes

[[Int]] is list of lists (of Int's) and

  • [[]] - list with one empty list inside
  • [] - empty list
4
votes

The type of [] is polymorphic, i.e. forall t. [t], meaning it represents an empty list of any type t. Since test is of type [[Int]], we can unify t ~ [Int] and therefore [] is an empty list of type [[Int]] also.