From: Julian Assange <proff@iq.org>
To: caml-list@inria.fr
Cc: proff@iq.org
Subject: list of objects
Date: 03 Oct 2000 03:38:59 +1100 [thread overview]
Message-ID: <wxaecnw63g.fsf@foo.iq.org> (raw)
I have a variety of signature schemes for text. I'd like to have
a list of these schemes, so I can do such things as:
List.map (fun x -> x#make text) schemes
Neither classes or modules are first class objects. However,
objects are. So, my first thought was to create something along the lines
of
let schemes = [new scheme_11; ...; new scheme_n]
Since the objects are functional (at least so far) this seems like an
acceptable approach.
class virtual signature =
object
end
class ['a] plain =
object (self)
inherit signature
method make s = s
method digest s = Digest.string (self#make s)
method compare (a:'a) b = a = b
end
class ['a] simple =
object
inherit ['a] plain
method make s = string_filter (alphabetize >> lower) s
end
let sig_list = [new plain; new simple]
On compilation, this produces:
The type of this expression, '_a Sigs.plain list,
contains type variables that cannot be generalized
However sending the exact same code to the top level,
produces:
module Sigs :
sig
val vanilla : 'a -> 'a
val lower : char option -> char option
val alphabetize : char option -> char option
val string_filter : (char option -> char option) -> string -> string
class virtual signature : object end
class ['a] plain :
object
method compare : 'a -> 'a -> bool
method digest : string -> Digest.t
method make : string -> string
end
class ['a] simple :
object
method compare : 'a -> 'a -> bool
method digest : string -> Digest.t
method make : string -> string
end
end
val sig_list : '_a Sigs.plain list = [<obj>; <obj>]
Works just fine! What gives?
next reply other threads:[~2000-10-03 7:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-10-02 16:38 Julian Assange [this message]
2000-10-03 9:53 ` Xavier Leroy
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=wxaecnw63g.fsf@foo.iq.org \
--to=proff@iq.org \
--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