|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
Questions about Equality of Code, CSP and StateHello, I have a few simple question about MetaOCaml. The first is
about equality of code. I get: # let x = .<2>. in x = x;; - : bool = true # .<2>. = .<2>.;; - : bool = false Why? For similar equation at function type MetaOCaml answers: # let f = (fun x -> x ) in f = f;; Exception: Invalid_argument "equal: functional value". # (fun x -> x ) = (fun x -> x );; Exception: Invalid_argument "equal: functional value". My second question concerns staging correctness and typing. The page http://okmij.org/ftp/Computation/Generative.html lists the following example: let code = let x = ref .<1>. in let _ = .<fun v -> .~(x := .<v>.; .<()>.)>. in !x;; It evaluates to: val code : ('a, int) code = .<v_1>. # .!code;; Unbound value v_1 Exception: Trx.TypeCheckingError. Why is this program allowed to typeckeck? Clearly CSP (cross-stage persistence) and state don't make easy bedfellows. Would ruling it out through some suitable restriction (along the lines of making state and polymorphism compatible) be too restrictive? Martin _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateDear Martin, Thank you for these questions. They are quite timely. I'm CC'ing the mailing list so that others can chime in as needed. On Thu, Jun 4, 2009 at 4:08 AM, Martin Berger <M.F.Berger@...> wrote: Hello, I have a few simple question about MetaOCaml. The first is Technically, code is an abstract type and so the equality test is of OCaml should not be defined. What you see above is exposing the underlying implementation (AST's) and testing equality on that. Ideally, it would be better if we can change the implementation so that it returns an error message if this type is compared for equality, in a way similar to what you illustrate below. # let f = (fun x -> x ) in f = f;; Cristiano/Ron: Would this change be easy enough for us to impelemnt? My second question concerns staging correctness and typing. The page Yes, this is the classic scope extrusion example, and it does behave this way in MetaOCaml. The classifier system, which is what MetaOCaml uses, is sound only in the purely functional setting. Why is this program allowed to typeckeck? Only because all alternatives were too heavy wait, and seemed impractical. Classifiers are very lightweight, but only ensure static type safety for the purely functional subset. Clearly CSP (cross-stage I don't see how CSP is implicated in this example. Would ruling it out This looks like it could be a new idea. Can you say a bit more about what you have in mind? Walid. Martin -- Walid Taha, Assistant Professor, Department of Computer Science and Department of Electrical and Computer Engineering Rice University, MS-1302, Duncan Hall 3103, Houston, TX 77025 Tel: (832) 528 5948. Fax: (832)645 0239 --- CONFIDENTIALITY NOTICE The information in this email may be confidential and/or privileged. This email is intended to be reviewed by only the individual or organization named above. If you are not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any review, dissemination or copying of this email and its attachments, if any, or the information contained herein is prohibited. If you have received this email in error, please immediately notify the sender by return email and delete this email from your system. _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
|
|
|
|
|
|
Re: Questions about Equality of Code, CSP and StateDear Martin, The type of scope extrusion that we have addressed in the recent Mint work arises when you have statically scoped next-stage code and imperative effects in the *current* stage. Any language that tries to guarantee static scoping for next-stage (and inevitably uses a kind of gensym to achieve static scoping) will suffer from that problem. Oleg is more familiar with TH than I, and can assert whether it uses gensym and allows state in the current (or first) stage. Whether or not you statically type the second stage is independent of the presence of the scope extrusion problem. As for expressivity, yes, a simple type discipline can limit what you can generate from *one* generator. However, if you have slightly more expressive types, such as indexed types, then you can write one generator that can generate all simply typed terms. Thus, you can have very expressive statically typed generators. This is the subject of both our Concoqtion paper and our "Tagless Staged Interpreters" paper. Now, if you really don't like types, then yes, any statically typed approach will not seem convenient. But if you want to be untyped (or dynamically typed as some people prefer to call such languages) and to avoid scope extrusion, you need to use something along the lines proposed in the mint paper. With respect to Converge, it really depends. If you are only allows to write DSL programs that contain no escapes (no possibility for static computation) then you are OK. And if you are only allowed to have escaped computation that is purely function, you should still be OK. But if you have escaped computation (and specifically, under binders), then I would expect that you can construct examples that would lead to scope extrusion. Walid. On Mon, Jun 8, 2009 at 8:33 AM, Martin Berger <M.F.Berger@...> wrote:
-- Walid Taha, Assistant Professor, Department of Computer Science and Department of Electrical and Computer Engineering Rice University, MS-1302, Duncan Hall 3103, Houston, TX 77025 Tel: (832) 528 5948. Fax: (832) 645 0239 --- CONFIDENTIALITY NOTICE The information in this email may be confidential and/or privileged. This email is intended to be reviewed by only the individual or organization named above. If you are not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any review, dissemination or copying of this email and its attachments, if any, or the information contained herein is prohibited. If you have received this email in error, please immediately notify the sender by return email and delete this email from your system. _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateMartin Berger <M.F.Berger@...> wrote in article <4A2D1322.5030809@...> in gmane.comp.lang.ocaml.meta.user:
> I have a question about the relationship between these typing systems > and the mechanisms Converge (http://convergepl.org) and Template Haskell > use to avoid such scope extrusion. It appears to me that these languages > do essentially the same thing in regard to avoiding inappropriate scope > extrusion, namely a program analysis on (essentially) the whole > program after parsing. (The TH paper [2] by Sheard and Peyton Jones is > unclear on this issue; a description of the Converge mechanism > can be found in [1]). This seems to be much more expressive than > using types (or at least the types that have been proposed) and > less intrusive. To echo what Walid said: it depends on what you mean by "expressive". If you measure expressivity by how many programs can be generated and how short their correct generators can be, then nothing beats good old printf. Another notion of expressivity (followed more by, e.g., Dussart & Thiemann, Calcagno, Moggi, Nielsen & Taha, and Kameyama, Kiselyov & Shan) is to balance what programs you can generate and how short their correct generators are against what safety properties can be guaranteed for the generated code before running the generator. For example, I am not familiar with Converge, but Template Haskell does not guarantee before running a generator that the generator will only generate well-formed code. -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig We want our revolution, and we want it now! -- Marat/Sade We want our revolution, and we'll take it at such time as you've gotten around to delivering it -- Haskell programmer _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateHello Chung-chieh!
> To echo what Walid said: it depends on what you mean by "expressive". > As far as I can see, neither Converge nor Template Haskell [...] > instead they are much more limited in the kinds of staging they > support with static scoping. You rise a very interesting question, that of expressivity in metaprogramming languages. In what sense precisely are some metaprogramming languages more expressive than others? Has the question of metaprogramming expressivity been studied formally? > but Template Haskell does not guarantee before running a generator > that the generator will only generate well-formed code. That's right, but since generated code will have to be compiled before execution, only well-typed code will ever be executed. (The scope-extrusion problem discussed in previous mails suggests that MetaOCaml's typing system cannot guarantee to generate only well-formed code either.) The TH approach (also found in C++ and Converge) where splicing in code happens at compile time, and the approach of the MetaML family of languages, where this is under program control, are two seemingly fundamentally different approaches with -- presumably -- different strengths and weaknesses. It would be interesting to have clearcut formal results on the expressive power of these approaches. Martin _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
|
|
|
|
|
|
|
|
|
Re: Questions about Equality of Code, CSP and StateOn 2009-06-13T13:39:56+0100, Martin Berger wrote:
> I agree that having a few annotations to ensure type-inference is > not a big deal. My question is more that I don't expect these > typing systems to scale when more involved forms of metaprogramming > are needed (like where you can splice in declarations, which you can > do in Converge). MetaOCaml (even just its functional fragment) can already splice in declarations of values (using let). > From the discussion here it seems to me now that there are two forms > of metaprogramming, which are (or appear to be) quite different. As > I'm new to the field of metaprogramming, it may appear naive to you, > or it might be wrong, in which case please correct my misconceptions. I don't understand the difference between the two forms because, for example, MetaOCaml can perfectly well be used to increase expressivity by splicing (a metaprogramming construct). Your description of the two forms mentions "a program P" and a distinction between "compile time" and "run time". Can P be a compiler, which takes a program x as input? What is the difference between compile time and run time (especially in the setting of Futamura projections)? I don't know how to tell "normal compilation" from abnormal compilation. -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig We want our revolution, and we want it now! -- Marat/Sade We want our revolution, and we'll take it at such time as you've gotten around to delivering it -- Haskell programmer _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateHello!
> MetaOCaml (even just its functional fragment) can already splice in > declarations of values (using let). Sorry, I meant type declarations, as in: let t = <int -> int> in let x = <lambda x : ~t. x3> in ... I'll answer to the rest of your mail when I get some time to think about it. Martin _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateMartin Berger wrote:
> Sorry, I meant type declarations, as in: > > let t = <int -> int> in > let x = <lambda x : ~t. x3> in ... I (in conjunction with others) have written some large and complicated MetaOCaml code, and I have not really needed that [although I did naively wish for it several times]. Using Functors properly, you can indeed 'generate' most of the dynamic types you need in practice. The only types you cannot generate this way are truly "computed" types, which are quite naturally outside the scope of the present MetaOCaml. True, to get what you need inside the strict type discipline of MetaOCaml you need to think a lot harder than what you can get away with in other, unsafe languages. Once I trained myself out of my bad habits garnered from my days of undisciplined meta-programming, I came to really appreciate this ``better'' way of doing things. I am not saying you never need to generate types computationally, but it turns out to be fairly rare. The kinds of types that MetaOCaml lets you generate *via OCaml* are quite generous already! The error of a lot of programmers here seems to be that they use very little of O'Caml's power when structuring and building their code generators. Jacques _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateHello Jacques!
> I (in conjunction with others) have written some large and > complicated MetaOCaml code, and I have not really needed that > [although I did naively wish for it several times]. Using Functors > properly, you can indeed 'generate' most of the dynamic types you > need in practice. The only types you cannot generate this way are > truly "computed" types, which are quite naturally outside the scope > of the present MetaOCaml. That's interesting. Can you generate types for n-ary selectors (for arbitrary n)? What I mean by this something like fun (x1, x2, ..., xn ) -> xi using functors? Is it possible to generate types for printf-like constants where the types of the remaining arguments depend on the value of the first argument? Martin _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateHello Chung-chieh!
> I don't understand the difference between the two forms because, for > example, MetaOCaml can perfectly well be used to increase expressivity > by splicing (a metaprogramming construct). Consider the following example: you have 100 computers and on each you want to run a program P. Assume you use MetaOCaml to write P, because you find Ocaml lacks in expressivity. Maybe you need some try ... with ... finally construct. If you construct and embed such an extension statically (e.g. with OcamlP4), you will pay the price of reducing the extended language to Ocaml once, at compile-time. If you make this extension using MetaOCaml, you will pay for this 100 times. To be sure, semantically (assuming conventional lambda-theories), the two approaches are the same. > Your description of the two > forms mentions "a program P" and a distinction between "compile time" > and "run time". Can P be a compiler, which takes a program x as input? > What is the difference between compile time and run time (especially in > the setting of Futamura projections)? I don't know how to tell "normal > compilation" from abnormal compilation. My understanding of the partial evaluation in general, and the relationship between MetaML-like metaprogramming and the Futamura projections is immature, so I'm not sure about the answer to this question. I hope I will be able to answer in the future. Martin _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateMartin Berger wrote:
> Hello Jacques! > > > I (in conjunction with others) have written some large and > > complicated MetaOCaml code, and I have not really needed that > > [although I did naively wish for it several times]. Using Functors > > properly, you can indeed 'generate' most of the dynamic types you > > need in practice. The only types you cannot generate this way are > > truly "computed" types, which are quite naturally outside the scope > > of the present MetaOCaml. > > That's interesting. Can you generate types for n-ary selectors (for > arbitrary n)? What I mean by this something like > > fun (x1, x2, ..., xn ) -> xi > > using functors? Is it possible to generate types for printf-like > constants where the types of the remaining arguments depend on the > value of the first argument? I do not know how to do the n-ary selector (and I doubt that it is possible). I can do it for the Church encoding of that function though, which is just as good, since in a code generation setting you don't want needless boxing/unboxing. As for printf-like, yes, you can do that - you just need to write things in CPS. See Oleg's recent post in haskell-cafe for the core ideas (based on ideas of Olivier Danvy from a long time ago). Lifting that to a code generator is relatively straightforward. Of course, you need the first argument to be a compile-time constant to do that, but that's the case for almost all uses of printing. Jacques _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateHello Jacques!
> I do not know how to do the n-ary selector (and I doubt that it is > possible). I can do it for the Church encoding of that function > though, [...] As for printf-like, yes, you can do that - you just > need to write things in CPS. Aha, thanks, it's good to know that it can be done if necessary. I'm not sure I want normal programmers to use Church numberals or CPS though. I don't expect such complicated encodings in metaprogramming, which is already more complicated than normal programming, to have good large-scale software engineering properties. There is a reason why mainstream languages have a built-in type for numbers, rather than relying on Church numerals, and why CPS is not the default way of returning a result from a function. Martin _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateOn 2009-06-16T11:23:28+0100, Martin Berger wrote:
> I'm not sure I want normal programmers to use Church numberals or > CPS though. I don't expect such complicated encodings in > metaprogramming, which is already more complicated than normal > programming, to have good large-scale software engineering properties. > > There is a reason why mainstream languages have a built-in type > for numbers, rather than relying on Church numerals, and why > CPS is not the default way of returning a result from a function. Our PEPM 2009 paper addresses exactly this issue! http://www.cs.rutgers.edu/~ccshan/metafx/circle-shift.pdf By the way, out of curiosity -- may I ask what motivates your interest in code generation (especially imperative code generation)? -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig We want our revolution, and we want it now! -- Marat/Sade We want our revolution, and we'll take it at such time as you've gotten around to delivering it -- Haskell programmer _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateOn 2009-06-15T13:44:26+0100, Martin Berger wrote:
> If you make this extension using MetaOCaml, you will pay for this > 100 times. > > To be sure, semantically (assuming conventional lambda-theories), > the two approaches are the same. Are you somehow ruling out the following way to use MetaOCaml? Print out a generated code value, then compile the printout ("offshore the generated code") and run the result on 100 computers. -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig We want our revolution, and we want it now! -- Marat/Sade We want our revolution, and we'll take it at such time as you've gotten around to delivering it -- Haskell programmer _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
|
|
Re: Questions about Equality of Code, CSP and StateHello Chung-chieh!
> Are you somehow ruling out the following way to use MetaOCaml? Print > out a generated code value, then compile the printout ("offshore the > generated code") and run the result on 100 computers. That's a very interesting question. If it was possible to print out (or convert into a string) generated code, then indeed what you suggest would be possible. But I am under the impression that that MetaOCaml does not offer this conversion (please correct me if I'm wrong). Moreover, if it is possible, would not the equational theory of MetaOCaml be trivial, since we could now for example distinguish alpha-convertible terms. Martin _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@... https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |