Re: [Caml-list] Subtyping structurally-equivalent records, or something like it?

2010-05-07 Thread AUGER
Le Sun, 02 May 2010 04:59:48 +0200, Anthony Tavener a écrit: Wow! Thanks Stéphane... that was a little piece of magic I was hoping for. It's a bit verbose, but at least it doesn't affect performance and it allows all the control over types I need. I now see I didn't really grok phantom types

Re: [Caml-list] Subtyping structurally-equivalent records, or something like it?

2010-05-01 Thread Anthony Tavener
Wow! Thanks Stéphane... that was a little piece of magic I was hoping for. It's a bit verbose, but at least it doesn't affect performance and it allows all the control over types I need. I now see I didn't really grok phantom types whenever they were mentioned. A bit of "in one ear and out the oth

Re: [Caml-list] Subtyping structurally-equivalent records, or something like it?

2010-05-01 Thread Dario Teixeira
Hi, > type kinematic = { lin: Vec.t; ang: Vec.t } > > Which I've been using to represent a medley of physical attributes (force, > > momentum, velocity, etc.). I second Stéphane's suggestion of using phantom types; moreover, I recommend you read an article that discusses them to some detail and

Re: [Caml-list] Subtyping structurally-equivalent records, or something like it?

2010-05-01 Thread Stéphane Lescuyer
Hi Anthony, I think that maybe using phantom types could do the trick : consider defining empty types for all the different "kinds" of similar constructs that you have, and then define the kinematic record with a phantom parameter type. type position type acceleration type force type 'a kinematic

[Caml-list] Subtyping structurally-equivalent records, or something like it?

2010-05-01 Thread Anthony Tavener
I have this: type kinematic = { lin: Vec.t; ang: Vec.t } Which I've been using to represent a medley of physical attributes (force, momentum, velocity, etc.). As the physics code becomes increasingly substantial I'm running into possible human-error, like passing a momentum where a force is ex

[Caml-list] Subtyping of first-class module types

2010-04-16 Thread Alain Frisch
Dear caml-list, During today's ocaml meeting, the question of whether first-class module types could support subtyping was asked. I'd like to give a more detailed answer here. The explicit subtyping construction (e : t1 :> t2) could easily be extended to support subtyping of the form (m

Re: [Caml-list] Subtyping

2009-04-07 Thread Goswin von Brederlow
Jacques Garrigue writes: > type 'a base = {x : 'a; fn : 'a -> unit} > type 'b base_op = {bop: 'a. 'a base -> 'b} > type base_wrapper = {base: 'b. 'b base_op -> 'b} > > let l = > let a = {x = 1; fn = print_int} > and b = {x = 1.2; fn = print_float} in > [{base = fun x -> x.bop a}; {base = fu

Re: [Caml-list] Subtyping

2009-04-07 Thread Jacques Garrigue
Here is a slightly more usable version, using helper functions to avoid writing intermediate closures by hand. type 'a base = {x : 'a; fn : 'a -> unit} (* 4 next lines are boilerplate, could be auto-generated *) type 'b base_op = {bop: 'a. 'a base -> 'b} type base_wrapper = {base: 'b. 'b b

Re: [Caml-list] Subtyping

2009-04-07 Thread Jacques Garrigue
From: Goswin von Brederlow > Small extra question concerning this. Can I get ocaml to recognise a > type like this? > > type base = 'a. { > x : 'a; > fn : 'a -> unit; > } > > List.iter > (fun r -> r.fn r) > [{x = 1; fn = (fun r -> print_int r.x); }; >{x = 1.2; fn = (fun r -> print_fl

Re: [Caml-list] Subtyping

2009-04-07 Thread Goswin von Brederlow
Goswin von Brederlow writes: > So what other ways are there of doing this? Records. Idealy I would > like to do this: > > type base = { x : int } > let make_base x = { x = x } > let print_x r = print_int r.x > type foo = { base with y : int } > let make_foo x y = { x = x; y = y } > let _ = > pr

Re: [Caml-list] Subtyping

2009-04-07 Thread Goswin von Brederlow
Peng Zang writes: > On Tuesday 07 April 2009 03:41:32 am David MENTRE wrote: >> Hello, >> >> On Tue, Apr 7, 2009 at 07:48, Goswin von Brederlow > wrote: >> > In the last 2 weeks I've been playing around with lots of different >> > ways to do the same thing to get a feel for what style suites me

Re: [Caml-list] Subtyping

2009-04-07 Thread Goswin von Brederlow
David MENTRE writes: > Hello, > > On Tue, Apr 7, 2009 at 07:48, Goswin von Brederlow wrote: >> In the last 2 weeks I've been playing around with lots of different >> ways to do the same thing to get a feel for what style suites me >> best. If you have improvements or alternative ways of doing th

Re: [Caml-list] Subtyping

2009-04-07 Thread Peng Zang
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Tuesday 07 April 2009 03:41:32 am David MENTRE wrote: > Hello, > > On Tue, Apr 7, 2009 at 07:48, Goswin von Brederlow wrote: > > In the last 2 weeks I've been playing around with lots of different > > ways to do the same thing to get a feel for w

Re: [Caml-list] Subtyping

2009-04-07 Thread David MENTRE
Hello, On Tue, Apr 7, 2009 at 07:48, Goswin von Brederlow wrote: > In the last 2 weeks I've been playing around with lots of different > ways to do the same thing to get a feel for what style suites me > best. If you have improvements or alternative ways of doing the two > things below let me kno

[Caml-list] Subtyping

2009-04-06 Thread Goswin von Brederlow
Hi, In the last 2 weeks I've been playing around with lots of different ways to do the same thing to get a feel for what style suites me best. If you have improvements or alternative ways of doing the two things below let me know. One of the things was trying to build a type hierachy with coerci