* [Caml-list] what is here the syntax error
@ 2014-11-05 11:45 Roelof Wobben
0 siblings, 0 replies; 3+ messages in thread
From: Roelof Wobben @ 2014-11-05 11:45 UTC (permalink / raw)
To: caml-list
Hello,
I know this question must be asked on the beginners list but I still did
not get approved after I left the list.
I try again to learn Ocaml and Im stuck at exercise 1 of the 99 ocaml
problems.
Here is my solution :
let rec last list =
match list with
[] -> None
[x] -> Some x
[_] -> last [_::t] ;;
But now I see a syntax error on the [x] part.
Can anyone explain to me what I did wrong ?
Roelof
^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <545A14BE.5080308@inria.fr>]
* Re: [Caml-list] what is here the syntax error
[not found] <545A14BE.5080308@inria.fr>
@ 2014-11-05 12:15 ` Francois Berenger
2014-11-05 12:24 ` Pierrick Couderc
0 siblings, 1 reply; 3+ messages in thread
From: Francois Berenger @ 2014-11-05 12:15 UTC (permalink / raw)
To: caml >> OCaml List
-------- Forwarded Message --------
Subject: Re: [Caml-list] what is here the syntax error
Date: Wed, 05 Nov 2014 13:14:54 +0100
From: Francois Berenger <francois.berenger@inria.fr>
To: Roelof Wobben <r.wobben@home.nl>
On 11/05/2014 12:45 PM, Roelof Wobben wrote:
> Hello,
>
> I know this question must be asked on the beginners list but I still did
> not get approved after I left the list.
>
> I try again to learn Ocaml and Im stuck at exercise 1 of the 99 ocaml
> problems.
>
> Here is my solution :
>
> let rec last list =
> match list with
> [] -> None
> [x] -> Some x
> [_] -> last [_::t] ;;
Your last line is wrong:
[_] -> last [_::t] ;;
try to replace it with:
x :: xs -> last xs ;;
> But now I see a syntax error on the [x] part.
>
> Can anyone explain to me what I did wrong ?
>
> Roelof
>
>
--
Regards,
Francois.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] what is here the syntax error
2014-11-05 12:15 ` Francois Berenger
@ 2014-11-05 12:24 ` Pierrick Couderc
0 siblings, 0 replies; 3+ messages in thread
From: Pierrick Couderc @ 2014-11-05 12:24 UTC (permalink / raw)
To: Francois Berenger; +Cc: caml >> OCaml List
[-- Attachment #1: Type: text/plain, Size: 1677 bytes --]
>
> Your last line is wrong:
> [_] -> last [_::t] ;;
>
> try to replace it with:
> x :: xs -> last xs ;;
Actually, that's the syntax of the pattern mathing that is wrong (but this
would also raise en error) : each case should begin with a '|' (the pipe is
optional for the first line).
i.e. :
match list with
[] -> None
| [x] -> Some x
| _ :: xs -> last xs
Pierrick
2014-11-05 13:15 GMT+01:00 Francois Berenger <francois.berenger@inria.fr>:
>
>
>
> -------- Forwarded Message --------
> Subject: Re: [Caml-list] what is here the syntax error
> Date: Wed, 05 Nov 2014 13:14:54 +0100
> From: Francois Berenger <francois.berenger@inria.fr>
> To: Roelof Wobben <r.wobben@home.nl>
>
> On 11/05/2014 12:45 PM, Roelof Wobben wrote:
>
>> Hello,
>>
>> I know this question must be asked on the beginners list but I still did
>> not get approved after I left the list.
>>
>> I try again to learn Ocaml and Im stuck at exercise 1 of the 99 ocaml
>> problems.
>>
>> Here is my solution :
>>
>> let rec last list =
>> match list with
>> [] -> None
>> [x] -> Some x
>> [_] -> last [_::t] ;;
>>
>
> Your last line is wrong:
> [_] -> last [_::t] ;;
>
> try to replace it with:
> x :: xs -> last xs ;;
>
> But now I see a syntax error on the [x] part.
>>
>> Can anyone explain to me what I did wrong ?
>>
>> Roelof
>>
>>
>>
> --
> Regards,
> Francois.
>
>
>
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
--
Pierrick COUDERC
*PhD Student at OCamlPro / Ensta*
[-- Attachment #2: Type: text/html, Size: 3622 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-11-05 12:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-05 11:45 [Caml-list] what is here the syntax error Roelof Wobben
[not found] <545A14BE.5080308@inria.fr>
2014-11-05 12:15 ` Francois Berenger
2014-11-05 12:24 ` Pierrick Couderc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).