caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Ollie Frolovs <ollie.frolovs.2012@my.bristol.ac.uk>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Modules and record fields
Date: Sun, 25 May 2014 12:45:21 +0200	[thread overview]
Message-ID: <CAPFanBErMhagQB_=fRuHayx30bRuGW=ArrUuswWEk-mE3AinHw@mail.gmail.com> (raw)
In-Reply-To: <52C51721-8564-472C-AA7A-2ABE66C4D809@my.bristol.ac.uk>

let open Solarized in Sdl.set_render_draw_color ren orange.r orange.g
orange.b 0xff

Solarized.(Sdl.set_render_draw_color ren orange.r orange.g orange.b 0xff)

let module S = Solarized in Sdl.set_render_draw_color ren S.(orange.r)
S.(orange.g) S.(orange.b) 0xff

let apply f color = Solarized.(f color.r color.g color.b) in
apply (Sdl.set_render_draw_color ren) orange 0xff

On Sun, May 25, 2014 at 12:30 PM, Ollie Frolovs
<ollie.frolovs.2012@my.bristol.ac.uk> wrote:
> Hello
>
> I was using some colours in my program and thought that it would be a good idea to put colour constants into a separate module.
>
> module Solarized = struct
>   type colour = {r:int; g:int;  b:int}
>
>   let base03 = {r=0x00; g=0x2b; b=0x36}
>   let orange = {r=0xcb; g=0x4b; b=0x16}
>   (* etc etc *)
> end
>
> I need three separate RGB components because I’m using an API which needs them separately, rather than in some pre-packed way.
>
> I was planning to use the module like this
>
> let module S = Solarized in
> Sdl.set_render_draw_color ren S.orange.r S.orange.g S.orange.b 0xff
> (* etc etc *)
>
> that is, to locally open the module and refer to the colours and their subcomponent.
>
> But this does not work. It appears for some reason that I have to address the subcomponents as
>
> Solarized.orange.Solarized.r
>
> which defeats the purpose! Is there any other way to achieve my goal?
>
> Best regards
>
> Ollie
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

  reply	other threads:[~2014-05-25 10:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-25 10:30 Ollie Frolovs
2014-05-25 10:45 ` Gabriel Scherer [this message]
2014-05-25 10:59 ` Gabriel Kerneis
2014-05-25 12:46   ` Ollie Frolovs
2014-05-25 13:57     ` Gabriel Scherer
2014-05-25 14:56       ` Ollie Frolovs
2014-05-25 15:02         ` Gabriel Scherer
2014-05-26  9:14           ` Goswin von Brederlow

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='CAPFanBErMhagQB_=fRuHayx30bRuGW=ArrUuswWEk-mE3AinHw@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=ollie.frolovs.2012@my.bristol.ac.uk \
    /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;
as well as URLs for NNTP newsgroup(s).