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

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

Thanks, this works :)

-- Steffen

On Mon, Feb 13, 2017 at 1:57 PM, Ivan Gotovchits <ivg@ieee.org> wrote:

> 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: 2221 bytes --]

      reply	other threads:[~2017-02-13 19:11 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
2017-02-13 19:11   ` Steffen Smolka [this message]

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=CAGh2ivBtsa9bVoWidHpt2BXHhoDWv1d_YzkKXFn96SYFcUR9cQ@mail.gmail.com \
    --to=smolka@cs.cornell.edu \
    --cc=caml-list@inria.fr \
    --cc=ivg@ieee.org \
    /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