[Haskell-cafe] List syntax -- [] vs ()

Stefan Holdermans sholderm at students.cs.uu.nl
Sat Jul 3 05:21:23 EDT 2004


Crypt Master,

  CM> I have noticed that lists seem to swtich between
  CM> using [] and  using (). for example:
  CM> 
  CM> listSum [] = 0
  CM> listSum (x:xs) = x + listsum xs 

The parentheses are just 'normal' parentheses that are needed because
application binds stronger than (:). Without the parentheses, you would get

  listSum x : xs

which is the same as

  (listSum x) : xs .

HTH,

Stefan




More information about the Haskell-Cafe mailing list