[Haskell-beginners] The (x:xs) in function parameter is a tuple?
Graham Gill
math.simplex at gmail.com
Wed Feb 24 18:37:08 UTC 2016
Hi Nan, are you just confused about the use of the parentheses "(" and ")"?
(x1,x2), (x1,x2,x3), ... are tuples in Haskell, but (x:xs) is not.
(There's no "one-ple", or 1-tuple, in Haskell.) In
occurs value [] = 0
occurs value (x:xs) = (if value == x then 1 else 0) + occurs value xs
the "(" and ")" around "x:xs" are just there for grouping, for operator
precedence reasons. Function application binds more tightly than ":". If
you leave the parentheses off, such as in
occurs value x:xs = ...
you'll get a parse error.
Graham
On 2/24/2016 5:31 AM, Nan Xiao wrote:
> Hi all,
>
> Greetings from me!
>
> I am confused about the function parameters and tuple. E.g.:
>
> occurs value [] = 0
> occurs value (x:xs) = (if value == x then 1 else 0) + occurs value xs
>
> should we consider (x:xs) as a tuple?
>
> Thanks in advance!
>
> Best Regards
> Nan Xiao
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
More information about the Beginners
mailing list