Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  The (x:xs) in function parameter is a tuple? (Nan Xiao)
   2. Re:  The (x:xs) in function parameter is a tuple?
      (Sumit Sahrawat, Maths & Computing, IIT (BHU))
   3. Re:  The (x:xs) in function parameter is a tuple?
      (Imants Cekusins)


----------------------------------------------------------------------

Message: 1
Date: Wed, 24 Feb 2016 18:31:49 +0800
From: Nan Xiao <xiaonan830...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] The (x:xs) in function parameter is a
        tuple?
Message-ID:
        <ca+mhoambg6d+d2vvrjptnjabhmn4zqerwdetkdhkkpow3oe...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

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


------------------------------

Message: 2
Date: Wed, 24 Feb 2016 16:14:04 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
        <sumit.sahrawat.ap...@iitbhu.ac.in>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] The (x:xs) in function parameter is a
        tuple?
Message-ID:
        <cajbew8mi5tsvnzsduvhhn13gawg_myghwsinsbfexvquvod...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

(:) 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 <xiaonan830...@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@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-0001.html>

------------------------------

Message: 3
Date: Wed, 24 Feb 2016 11:45:23 +0100
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] The (x:xs) in function parameter is a
        tuple?
Message-ID:
        <CAP1qinbkeGCCFdDFObtoLWrVHbOPX6t4TKeDYvnZ+mPVZyW=x...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hello Xiao,

(one_element)             -- is evaluation
(element,element,...)    -- is tuple

(1:[2])     -- [1,2] because it is one "array element"
(1,2)      -- is a tuple because there are 2 elements


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 92, Issue 28
*****************************************

Reply via email to