Re: what is the difference here ?

"Esther Baruk [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <CAFzMiE2KMkuHctt54FD-yauzy2QUb6hxpoSRfh+s98XByCJ3nA@mail.gmail.com>
Hi,

When you write x :: y, it means that x represent the head of the list and y
represents the tail of the list, which is itself a list.
So x :: y and _ :: xs represent the same pattern, that's why you are
getting this warning.

You can read the following tutorial to understand the syntax about lists:
http://ocaml.org/learn/tutorials/data_types_and_matching.html

Cheers,

Esther Baruk

On Wed, Nov 5, 2014 at 3:28 PM, Roelof Wobben [email protected]
[ocaml_beginners] <[email protected]> wrote:

>
>
> Hello,
>
> I found the solution to exercise 2 of the 99 ocaml problems.
> The solution I found was this :
>
> let rec last_two list =
> match list with
> | [] | [_] -> None
> | [x;y] -> Some (x,y)
> | _::xs -> last_two xs ;;
>
> Now I wonder something.
> For me it looks like [x;y] and _::xs are the same.
> If I understand it right you can write [x;y] as x::y and _::xs looks
> then the same to me.
> But if I change [x;y] to x::y then I see a message that _:xs is not used.
>
> Can someone explain in simple words what is the difference between those
> two ?
>
> Roelof
>
>  
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.