Why is it possible to make such a list in Haskell:
slist = [ [], [[]], [[],[[]]] ]
As far I understand, every element has various types here (like in mathematics: Ø, {Ø} and so on). And ghci says:
> :t []
[] :: [t]
> :t [[]]
[[]] :: [[t]]
formally, I see different notes.
In other words, the first element is a simple empty list and the second one is a list of list (!) and so on.
What is wrong? Why does Haskell consider them to be the same type?
You are right, that in a Haskell list, all elements must be of the same type. And indeed, the type in your example is:
> :t slist
slist :: [[[[a]]]]
But the empty list []
can have any type, as long as it's of the form [b]
, but there are many possible b
s. So there are many possible concrete types. One of them is for b
to be of type [[[a]]]
, as in your slist
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments