caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Calling a function with a self-defined type as argument
@ 2002-08-22  1:11 Oliver Bandel
  2002-08-22  1:43 ` SooHyoung Oh
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Oliver Bandel @ 2002-08-22  1:11 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2002-08-22 23:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-22  1:11 [Caml-list] Calling a function with a self-defined type as argument Oliver Bandel
2002-08-22  1:43 ` SooHyoung Oh
2002-08-22  1:50 ` Oleg
2002-08-22  2:20   ` Pal-Kristian Engstad
2002-08-22  2:32     ` Dimitri Ara
2002-08-22 12:40   ` Oliver Bandel
2002-08-22 13:15     ` Markus Mottl
2002-08-22 20:40       ` Oliver Bandel
2002-08-22  2:04 ` Dimitri Ara
2002-08-22 12:47   ` Oliver Bandel
2002-08-22 13:13     ` Sven LUTHER
2002-08-22 14:07     ` Remi VANICAT
2002-08-22 14:15       ` Markus Mottl
2002-08-22 23:51   ` Pixel

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).