Reputation: 129
Is [([(True, False),(True, False)])]
equivalent to [((True, False),(True, False))]
in terms of typing?
Upvotes: 0
Views: 90
Reputation: 476537
No. We can query the type in GHCi, and obtain:
Prelude> :t [([(True, False),(True, False)])]
[([(True, False),(True, False)])] :: [[(Bool, Bool)]]
Prelude> :t [((True, False),(True, False))]
[((True, False),(True, False))] :: [((Bool, Bool), (Bool, Bool))]
So the first expression is a list of lists of 2-tuples of Bool
s; the latter is a list of 2-tuples of 2-tuples of Bool
s.
A list is not a tuple. In Haskell in a list all elements have the same type, furthermore the length of the list is not fixed at compile time.
A tuple on the other hand has a fixed arity (number of elements), and the type of the elements can vary.
We can also see that in the syntax: (True, False)
is a 2-tuple with two booleans, but in the first variant, we put this expression twice between square brackets (hence a list), whereas in the latter, it is between round brackets (hence a tuple, or brackets to "group" an expression).
Upvotes: 6