I like the type-based answers given here, but I also want to give some up-to-date information explaining why we don't want this to be typecheck checked. Take the source of foldr1 to start with:
foldr1 :: (a -> a -> a) -> [a] -> a foldr1 _ [x] = x foldr1 f (x:xs) = fx (foldr1 f xs)
Now try to run your program.
foldr1 insert [1,19,-2,7,43] = { list syntax } foldr1 insert (1:[19,-2,7,43]) = { definition of foldr1 } insert 1 (foldr1 insert [19,-2,7,43]) = { three copies of the above two steps } insert 1 (insert 19 (insert (-2) (insert 7 (foldr1 insert [43])))) = { definition of foldr1 } insert 1 (insert 19 (insert (-2) (insert 7 43)))
... oops! This insert 7 43 will never work. =)
source share