Browse thread
[Caml-list] Re: A similar small problem
- sebastien FURIC
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | sebastien FURIC <sebastien.furic@t...> |
| Subject: | [Caml-list] Re: A similar small problem |
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