Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Philippe Veber <philippe.veber@gmail.com>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Emulating width subtyping with 1st-class modules
Date: Thu, 5 Aug 2010 18:10:54 +0200	[thread overview]
Message-ID: <AANLkTimezHJhnwKaUgJ6VyvEc2qSnYXRtRncV-6iuoTB@mail.gmail.com> (raw)
In-Reply-To: <607998.18398.qm@web111514.mail.gq1.yahoo.com>

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

I have a related question: the only reason why i'm not fully happy with
objects used as anonymous records is that i sometimes use them as mere data
containers and need to save (marshal) them at some point. Which is not
permitted as soon as you want to exchange marshalled values between two
different programs. Hopefully one can rely on json-static to cope with that
limitation in a quite elegant way. Are first-class modules distinct in that
respect ? That is, can they be marshalled if they do not contain closures ?

philippe.

PS For those who missed it, there was an interesting thread on this very
topic a year ago

http://groups.google.com/group/fa.caml/browse_thread/thread/1eb4bba668b27aa3/9192a2760ef97ca9


2010/8/5 Dario Teixeira <darioteixeira@yahoo.com>

> Hi,
>
> I have a problem where some form of width subtyping for records would be
> useful.  At the present I'm taking advantage of the structural subtyping
> nature
> of Ocaml's object system to emulate the width subtyping.  This works and is
> reasonably compact, but I'm still open to other approaches.  It has
> occurred
> to me that 3.12's modules-as-first-class-values provide yet another
> solution:
>
>
> module type BRIEF =
> sig
>        val a: int
>        val b: string
> end
>
>
> module type FULL =
> sig
>        include BRIEF
>        val c: float
> end
>
>
> let print_brief m =
>        let module M = (val m: BRIEF) in
>        Printf.printf "A: %d, B: %s\n" M.a M.b
>
>
> let print_full m =
>        let module M = (val m: FULL) in
>        Printf.printf "A: %d, B: %s, C: %f\n" M.a M.b M.c
>
>
> module Full =
> struct
>        let a = 1
>        let b = "full"
>        let c = 0.5
> end
>
>
> module Brief =
> struct
>        let a = 0
>        let b = "short"
> end
>
>
> let () =
>        print_brief (module Brief : BRIEF);
>        print_brief (module Full : BRIEF);
>        print_full (module Full : FULL)
>
>
> While this approach seems awfully verbose, I reckon it could be made much
> more palatable via some Camlp4 sugaring.  Nevertheless, I have a question:
> just how heavy would this approach be when compared to the object one?
> And how would it fare in comparison to regular records?
>
> Thanks for your attention!
> Best regards,
> Dario Teixeira
>
>
>
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

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

  reply	other threads:[~2010-08-05 16:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-05 15:02 Dario Teixeira
2010-08-05 16:10 ` Philippe Veber [this message]
2010-08-05 16:17   ` [Caml-list] " Alain Frisch
2010-08-05 16:35 ` Alain Frisch
2010-08-05 19:02   ` Dario Teixeira

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=AANLkTimezHJhnwKaUgJ6VyvEc2qSnYXRtRncV-6iuoTB@mail.gmail.com \
    --to=philippe.veber@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=darioteixeira@yahoo.com \
    /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