caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Does this function exist?
@ 2002-09-09 17:56 Lukasz Lew
  2002-09-09 19:34 ` John Prevost
  2002-09-12 15:31 ` [Caml-list] " Michaël Grünewald
  0 siblings, 2 replies; 16+ messages in thread
From: Lukasz Lew @ 2002-09-09 17:56 UTC (permalink / raw)
  To: caml-list

Hello 
Is there in OCaml a function ['a -> ()] which would print striong 
representation of first arument on stdout, just like OcamlTop does?

print [3; 3];;

should print:
"- : int list = [3; 3]"

It would be very usefull for debugging.
Lukasz Lew

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

-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 17:56 [Caml-list] Does this function exist? Lukasz Lew
@ 2002-09-09 19:34 ` John Prevost
  2002-09-09 20:18   ` Lukasz Lew
                     ` (2 more replies)
  2002-09-12 15:31 ` [Caml-list] " Michaël Grünewald
  1 sibling, 3 replies; 16+ messages in thread
From: John Prevost @ 2002-09-09 19:34 UTC (permalink / raw)
  To: Lukasz Lew; +Cc: caml-list

>>>>> "ll" == Lukasz Lew <ll189417@zodiac.mimuw.edu.pl> writes:

    ll> Hello Is there in OCaml a function ['a -> ()] which would
    ll> print striong representation of first arument on stdout, just
    ll> like OcamlTop does?

    ll> print [3; 3];;

    ll> should print: "- : int list = [3; 3]"

    ll> It would be very usefull for debugging.  Lukasz Lew

It would be, but I don't believe that it's really possible--you need
type information in order to determine what to display, and that
information is not available at runtime.  If you know the type of what
you're printing, you can always use printf.

John.

-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 19:34 ` John Prevost
@ 2002-09-09 20:18   ` Lukasz Lew
  2002-09-09 20:55     ` John Prevost
                       ` (2 more replies)
       [not found]   ` <Pine.LNX.4.44.0209092212360.21417-100000@zodiac.mimuw.edu. pl>
  2002-09-16 16:56   ` Kontra, Gergely
  2 siblings, 3 replies; 16+ messages in thread
From: Lukasz Lew @ 2002-09-09 20:18 UTC (permalink / raw)
  To: John Prevost; +Cc: caml-list

>     ll> Hello Is there in OCaml a function ['a -> ()] which would
>     ll> print striong representation of first arument on stdout, just
>     ll> like OcamlTop does?
> 
>     ll> print [3; 3];;
> 
>     ll> should print: "- : int list = [3; 3]"
> 
>     ll> It would be very usefull for debugging.  Lukasz Lew
> 
> It would be, but I don't believe that it's really possible--you need
> type information in order to determine what to display, and that
> information is not available at runtime.  If you know the type of what
> you're printing, you can always use printf.

OK, so I want just "[3; 3]", (no type information),

I can use printf, but it isn't very easy to write when you have i.e. 
list of pairs of lists. And i believe that there is unversal ``print''.
Can you help?

Lukasz Lew

-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 20:18   ` Lukasz Lew
@ 2002-09-09 20:55     ` John Prevost
  2002-09-09 20:59       ` Lukasz Lew
  2002-09-17 16:21       ` Kontra, Gergely
  2002-09-09 21:40     ` Yutaka OIWA
  2002-09-09 23:10     ` Nicolas Cannasse
  2 siblings, 2 replies; 16+ messages in thread
From: John Prevost @ 2002-09-09 20:55 UTC (permalink / raw)
  To: Lukasz Lew; +Cc: John Prevost, caml-list

>>>>> "ll" == Lukasz Lew <ll189417@students.mimuw.edu.pl> writes:

    ll> OK, so I want just "[3; 3]", (no type information),

Doesn't matter--you still need type information.  Otherwise, you'll
get things like:

type foo = A | B | C

print [A; B; C]

outputs: [0; 1; 2]

or

print ["a"; "b"; "c"]

outputs: [<ref>; <ref>; <ref>]

Since the runtime can't tell the difference between integers and
abstract sum types in the first case and can't tell what a pointer is
pointing to in the second case.

Take a look at what you can see in the O'Caml debugger--in some cases
it can tell you the values of things.  In many cases, you're in a
polymorphioc function and all it says is "<poly>" for a value, because
it doesn't know how to display the value.

Here's an example of that:

test.ml
------------------------------------------------------------------------
let rec map f = function
  | [] -> []
  | h::t -> (f h)::(map f t)

type t = A | B | C | D | E

let i1 = [1; 2; 3; 4; 5]
let i2 = [A; B; C; D; E]
let i3 = ["a"; "b"; "c"]

let o1 = map (fun x -> x) i1
let o2 = map (fun x -> x) i2
let o3 = map (fun x -> x) i3
------------------------------------------------------------------------

$ ocamldebug a.out
        Objective Caml Debugger version 3.04

(ocd) run
Loading program... done.
Time : 82
Program exit.
(ocd) break Test.map
Breakpoint 1 at 5008 : file Test, line 1 column 13
(ocd) goto 0
Time : 0
Beginning of program.
(ocd) run
Time : 12 - pc : 5040 - module Test
Breakpoint : 1
3   | h::t -> <|b|>(f h)::(map f t)
(ocd) print h
h : 'a = <poly>
(ocd) print t
t : 'a list = [<poly>; <poly>; <poly>; <poly>]
(ocd) bt
#0  Pc : 5040  Test char 50
#1  Pc : 5196  Test char 200
(ocd) up
#1  Pc : 5196  Test char 200
11 let o1 = map (fun x -> x) i1<|a|>
(ocd) print i1
i1 : int list = [1; 2; 3; 4; 5]

Here we see that when we're inside the polymorphic function, the type
information is lost (even though we're in debugging mode.)  Only by
going up the stack to a point where the type of the value is known can
we learn anything.

John.
-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 20:55     ` John Prevost
@ 2002-09-09 20:59       ` Lukasz Lew
  2002-09-17 16:21       ` Kontra, Gergely
  1 sibling, 0 replies; 16+ messages in thread
From: Lukasz Lew @ 2002-09-09 20:59 UTC (permalink / raw)
  To: caml-list

> Here we see that when we're inside the polymorphic function, the type
> information is lost (even though we're in debugging mode.)  Only by
> going up the stack to a point where the type of the value is known can
> we learn anything.

Agreed. So, it's a pity.
Does it apply equally to bytecode and native?
So maybe at least at ocamltop this function exist?

Lukasz Lew

-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 20:18   ` Lukasz Lew
  2002-09-09 20:55     ` John Prevost
@ 2002-09-09 21:40     ` Yutaka OIWA
  2002-09-09 23:10     ` Nicolas Cannasse
  2 siblings, 0 replies; 16+ messages in thread
From: Yutaka OIWA @ 2002-09-09 21:40 UTC (permalink / raw)
  To: Lukasz Lew; +Cc: caml-list

>> On Mon, 9 Sep 2002 22:18:08 +0200 (CEST), Lukasz Lew <ll189417@zodiac.mimuw.edu.pl> said:

> I can use printf, but it isn't very easy to write when you have i.e. 
> list of pairs of lists. And i believe that there is unversal ``print''.
> Can you help?

No. Why can you believe it?  Or is it just a wish? :-)


In OCaml runtime, several different data share the same representation.
For example, all (0 : int), ('\000' : char), (None: 'a option), 
((): unit), ([]: 'a list), (FP_normal : fpclass), (Open_rdonly : open_flag), 
and etc...... are represented by the same 32/64bit word "0x00000001".
Also, (0, 0), [0], and [| 0; 0 |] share the same representation.
See Section 18.3 of the OCaml manual, and the header file
"mlvalues.h" in the Ocaml's lib directory for further detail.
One can not distinguish those on-memory data in any way.

Therefore, the type information is strictly required for
pretty-printing values correctly. Even bytecode does
not have an enough information to recover the type information *1 .

If your requirement is only to acquire some programmer-readable
output for debugging purpose, you can try 
[ http://www.yl.is.s.u-tokyo.ac.jp/~oiwa/pub/misc/datadumper.ml ] *2 .
This module walks on-memory data structures
and prints the values in some "simplest" form like integers and pairs.
For example, the values above are printed just as 0 and (0, 0).


-- Footnote --
*1: The two functions

let f1 (x : int) = f x
let f2 (x : int) = f (Char.unsafe_chr x)

emits exactly the same bytecode. Even inspecting all instructions,
one can not determine whether the argument passed to a polymorphic
function f is an integer or a character.

*2: datadumper.ml is written for OCaml 3.04.
I did not tried it with the new representation of the lazy values
in OCaml 3.05/3.06.

-- 
Yutaka Oiwa              Yonezawa Lab., Dept. of Computer Science,
      Graduate School of Information Sci. & Tech., Univ. of Tokyo.
      <oiwa@yl.is.s.u-tokyo.ac.jp>, <yutaka@oiwa.shibuya.tokyo.jp>
PGP fingerprint = C9 8D 5C B8 86 ED D8 07  EA 59 34 D8 F4 65 53 61
-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
       [not found]   ` <Pine.LNX.4.44.0209092212360.21417-100000@zodiac.mimuw.edu. pl>
@ 2002-09-09 22:05     ` Chris Hecker
  2002-09-09 22:48       ` Remi VANICAT
  0 siblings, 1 reply; 16+ messages in thread
From: Chris Hecker @ 2002-09-09 22:05 UTC (permalink / raw)
  To: Lukasz Lew, John Prevost; +Cc: caml-list


>I can use printf, but it isn't very easy to write when you have i.e.
>list of pairs of lists. And i believe that there is unversal ``print''.
>Can you help?

This has gone around before, and I think it's impossible because there's no 
type information available at runtime.

However, it seems like it would solve 90% of the problems if we could 
generate the code for such a function for a specific type using a tool, 
like camlp4 or something, and then compile that in when we want it.  In 
other words, say I have this:

type foo = A of int | B of int list

Then have camlp4 generate

let print_foo fmt f =
   Format.fprintf fmt "@[foo = ";
   begin match f with
     A i -> Format.fprintf fmt "A %d" i
   | B il -> Format.fprintf fmt "B [%s]"
         (List.fold_left ~f:(fun s i -> s ^ Printf.sprintf "%s%d" (if s <> 
"" then "; " else "") i) ~init:"" il)
   end;
   Format.fprintf fmt "@]"

or whatever (you'd probably want it to just return a string so you could 
compose them, but then you'd want the formatting stuff in there, so it's 
unclear exactly which would be better...maybe Format.sprintf works).  The 
idea is you don't want to have to write that code by hand, but generating 
it would be fine.

Is this something camlp4 can do?

Chris


-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 22:05     ` Chris Hecker
@ 2002-09-09 22:48       ` Remi VANICAT
  2002-09-10  1:10         ` Daniel de Rauglaudre
  0 siblings, 1 reply; 16+ messages in thread
From: Remi VANICAT @ 2002-09-09 22:48 UTC (permalink / raw)
  To: caml-list

Chris Hecker <checker@d6.com> writes:

> type foo = A of int | B of int list
>
> Then have camlp4 generate
>
> let print_foo fmt f =
>    Format.fprintf fmt "@[foo = ";
>    begin match f with
>      A i -> Format.fprintf fmt "A %d" i
>    | B il -> Format.fprintf fmt "B [%s]"
>          (List.fold_left ~f:(fun s i -> s ^ Printf.sprintf "%s%d" (if
> s <> "" then "; " else "") i) ~init:"" il)
>    end;
>    Format.fprintf fmt "@]"
>
> or whatever (you'd probably want it to just return a string so you
> could compose them, but then you'd want the formatting stuff in there,
> so it's unclear exactly which would be better...maybe Format.sprintf
> works).  The idea is you don't want to have to write that code by
> hand, but generating it would be fine.
>
> Is this something camlp4 can do?

There is ioXML (http://pauillac.inria.fr/~ddr/IoXML/index.html) that
make more or less that (but with XML).

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 20:18   ` Lukasz Lew
  2002-09-09 20:55     ` John Prevost
  2002-09-09 21:40     ` Yutaka OIWA
@ 2002-09-09 23:10     ` Nicolas Cannasse
  2 siblings, 0 replies; 16+ messages in thread
From: Nicolas Cannasse @ 2002-09-09 23:10 UTC (permalink / raw)
  To: Lukasz Lew, John Prevost; +Cc: caml-list

> OK, so I want just "[3; 3]", (no type information),
>
> I can use printf, but it isn't very easy to write when you have i.e.
> list of pairs of lists. And i believe that there is unversal ``print''.
> Can you help?

You still can use the (undocumented because unsafe) Obj module of the
standard distribution. This enable you to recursivly scan ocaml blocks :

let rec print_ints x =
    let r = Obj.repr x in
    match Obj.is_int r with
    | true -> Printf.sprintf "%d" (Obj.magic x : int)
    | false -> (* recursivly print fields from 0 to (Obj.size r)-1 *) ...

val print_ints : 'a -> unit

Nicolas Cannasse

-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 22:48       ` Remi VANICAT
@ 2002-09-10  1:10         ` Daniel de Rauglaudre
  0 siblings, 0 replies; 16+ messages in thread
From: Daniel de Rauglaudre @ 2002-09-10  1:10 UTC (permalink / raw)
  To: caml-list

Hi,

Chris Hecker <checkerOd6.com> writes:
> 
> type foo = A of int | B of int list
> Then have camlp4 generate
> let print_foo fmt f =
> [...]
> Is this something camlp4 can do?

Camlp4 can do that, indeed, the way ioXML does, like Remi Vanicat says.
With changes in ioXML, you can generate printing functions you want,
for each type.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
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] 16+ messages in thread

* [Caml-list] Re: Does this function exist?
  2002-09-09 17:56 [Caml-list] Does this function exist? Lukasz Lew
  2002-09-09 19:34 ` John Prevost
@ 2002-09-12 15:31 ` Michaël Grünewald
  1 sibling, 0 replies; 16+ messages in thread
From: Michaël Grünewald @ 2002-09-12 15:31 UTC (permalink / raw)
  To: caml-list

Lukasz Lew <ll189417@zodiac.mimuw.edu.pl> writes:

> Hello 
> Is there in OCaml a function ['a -> ()] which would print striong 
> representation of first arument on stdout, just like OcamlTop does?
> 
> print [3; 3];;
> 
> should print:
> "- : int list = [3; 3]"
> 
> It would be very usefull for debugging.
> Lukasz Lew

[...]

The function `Toplevel.print_value ' should deserve such an intention, but
help will come from the implementors.
-- 
Michaël Grünewald <michael-grunewald@wanadoo.fr>  - RSA PGP Key ID: 0x20D90C12
-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 19:34 ` John Prevost
  2002-09-09 20:18   ` Lukasz Lew
       [not found]   ` <Pine.LNX.4.44.0209092212360.21417-100000@zodiac.mimuw.edu. pl>
@ 2002-09-16 16:56   ` Kontra, Gergely
  2 siblings, 0 replies; 16+ messages in thread
From: Kontra, Gergely @ 2002-09-16 16:56 UTC (permalink / raw)
  To: caml-list

>It would be, but I don't believe that it's really possible--you need
>type information in order to determine what to display, and that
>information is not available at runtime.  If you know the type of what
>you're printing, you can always use printf.

I thought ocaml is strictly typed. Then, if overloading would be
enabled, this problem didn't exist any more.

Gergo

+-[Kontra, Gergely @ Budapest University of Technology and Economics]-+
|         Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu          |
|  URL:   turul.eet.bme.hu/~kgergely    Mobile: (+36 20) 356 9656     |
+-------"Olyan langesz vagyok, hogy poroltoval kellene jarnom!"-------+
.
Magyar php mirror es magyar php dokumentacio: http://hu.php.net

-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-09 20:55     ` John Prevost
  2002-09-09 20:59       ` Lukasz Lew
@ 2002-09-17 16:21       ` Kontra, Gergely
  2002-09-17 17:17         ` Florian Hars
  1 sibling, 1 reply; 16+ messages in thread
From: Kontra, Gergely @ 2002-09-17 16:21 UTC (permalink / raw)
  To: John Prevost; +Cc: Lukasz Lew, caml-list

>Doesn't matter--you still need type information.

BTW allowing polimorphism doesn't solve the problem? Ocaml is strictly
typed, so one can figure out it's parameter in compile-type, right?
Or wrong?

Gergo

+-[Kontra, Gergely @ Budapest University of Technology and Economics]-+
|         Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu          |
|  URL:   turul.eet.bme.hu/~kgergely    Mobile: (+36 20) 356 9656     |
+-------"Olyan langesz vagyok, hogy poroltoval kellene jarnom!"-------+
.
Magyar php mirror es magyar php dokumentacio: http://hu.php.net

-------------------
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] 16+ messages in thread

* Re: [Caml-list] Does this function exist?
  2002-09-17 16:21       ` Kontra, Gergely
@ 2002-09-17 17:17         ` Florian Hars
  0 siblings, 0 replies; 16+ messages in thread
From: Florian Hars @ 2002-09-17 17:17 UTC (permalink / raw)
  To: Kontra, Gergely; +Cc: caml-list

Kontra, Gergely wrote:
> BTW allowing polimorphism doesn't solve the problem? 

No

 > Ocaml is strictly
> typed, so one can figure out it's parameter in compile-type, right?

Yes. This is why such a beast as requested at the start of this thread can't be
implemented as a function, but only with some serious compiler magic (that 
breaks separate compilation) like the toplevel does.

How would you compile a module like:

type verbose_list 'a = Nil | Cons of 'a * 'a verbose_list
let cons elt l =
	print_string "Consing element ";
	print elt;
	print_string " to list ";
	print l;
	print_newline ();
	Cons (elt, l)

when all you know about elt at compile time is that it is completly polymorphic?

Yours, Florian Hars.

-------------------
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] 16+ messages in thread

* RE: [Caml-list] Does this function exist?
@ 2002-09-18 23:01 Gurr, David (MED, self)
  0 siblings, 0 replies; 16+ messages in thread
From: Gurr, David (MED, self) @ 2002-09-18 23:01 UTC (permalink / raw)
  To: Kontra, Gergely; +Cc: caml-list, Gurr David (MED Self) (E-mail)



> -----Original Message-----
> From: Kontra, Gergely [mailto:kgergely@mlabdial.hit.bme.hu]
> Sent: Tuesday, September 17, 2002 9:21 AM
> To: John Prevost
> Cc: Lukasz Lew; caml-list@inria.fr
> Subject: Re: [Caml-list] Does this function exist?
> 
> 
> >Doesn't matter--you still need type information.
> 
> BTW allowing polymorphism doesn't solve the problem? Ocaml is strictly
> typed, so one can figure out it's parameter in compile-type, right?
> Or wrong?

Most ML languages do type erasure rather than 
dictionary passing.  Yeah, the compiler knows the type,
but you want the runtime to know the type.  But the 
runtime doesn't know much more than int,float,closure,
pointer to something with a constructor tag.  Java's
reflection and C++ RTTI come at a price that is 
considered wrong by designers who pick type erasure.
I am a fan of reflection but I agree with Ocaml's
choices.  What you seem to want is IMHO something
that is right for debuggers and interactive toploops
but not other code, thus they not the other code should
pay the price.  Read up on implementation of ML on
JVM or MSCLR for an alternative to the Ocaml choices.
-D
PS if you are really into this, you could implement
RTTI with preprocessing via camlp4 (?or MetaOcaml?).

> Gergo
> 
> +-[Kontra, Gergely @ Budapest University of Technology and 
> Economics]-+
> |         Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu  
>         |
> |  URL:   turul.eet.bme.hu/~kgergely    Mobile: (+36 20) 356 
> 9656     |
> +-------"Olyan langesz vagyok, hogy poroltoval kellene 
> jarnom!"-------+
> .
> Magyar php mirror es magyar php dokumentacio: http://hu.php.net
> 
> -------------------
> 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
> 
-------------------
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] 16+ messages in thread

* RE: [Caml-list] Does this function exist?
@ 2002-09-18 23:01 Gurr, David (MED, self)
  0 siblings, 0 replies; 16+ messages in thread
From: Gurr, David (MED, self) @ 2002-09-18 23:01 UTC (permalink / raw)
  To: Florian Hars; +Cc: caml-list, Gurr David (MED Self) (E-mail)



> -----Original Message-----
> From: Florian Hars [mailto:florian@hars.de]
> Sent: Tuesday, September 17, 2002 10:18 AM
> To: Kontra, Gergely
> Cc: caml-list@inria.fr
> Subject: Re: [Caml-list] Does this function exist?
> 
> 
> Kontra, Gergely wrote:
> > BTW allowing polimorphism doesn't solve the problem? 
> 
> No
> 
>  > Ocaml is strictly
> > typed, so one can figure out it's parameter in compile-type, right?
> 
> Yes. This is why such a beast as requested at the start of 
> this thread can't be
> implemented as a function, but only with some serious 
> compiler magic (that 
> breaks separate compilation) like the toplevel does.

How does the toploop break separate compilation?  The toploop
is not magic and any user program that needs the same 
functionality (like a debugger) could do the same.

> 
> How would you compile a module like:
> 
> type verbose_list 'a = Nil | Cons of 'a * 'a verbose_list
> let cons elt l =
> 	print_string "Consing element ";
> 	print elt;
> 	print_string " to list ";
> 	print l;
> 	print_newline ();
> 	Cons (elt, l)
> 
> when all you know about elt at compile time is that it is 
> completly polymorphic?

The same way that F# knows it.  F# has separate compilation.
Or Java, or C#, or Smalltalk, or Perl.  Not that that I 
believe that that is a "good thing".

-D

> 
> Yours, Florian Hars.
> 
> -------------------
> 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
-------------------
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] 16+ messages in thread

end of thread, other threads:[~2002-09-18 23:01 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-09 17:56 [Caml-list] Does this function exist? Lukasz Lew
2002-09-09 19:34 ` John Prevost
2002-09-09 20:18   ` Lukasz Lew
2002-09-09 20:55     ` John Prevost
2002-09-09 20:59       ` Lukasz Lew
2002-09-17 16:21       ` Kontra, Gergely
2002-09-17 17:17         ` Florian Hars
2002-09-09 21:40     ` Yutaka OIWA
2002-09-09 23:10     ` Nicolas Cannasse
     [not found]   ` <Pine.LNX.4.44.0209092212360.21417-100000@zodiac.mimuw.edu. pl>
2002-09-09 22:05     ` Chris Hecker
2002-09-09 22:48       ` Remi VANICAT
2002-09-10  1:10         ` Daniel de Rauglaudre
2002-09-16 16:56   ` Kontra, Gergely
2002-09-12 15:31 ` [Caml-list] " Michaël Grünewald
2002-09-18 23:01 [Caml-list] " Gurr, David (MED, self)
2002-09-18 23:01 Gurr, David (MED, self)

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