* Typing Dynamic Typing in ocaml?
@ 2008-12-17 19:45 Jacques Carette
2008-12-17 19:58 ` [Caml-list] " Stéphane Glondu
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Jacques Carette @ 2008-12-17 19:45 UTC (permalink / raw)
To: OCaml
I have two (related) questions:
1) Has anyone transcribed the TypeRep library into ocaml?
http://people.cs.uu.nl/arthurb/dynamic.html
2) How do I embed 'dynamically known' data into a single ocaml
data-structure?
More specifically, I am experimenting with a (new) language which allows
deduction and computations to be performed with equal ease on its
terms. This language uses ocaml has the host meta-language (ie the
interpreter is written in ocaml). I would like to be able to use
arbitrary ocaml data-structures to represent some of my terms, when
these terms are known to come from specific theories. For example, I
would like to use Bigint to represent integers, but without exposing
that per se. Perhaps a better way to phrase this would be to say that I
want to have a "generic external data container" type in my language
terms, which I can instantiate in multiple different ways (in the same
program), with data handled in different modules, without having to
change the 'generic' data-structure everytime I add a new module.
Polymorphic variants of course come to mind - but they would force me to
add a new type parameter to all my types, which I would rather avoid. I
would be quite happy to use polymorphic variants if I could 'hide away'
the extra type parameter involved with open variants. My attempts at
hiding this parameter (with existentials) has been too successful, in
that once hidden I can't extract my data from this container anymore
[which is the correct behaviour for the compiler].
I thought of using objects too, but my data does not really have any
common structure, so the object would be a pure container. I cannot see
any advantage over polymorphic variants, and all the same headaches of
an 'extra' polymorphic parameter remain.
Jacques
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Typing Dynamic Typing in ocaml?
2008-12-17 19:45 Typing Dynamic Typing in ocaml? Jacques Carette
@ 2008-12-17 19:58 ` Stéphane Glondu
2008-12-17 21:08 ` Jacques Carette
2008-12-17 20:29 ` Mikkel Fahnøe Jørgensen
` (3 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Stéphane Glondu @ 2008-12-17 19:58 UTC (permalink / raw)
To: Jacques Carette; +Cc: OCaml
Jacques Carette a écrit :
> I have two (related) questions:
> 1) Has anyone transcribed the TypeRep library into ocaml?
> http://people.cs.uu.nl/arthurb/dynamic.html
>
> 2) How do I embed 'dynamically known' data into a single ocaml
> data-structure?
> [...]
You might be interested by the following:
http://gforge.inria.fr/plugins/scmsvn/viewcvs.php/trunk/lib/dyn.ml?rev=5920&root=coq&view=markup
HTH,
--
Stéphane
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Typing Dynamic Typing in ocaml?
2008-12-17 19:45 Typing Dynamic Typing in ocaml? Jacques Carette
2008-12-17 19:58 ` [Caml-list] " Stéphane Glondu
@ 2008-12-17 20:29 ` Mikkel Fahnøe Jørgensen
2008-12-17 21:28 ` David Teller
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Mikkel Fahnøe Jørgensen @ 2008-12-17 20:29 UTC (permalink / raw)
To: Jacques Carette; +Cc: OCaml
Hi Jacques
> written in ocaml). I would like to be able to use arbitrary ocaml
> data-structures to represent some of my terms, when these terms are known to
> come from specific theories. For example, I would like to use Bigint to
> represent integers, but without exposing that per se.
I'm not really sure I understand exactly what problem you are trying
to solve. But if it is flexible dynamic data structure that can
optionally be associated with a type tag you can take a look at the
source Symbiosis implementation
http://dvide.com/labs/symbiosis/
http://git.dvide.com/pub/symbiosis/tree/myocamlbuild_config.ml
Most of this code is a java script object parser (JSON) which
generates an mostly untyped JSON object tree of lists and maps, but
still has basic float, int and string types.
The actual Symbiosis logic is a thin layer on top of this to access
different configuration logic.
One interesting part of this is the object navigation: each node is
represented as <node, pos> where node is one of the basic JSON types.
Any navigation into the JSON tree results in a new position, but the
position remains separate from the tree. Whenever an expected value is
not found, an exception is thrown and the position is used to report
the error location.
In some sense this attached position corresponds to dynamic type
information. You could view navigation as a computation and attach
type. For example matrix multiplying two JSON lists and attached the
resulting dimensions to the resulting JSON object tree.
I guess this can also be formulated as a monad somehow.
Perhaps this can be of some inspiration, or perhaps it is a different
problem you are trying to solve.
Regards,
Mikkel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Typing Dynamic Typing in ocaml?
2008-12-17 19:58 ` [Caml-list] " Stéphane Glondu
@ 2008-12-17 21:08 ` Jacques Carette
2008-12-17 21:15 ` Stéphane Glondu
2008-12-17 21:15 ` Daniel Bünzli
0 siblings, 2 replies; 9+ messages in thread
From: Jacques Carette @ 2008-12-17 21:08 UTC (permalink / raw)
To: Stéphane Glondu; +Cc: OCaml
Stéphane Glondu wrote:
>> 2) How do I embed 'dynamically known' data into a single ocaml
>> data-structure?
>> [...]
>
> You might be interested by the following:
> http://gforge.inria.fr/plugins/scmsvn/viewcvs.php/trunk/lib/dyn.ml?rev=5920&root=coq&view=markup
>
Scarily enough, I do believe that that is exactly what I need. I guess
I was hoping to avoid Obj, but this may be one of those instances where
it is indeed the most reasonable compromise.
Jacques
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Typing Dynamic Typing in ocaml?
2008-12-17 21:08 ` Jacques Carette
@ 2008-12-17 21:15 ` Stéphane Glondu
2008-12-17 21:15 ` Daniel Bünzli
1 sibling, 0 replies; 9+ messages in thread
From: Stéphane Glondu @ 2008-12-17 21:15 UTC (permalink / raw)
To: Jacques Carette; +Cc: OCaml
Jacques Carette wrote:
>> You might be interested by the following:
>> http://gforge.inria.fr/plugins/scmsvn/viewcvs.php/trunk/lib/dyn.ml?rev=5920&root=coq&view=markup
>>
> Scarily enough, I do believe that that is exactly what I need. I guess
> I was hoping to avoid Obj, but this may be one of those instances where
> it is indeed the most reasonable compromise.
BTW, I forgot to mention that the .mli is also important.
Cheers,
--
Stéphane
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Typing Dynamic Typing in ocaml?
2008-12-17 21:08 ` Jacques Carette
2008-12-17 21:15 ` Stéphane Glondu
@ 2008-12-17 21:15 ` Daniel Bünzli
1 sibling, 0 replies; 9+ messages in thread
From: Daniel Bünzli @ 2008-12-17 21:15 UTC (permalink / raw)
To: Jacques Carette; +Cc: OCaml List
Le 17 déc. 08 à 22:08, Jacques Carette a écrit :
> Scarily enough, I do believe that that is exactly what I need. I
> guess I was hoping to avoid Obj, but this may be one of those
> instances where it is indeed the most reasonable compromise.
Maybe not. Follow these pointers [1,2].
Best,
Daniel
[1] http://mlton.org/UniversalType
[2] http://ocaml.janestreet.com/?q=node/18
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Typing Dynamic Typing in ocaml?
2008-12-17 19:45 Typing Dynamic Typing in ocaml? Jacques Carette
2008-12-17 19:58 ` [Caml-list] " Stéphane Glondu
2008-12-17 20:29 ` Mikkel Fahnøe Jørgensen
@ 2008-12-17 21:28 ` David Teller
2008-12-17 22:42 ` Mauricio Fernandez
2008-12-18 1:16 ` Yaron Minsky
4 siblings, 0 replies; 9+ messages in thread
From: David Teller @ 2008-12-17 21:28 UTC (permalink / raw)
To: Jacques Carette; +Cc: OCaml
Have you look at Deriving and its Typing module?
On Wed, 2008-12-17 at 14:45 -0500, Jacques Carette wrote:
> I have two (related) questions:
> 1) Has anyone transcribed the TypeRep library into ocaml?
> http://people.cs.uu.nl/arthurb/dynamic.html
>
> 2) How do I embed 'dynamically known' data into a single ocaml
> data-structure?
--
David Teller-Rajchenbach
Security of Distributed Systems
http://www.univ-orleans.fr/lifo/Members/David.Teller
Latest News of French Research: System being liquidated. Researchers
angry.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Typing Dynamic Typing in ocaml?
2008-12-17 19:45 Typing Dynamic Typing in ocaml? Jacques Carette
` (2 preceding siblings ...)
2008-12-17 21:28 ` David Teller
@ 2008-12-17 22:42 ` Mauricio Fernandez
2008-12-18 1:16 ` Yaron Minsky
4 siblings, 0 replies; 9+ messages in thread
From: Mauricio Fernandez @ 2008-12-17 22:42 UTC (permalink / raw)
To: caml-list
On Wed, Dec 17, 2008 at 02:45:01PM -0500, Jacques Carette wrote:
> I have two (related) questions:
> 1) Has anyone transcribed the TypeRep library into ocaml?
> http://people.cs.uu.nl/arthurb/dynamic.html
>
> 2) How do I embed 'dynamically known' data into a single ocaml
> data-structure?
>
> More specifically, I am experimenting with a (new) language which allows
> deduction and computations to be performed with equal ease on its terms.
> This language uses ocaml has the host meta-language (ie the interpreter
> is written in ocaml). I would like to be able to use arbitrary ocaml
> data-structures to represent some of my terms, when these terms are known
> to come from specific theories. For example, I would like to use Bigint
> to represent integers, but without exposing that per se. Perhaps a
> better way to phrase this would be to say that I want to have a "generic
> external data container" type in my language terms, which I can
> instantiate in multiple different ways (in the same program), with data
> handled in different modules, without having to change the 'generic'
> data-structure everytime I add a new module.
Does this signature correspond to what you need? (This is a "property list",
typically used to decorate an AST in multiple passes.)
type 'a t
type ('a, 'b) property
val create : unit -> 'a t
val new_property : unit -> ('a, 'b) property
val get : 'a t -> ('b, 'a) property -> 'b option
val set : 'a t -> ('b, 'a) property -> 'b -> unit
Your data structure holds a 'a t value, and the different modules
declare their own properties (of different types, not reflected in the
property list).
Here's a fairly efficient implementation of mine:
type 'a t = (int, unit -> unit) Hashtbl.t
type ('a, 'b) property = {
set : 'b t -> 'a -> unit;
get : 'b t -> 'a option;
}
let create () = Hashtbl.create 13
let new_id : unit -> int =
let id = ref 0 in
fun () -> incr id; !id
let new_property () =
let id = new_id () in
let v = ref None in
let set t x =
Hashtbl.replace t id (fun () -> v := Some x) in
let get t =
try
(Hashtbl.find t id) ();
match !v with
Some x as s -> v := None; s
| None -> None
with Not_found -> None
in { set = set; get = get }
let set t p x = p.set t x
let get t p = p.get t
--
Mauricio Fernandez - http://eigenclass.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Typing Dynamic Typing in ocaml?
2008-12-17 19:45 Typing Dynamic Typing in ocaml? Jacques Carette
` (3 preceding siblings ...)
2008-12-17 22:42 ` Mauricio Fernandez
@ 2008-12-18 1:16 ` Yaron Minsky
4 siblings, 0 replies; 9+ messages in thread
From: Yaron Minsky @ 2008-12-18 1:16 UTC (permalink / raw)
To: Jacques Carette; +Cc: OCaml
[-- Attachment #1: Type: text/plain, Size: 2330 bytes --]
The following blog post might be of use.
http://ocaml.janestreet.com/?q=node/18
y
On Wed, Dec 17, 2008 at 2:45 PM, Jacques Carette <carette@mcmaster.ca>wrote:
> I have two (related) questions:
> 1) Has anyone transcribed the TypeRep library into ocaml?
> http://people.cs.uu.nl/arthurb/dynamic.html
>
> 2) How do I embed 'dynamically known' data into a single ocaml
> data-structure?
>
> More specifically, I am experimenting with a (new) language which allows
> deduction and computations to be performed with equal ease on its terms.
> This language uses ocaml has the host meta-language (ie the interpreter is
> written in ocaml). I would like to be able to use arbitrary ocaml
> data-structures to represent some of my terms, when these terms are known to
> come from specific theories. For example, I would like to use Bigint to
> represent integers, but without exposing that per se. Perhaps a better way
> to phrase this would be to say that I want to have a "generic external data
> container" type in my language terms, which I can instantiate in multiple
> different ways (in the same program), with data handled in different
> modules, without having to change the 'generic' data-structure everytime I
> add a new module.
>
> Polymorphic variants of course come to mind - but they would force me to
> add a new type parameter to all my types, which I would rather avoid. I
> would be quite happy to use polymorphic variants if I could 'hide away' the
> extra type parameter involved with open variants. My attempts at hiding
> this parameter (with existentials) has been too successful, in that once
> hidden I can't extract my data from this container anymore [which is the
> correct behaviour for the compiler].
>
> I thought of using objects too, but my data does not really have any common
> structure, so the object would be a pure container. I cannot see any
> advantage over polymorphic variants, and all the same headaches of an
> 'extra' polymorphic parameter remain.
>
> Jacques
>
>
>
> _______________________________________________
> 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: 3112 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-12-18 1:16 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-17 19:45 Typing Dynamic Typing in ocaml? Jacques Carette
2008-12-17 19:58 ` [Caml-list] " Stéphane Glondu
2008-12-17 21:08 ` Jacques Carette
2008-12-17 21:15 ` Stéphane Glondu
2008-12-17 21:15 ` Daniel Bünzli
2008-12-17 20:29 ` Mikkel Fahnøe Jørgensen
2008-12-17 21:28 ` David Teller
2008-12-17 22:42 ` Mauricio Fernandez
2008-12-18 1:16 ` Yaron Minsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox