data Tree a = Branch a a | Leaf deriving (Show)
construct :: (Integral a) => [a] -> Tree a
construct [] = Leaf
construct (x:[]) = Leaf -- _____error________
construct (l:r:xs) = if l>r then Branch l (construct $ r:xs)
else Branch (construct $ l:xs) r
* Occurs check: cannot construct the infinite type: a ~ Tree a
* In the second argument of `Branch', namely `(construct $ r : xs)'
In the expression: Branch l (construct $ r : xs)
In the expression:
if l > r then
Branch l (construct $ r : xs)
else
Branch (construct $ l : xs) r
* Relevant bindings include
xs :: [a] (bound at C:\Stuff\code\New folder (2)\try.hs:69:16)
r :: a (bound at C:\Stuff\code\New folder (2)\try.hs:69:14)
l :: a (bound at C:\Stuff\code\New folder (2)\try.hs:69:12)
construct :: [a] -> Tree a
why was it infinite type? This "infinite type" is input or output?
and also, If I change the construct (x:[]) = Leaf
to construct (x:[]) = x
then the error occurs in that x
. Why?