From: Richard Jones <rich@annexia.org>
To: josh <josh@trdlnk.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Specifying abstract type in a record
Date: Fri, 12 Nov 2004 16:37:38 +0000 [thread overview]
Message-ID: <20041112163738.GA14038@annexia.org> (raw)
In-Reply-To: <4194E0C7.4060102@trdlnk.com>
[-- Attachment #1: Type: text/plain, Size: 1959 bytes --]
On Fri, Nov 12, 2004 at 10:11:51AM -0600, josh wrote:
> OK, Here's what I'm trying to do:
>
> # type doer = { file_name:string ; actor: ('a -> unit) };;
>
> But when I do this, it tells me that I've got "Unbound type parameter 'a ".
You need to do this:
# type 'a doer = { file_name:string ; actor: ('a -> unit) };;
type 'a doer = { file_name : string; actor : 'a -> unit; }
because you're creating a polymorphic type ('a doer). Note that this
won't let you store an actor function of type, say, int -> unit and
then replace it with another function of type, say, string -> unit.
For the same reason it won't let you pass an ``int doer'' to a
function expecting a ``string doer''.
> # type t
> # type doer = { file_name:string; actor (t -> unit) };;
>
> It works until I try to use a created record:
>
> # let b = {file_name = "one"; actor = (fun x -> () ) };;
> # b.actor 10;;
> The expression has type int but is used with type t
>
> even if I try to do this
>
> # type t = int;;
>
> it doesn't work.
OK, this is another problem. Here what you're doing is defining a
_new_ type ``t'', which is unrelated to your old type ``t''.
Here's another example:
# let f () = "hello";;
val f : unit -> string = <fun>
# f ();;
- : string = "hello"
# let g = f;;
val g : unit -> string = <fun>
# let f () = "goodbye";;
val f : unit -> string = <fun>
# f ();;
- : string = "goodbye"
# g ();;
- : string = "hello"
Notice that ``g'' still calls the old ``f'', even after ``f'' has been
redefined.
There's a beginner's list:
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Rich.
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
>>> http://www.team-notepad.com/ - collaboration tools for teams <<<
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
Use Perl libs in OCaml - http://www.merjis.com/developers/perl4caml
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2004-11-12 16:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-11 8:35 module type Pietro Abate
2004-11-11 8:56 ` [Caml-list] " skaller
2004-11-11 9:09 ` Pietro Abate
2004-11-11 9:48 ` Virgile Prevosto
2004-11-12 16:11 ` Specifying abstract type in a record josh
2004-11-12 16:33 ` [Caml-list] " Luc Maranget
2004-11-12 16:37 ` Aleksey Nogin
2004-11-12 16:37 ` Richard Jones [this message]
2004-11-12 16:40 ` Andrew Bagdanov
2004-11-12 16:44 ` Matt Gushee
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=20041112163738.GA14038@annexia.org \
--to=rich@annexia.org \
--cc=caml-list@inria.fr \
--cc=josh@trdlnk.com \
/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