From: Brian Hurt <brian.hurt@qlogic.com>
To: Ocaml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] Variant parameterized method?
Date: Tue, 22 Jul 2003 15:09:59 -0500 (CDT) [thread overview]
Message-ID: <Pine.LNX.4.33.0307221457320.2041-100000@eagle.ancor.com> (raw)
What I want to do is write a class interface like:
class virtual ['a] foo :
object
method virtual doit : 'a
method map : 'b. ('a -> 'b) -> 'b foo
end
The map function returns a new foo (not necessarily a new member of
whatever derived from foo class the function is actually being called on)
parameterized on the variant type. This would be implemented more or less
like:
class ['a] mapped_foo f_init e_init =
object
val f = f_init
val e = e_init
method doit = f (e#doit)
method map g =
let h x = g (f x) in
mapped_foo g e
end
The first prototype, when I try to compile it, returns with:
File "foo.mli", line 2, characters 6-100:
The abbreviation foo is used with parameters 'a foo
wich are incompatible with constraints 'b foo
[sic on the wich- minor typo there]. It works just fine if I change map to
return a 'b list, or 'b array, or 'b Stack.t- it seems to be just 'b foo
that's a problem. Am I missing something? If not, what is the suggested
way for doing this? I need map as a member function- it needs to behave
differently on different types, and as I don't have reflextion, I need it
to be a member function. I'd prefer to keep it as a class for taste
reasons.
Help is appreciated.
Brian
-------------------
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 reply other threads:[~2003-07-22 20:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-22 20:09 Brian Hurt [this message]
2003-07-22 22:06 ` Jacques Garrigue
2003-07-22 22:34 ` Brian Hurt
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.4.33.0307221457320.2041-100000@eagle.ancor.com \
--to=brian.hurt@qlogic.com \
--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