Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Ivan Gotovchits <ivg@ieee.org>
To: Steffen Smolka <smolka@cs.cornell.edu>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] private object constructor?
Date: Mon, 13 Feb 2017 13:57:12 -0500	[thread overview]
Message-ID: <CALdWJ+z8Sa1TrV-53ZPMrp--==X9XcmD=H9u4oCixXfCyjsxWA@mail.gmail.com> (raw)
In-Reply-To: <CAGh2ivAncBJ9_je1YhV17XjcniXJG2W63E5ay4ba9wKFemk87w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 975 bytes --]

Hi Steffen,

Your question contains the answer :) You can indeed expose an object type
and a class type without exposing the class.

module Example : sig
  class type t = object
      method print : unit
    end
end = struct
    class t = object
      method print = print_endline "yep"
    end
  end

The class implementation will not be exposed, so `new Example.t` will say
`Unbound class Example.t`. But, the class type and object type will be
exposed,
e.g, you may say `type printable = Example.t` (yes, class type declaration
declares both the type and the class type).

Regards,
Ivan


On Mon, Feb 13, 2017 at 1:23 PM, Steffen Smolka <smolka@cs.cornell.edu>
wrote:

> Hi,
>
> Is it possible to expose an object or class type in OCaml without exposing
> the constructor, i.e. the ability to construct objects of the type? OCaml
> supports private ADTs and type synonyms, but the private keyword doesn't
> seem to work with classes or objects.
>
> Thanks,
> -- Steffen
>

[-- Attachment #2: Type: text/html, Size: 1667 bytes --]

  reply	other threads:[~2017-02-13 18:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-13 18:23 Steffen Smolka
2017-02-13 18:57 ` Ivan Gotovchits [this message]
2017-02-13 19:11   ` Steffen Smolka

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='CALdWJ+z8Sa1TrV-53ZPMrp--==X9XcmD=H9u4oCixXfCyjsxWA@mail.gmail.com' \
    --to=ivg@ieee.org \
    --cc=caml-list@inria.fr \
    --cc=smolka@cs.cornell.edu \
    /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