caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Modules and record fields
@ 2014-05-25 10:30 Ollie Frolovs
  2014-05-25 10:45 ` Gabriel Scherer
  2014-05-25 10:59 ` Gabriel Kerneis
  0 siblings, 2 replies; 8+ messages in thread
From: Ollie Frolovs @ 2014-05-25 10:30 UTC (permalink / raw)
  To: caml users

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 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-05-26  9:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-25 10:30 [Caml-list] Modules and record fields Ollie Frolovs
2014-05-25 10:45 ` Gabriel Scherer
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

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).