From: John Prevost <j.prevost@cs.cmu.edu>
To: Lukasz Lew <ll189417@zodiac.mimuw.edu.pl>
Cc: John Prevost <j.prevost@cs.cmu.edu>, caml-list@inria.fr
Subject: Re: [Caml-list] Does this function exist?
Date: 09 Sep 2002 16:55:36 -0400 (87.194 UMT) [thread overview]
Message-ID: <86bs76c27r.fsf@laurelin.dementia.org> (raw)
In-Reply-To: <Pine.LNX.4.44.0209092212360.21417-100000@zodiac.mimuw.edu.pl>
>>>>> "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
next prev parent reply other threads:[~2002-09-09 21:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-09 17:56 Lukasz Lew
2002-09-09 19:34 ` John Prevost
2002-09-09 20:18 ` Lukasz Lew
2002-09-09 20:55 ` John Prevost [this message]
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)
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=86bs76c27r.fsf@laurelin.dementia.org \
--to=j.prevost@cs.cmu.edu \
--cc=caml-list@inria.fr \
--cc=ll189417@zodiac.mimuw.edu.pl \
/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