When i type :type [(True,[]),(False, [['a']])] , "[(Bool,[[char]])]" in ghci it outputs [ (Bool , [ [char] ] )]. how is it possible that Haskell's type inference is treating an empty list and [[char]] as the same.
Haskell knows that True and False are Bools, and furthermore we know that all the elements of a list have the same type.
We are thus looking for a type [(True,[]),(False, [['a']])]. We see with the element that it is a 2-tuple with as first element a Bool, and as second item there is an empty list, so that has type [] :: [a] with a, at that time, unknown.
Now if we look at the second item, and see (False, [['a']]). This is thus a 2-tuple with False as first item, and [['a']] as second item. The type of 'a' is Char, hence ['a'] has type [Char], and [['a']] has type [[Char]]. Since the elements of a list should have the same type, we thus derive that the a type parameter of the first item, is a ~ [Char], and thus the outer list has type [(True,[]),(False, [['a']])] :: [(Bool, [[Char]])].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With