[Ur] Structure within let
Adam Chlipala
adamc at csail.mit.edu
Thu Nov 9 08:19:12 EST 2017
Matt's response is longer than I had planned! My answer was:
1) Ur/Web doesn't support module definitions anywhere inside expressions.
2) It's actually quite intricate to get the typing and run-time behavior
right if adding such a feature. OCaml only added support for it in the
last few years, I believe.
On 11/09/2017 06:12 AM, Matt Rice wrote:
> Hi, i'm certainly no good at urweb, but hopefully i can shed some light on this
> First a little bit of history:
>
> traditionally, e.g. in SML "let" works on expressions, e.g. let expr
> in expr end,
> while structure, is a form of declaration.
>
> There exists in SML, a let-esque variation which works on declarations, "local",
> where the syntax is "local dec in dec end".
>
> however with the advent of the module system, this has largely gone
> out of favor.
> with the advent of "ascription", (transparent, or opaque), There is a
> chapter on this in a sml book here:
> http://www.cs.cmu.edu/~rwh/isml/book.pdf#chapter.20
> ascription (also sometimes called sealing, or structural subtyping)
>
> from what I can tell ur/web drops support for the old "local" syntax,
> But still we can use signature ascription to hide structures like the
> "structure AB" within another structure.
> E.g, we have to flip it around somewhat from hiding with
> expressions/scoping to hiding within declarations.
> This appeared to compile, hopefully it works.
>
> structure Mymaths = struct
> functor Make (M : sig val callback : string -> transaction {} end)
> : sig val simple : string -> transaction string end
> = struct fun simple x = M.callback x; return x end
> end
>
> signature CALLABLE =
> sig
> val callMe : unit -> transaction unit
> end
>
> structure Callable : CALLABLE = struct
> fun debugMe a =
> alert a
>
> structure AB = Mymaths.Make(struct val callback = debugMe end)
>
> fun callMe() =
> x <- AB.simple "test";
> debug x
> end
>
> fun main()=
> return <xml>
> <body>
> <h1> Sample </h1>
> <button value="Click Me" onclick={fn _ =>
> Callable.callMe()}></button>
> </body>
> </xml>
>
> On Thu, Nov 9, 2017 at 1:10 AM, Nitin Surana <nsurana at usc.edu> wrote:
>> Hi
>>
>> I'm trying to define a structure within let block but it fails. Having the
>> structure outside works perfectly fine.
>>
>> sample.ur
>>
>> fun main()=
>> let
>>
>> fun debugMe a =
>> alert a
>>
>>
>> structure AB = Mymaths.Make(struct
>> val callback = debugMe
>> end)
>>
>> fun callMe () =
>> x <- AB.simple "test";
>> debug x
>>
>> in
>> return <xml>
>> <body>
>> <h1> Sample </h1>
>> <button value="Click Me" onclick={fn _ => callMe()}></button>
>> </body>
>> </xml>
>> end
>>
>>
>> Above code throws compile error, where as the following code compiles & runs
>> fine :
>>
>> fun debugMe a =
>> alert a
>>
>> structure AB = Mymaths.Make(struct
>> val callback = debugMe
>> end)
>>
>> fun main()=
>> let
>> fun callMe () =
>> x <- AB.simple "test";
>> debug x
>>
>> in
>> return <xml>
>> <body>
>> <h1> Sample </h1>
>> <button value="Click Me" onclick={fn _ => callMe()}></button>
>> </body>
>> </xml>
>> end
>>
>>
>> Any idea what's going wrong ? Can't a structure be created within let ? If
>> no, then is there an alternative ?
>>
>>
>> --
>> Regards
>> Nitin Surana
>> MS Computer Science
More information about the Ur
mailing list