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
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
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
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
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
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
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
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
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
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
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
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
-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
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
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
15 matches
Mail list logo