Reputation: 11307
This makes sense:
test :: [[Int]]
test = [[]]
main = print test
But why does this compile (and run)?
test :: [[Int]]
test = []
main = print test
Upvotes: 3
Views: 278
Reputation: 2703
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.
Upvotes: 4
Reputation: 444
[[Int]]
is list of lists (of Int's) and
[[]]
- list with one empty list inside[]
- empty listUpvotes: 9