From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id DAA00805; Thu, 22 Aug 2002 03:20:06 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id DAA00764 for ; Thu, 22 Aug 2002 03:20:05 +0200 (MET DST) Received: from hirsch.in-berlin.de (hirsch.in-berlin.de [192.109.42.6]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7M1K4n08205 for ; Thu, 22 Aug 2002 03:20:04 +0200 (MET DST) Received: from hirsch.in-berlin.de (localhost [127.0.0.1]) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with ESMTP id g7M1K3Zg004500 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT) for ; Thu, 22 Aug 2002 03:20:03 +0200 Received: (from uucp@localhost) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with UUCP id g7M1K2h6004496 for caml-list@inria.fr; Thu, 22 Aug 2002 03:20:02 +0200 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: caml-list@inria.fr Received: from localhost (oliver@localhost) by first.in-berlin.de (8.7.6/8.7.3) with SMTP id DAA00204 for ; Thu, 22 Aug 2002 03:11:56 +0200 Date: Thu, 22 Aug 2002 03:11:56 +0200 (MET DST) From: Oliver Bandel To: caml-list@inria.fr Subject: [Caml-list] Calling a function with a self-defined type as argument Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, after rewriting a perl-program into Ocaml, I tried it in different ways. After getting a minimal working-version ready, I tried some OO-stuff today first time in Ocaml. That's nice. I like it. Normally OO is annoying, but in OCaml, it's really fun. :) But during rewriting the program, I saw that I could do some advantages in using own types. I had tried it before, but had no success with using "try ...with ..." and the self defined type. But today I had better Ideas and so I started concentrating on working with the type, and after that maybe add some OO-stuff (if necessary/ helpful). During experimenting with the type, I experienced a - for me - strange behaviour. You can see my questions in the last lines of the code (see below). If you have other comments (optimizing code, better indenting-style), please let me know. (The program-code is not complete, here; only the necessary stuff for showing my question is in this mail.) ########################################################################### ########################################################################### ########################################################################### let suchstring = if Array.length Sys.argv > 1 then Sys.argv.(1) else "" let inch = open_in "de-tex-faq.txt" (* where to read from (inch: in-channel) *) type contents = EMPTY | Line of string | Empty_Line | EOF type inputline = { mutable line: contents; mutable lastline: contents } let il = { line = EMPTY; lastline = EMPTY } (* il: inputline *) (* rl: read line *) let rl channel = let content = try Line(input_line channel) with | _ -> EOF in let res content = match content with | Line ("") -> Empty_Line | l -> l (* should match all other stuff *) in il.lastline <- il.line; il.line <- content let x y = match y with | EOF -> print_string "EOF!!\n" | Empty_Line -> print_string "Empty_Line!!\n" | EMPTY -> print_string "unexpected EMPTY-case!\n" | Line txt -> print_string txt (* yes, "x" is a stupid name, but it was only a test until now. *) let _ = x Empty_Line;; (* expected behaviour *) let _ = x EOF;; (* expected behaviour *) let _ = x EMPTY;; (* expected behaviour *) (* let _ = x Line "h0oifdaji oi" ;; This last one does not work: => "This function is applied to too many arguments" let _ = x Line( "reuruhjf" ) ;; This last one does not work: => "This function is applied to too many arguments" But it works in this way: let _ = x (Line "reuruhjf") ;; WHY? (why *only* that?) At least the second example (with parantheses around the Line's arguments) should work...?! *) ########################################################################### ########################################################################### ########################################################################### Ciao, Oliver P.S.: I love that language. It's really fine :) ------------------- 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