{-# LANGUAGE ScopedTypeVariables #-} -- Language extension does not affect error. f :: [a] -> a f xs = x where x :: a -- Commenting this resolves the error. x = xs !! 0 main :: IO () main = print "hello, world"