
Hi. I'm a Haskell newbie and there's a bit of Haskell code that I don't understand how it works. In the prelude, defining the class Show, the function showList is implemented twice, one for String and another one for other lists: showList cs = showChar '"' . showl cs where showl "" = showChar '"' showl ('"':cs) = showString "\\\"" . showl cs showl (c:cs) = showLitChar c . showl cs and showList [] = showString "[]" showList (x:xs) = showChar '[' . shows x . showl xs where showl [] = showChar ']' showl (x:xs) = showChar ',' . shows x . showl xs The thing is... how does Haskell «know» which to execute? It works even for the blank string: Prelude> show "" "\"\"" Prelude> show [] "[]" Salud, Abby