* [Caml-list] Re: A similar small problem
[not found] <200212160855.gBG8tvL14522@iws.cs.uni-magdeburg.de>
@ 2002-12-16 9:24 ` sebastien FURIC
0 siblings, 0 replies; only message in thread
From: sebastien FURIC @ 2002-12-16 9:24 UTC (permalink / raw)
To: benecke, caml-list; +Cc: Sven Luther
Klaus Benecke a écrit :
>
> Thank you very much for your comments,
> I installed OCAML 3.01 and the mentioned problems disappeared,
> but a similar problem remains:
>
> let rec inclu_l=fun
> [] l -> true
> | (n::ns) l -> mem n l & inclu_l ns l;;
>
> File "C:/OTTO/CAMLquellen/XML2002/test.ml", line 3, characters
> 1-2:
> Syntax error
> Can you help me once more?
> Mit freundlichen Gruessen
> Klaus Benecke
> e-mail: benecke@iws.cs.uni-magdeburg.de
> home-page: http://theo.cs.uni-magdeburg.de/benecke.html
"fun patt1 patt2 ... pattn ->" could be view as a macro for:
"function patt1 -> function patt2 -> ... function pattn ->"
so your program is not syntactically valid. You have to use "match ...
with" if you want to match against more than one pattern:
let rec inclu_l ns l = match ns, l with
| [], _ -> true
| n :: ns', _ -> mem n l && inclu_l l ns'
However, since you don't have to match "l" against anything (hence
wildcards), you can simply write:
let rec inclu_l ns l = match ns with
| [] -> true
| n :: ns' -> mem n l && inclu_l l ns'
Or, (syntactically) better:
let rec inclu_l l = function
| [] -> true
| n :: ns -> mem n l && inclu_l l ns
by exanching "l" with the matched list (arguments that do not need to
be matched are often placed at first positions).
Cheers,
Sebastien.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-12-16 9:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <200212160855.gBG8tvL14522@iws.cs.uni-magdeburg.de>
2002-12-16 9:24 ` [Caml-list] Re: A similar small problem sebastien FURIC
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).