caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Oliver Bandel <oliver@first.in-berlin.de>
To: caml-list@inria.fr
Subject: [Caml-list] Calling a function with a self-defined type as argument
Date: Thu, 22 Aug 2002 03:11:56 +0200 (MET DST)	[thread overview]
Message-ID: <Pine.LNX.3.95.1020822025344.150A-100000@first.in-berlin.de> (raw)

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


             reply	other threads:[~2002-08-22  1:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-22  1:11 Oliver Bandel [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.3.95.1020822025344.150A-100000@first.in-berlin.de \
    --to=oliver@first.in-berlin.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).