From: Remi Vanicat <vanicat@debian.org>
To: caml-list@inria.fr
Subject: Re: type error
Date: Mon, 24 Mar 2008 09:53:16 +0100 [thread overview]
Message-ID: <87myoopkoz.dlv@maison.homelinux.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0803232304450.15117@martin.ec.wink.com>
Martin Jambon <martin.jambon@ens-lyon.org> writes:
> A more idiomatic way is to declare the following type:
>
> type foo = < bar: int >
An even more idiomatic way to do it is by using type class:
class type foo = object method bar : int end;;
and then you can use #foo that will be the type you wanted, Martin's
example become:
# class type foo = object method bar : int end;;
class type foo = object method bar : int end
# let print_bar (x : #foo) = print_int x # bar;;
val print_bar : #foo -> unit = <fun>
# let x =
(object
method bar = 123
method hello () = print_endline "hello"
end);;
val x : < bar : int; hello : unit -> unit > = <obj>
# print_bar x;;
123- : unit = ()
--
Rémi Vanicat
next prev parent reply other threads:[~2008-03-24 8:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-23 22:01 Jacques Le Normand
2008-03-23 22:19 ` [Caml-list] " Martin Jambon
2008-03-24 8:53 ` Remi Vanicat [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-04-01 2:27 Jacques Le Normand
2006-10-15 3:29 Type error Denis Bueno
2005-04-02 1:29 Jon Harrop
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=87myoopkoz.dlv@maison.homelinux.org \
--to=vanicat@debian.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