[Haskell-beginners] The (x:xs) in function parameter is a tuple?

Sumit Sahrawat, Maths & Computing, IIT (BHU) sumit.sahrawat.apm13 at iitbhu.ac.in
Wed Feb 24 10:44:04 UTC 2016


(:) is a constructor. For example, you can define lists as:

data List a = Nil | Cons a (List a)

GHC does some magic to provide us with the same definition, but with Nil
replaced by [] and Cons replaced by (:).

As constructors can be pattern matched on, you can also match on a (:),
which is a data constructor.

You might consider (x:xs) as a tuple, only if you're willing to consider
(Cons x xs) as a tuple. It is a tuple (ordered collection of two values),
but not a tuple according to their definition in haskell.
What kind of tuple are you talking about?

Hope this helps.

Regards,
  Sumit

On 24 February 2016 at 16:01, Nan Xiao <xiaonan830818 at gmail.com> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160224/ebbe3674/attachment.html>


More information about the Beginners mailing list