List syntax -- [] vs ()

Hi I have noticed that lists seem to swtich between using [] and using (). for example: listSum [] = 0 listSum (x:xs) = x + listsum xs but when specificy lists you use [] as in [1,2,3]. or type signatures are [a] -> [a] It also seems when they mentioned on the right hand side it also always []. Is it just for pattern matching that you use the "tuple" syntax ? How does haskell know we dont mean a tuple ? Or do we mean a tuple when we say (x:xs) ? Thanks _________________________________________________________________ MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus

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
participants (2)
-
Crypt Master
-
Stefan Holdermans