| Newsgroups |
gmane.comp.lang.ocaml.beginners |
| Message-ID |
<[email protected]> |
Thanks both.
Now I understand where my thinking takes a wrong turn.
Roelof
Chantal Keller schreef op 5-11-2014 15:46:
> Hi Roelof,
>
> [x;y] : 'a list is a list with two elements x : 'a and y : 'a.
>
> x::y : 'a list is a list with at least one element, its head x : 'a, and
> some tail y : 'a list about which we know nothing (it can be empty or
> not... etc.).
>
> Notice the difference between the two types of y in the two different
> expressions.
>
> For instance, you can define:
>
> let l = [1;2];;
> let l' = 1::[2];;
>
> Hope this helps,
> Chantal.
>
>
>
> Le 05/11/2014 15:28, Roelof Wobben [email protected] [ocaml_beginners] a
> écrit :
>> 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
>>
>>
------------------------------------
------------------------------------
Archives up to December 31, 2011 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners
The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid flames etc.
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ocaml_beginners/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ocaml_beginners/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/