[Ur] Combinator Parsing in Ur: Anonymous function remains at code generation

Adam Chlipala adamc at csail.mit.edu
Tue Jul 22 15:25:10 EDT 2014


On 07/22/2014 03:09 PM, orchidaceae phalaenopsis wrote:
> Sorry to say but I could not continue to build my BBCode parser, I
> added a new combinator:
>
> fun choice [a] (p : parser a) (q : parser a) : parser a =
>      fn input =>  case p input of
>                      Empty Failure =>  q input
>                    | Empty ok =>  (case q input of
>                                       Empty _ =>  Empty ok
>                                     | consumed =>  consumed)
>                    | consumed =>  consumed
>
> and
>
> val bbid : parser bbtag =
>      choice
>          (_<- char #"b" ; return B)
>          (_<- char #"u" ; return U)
>
> triggers the anonymous function problem.
>    

Can you point me to a full program demonstrating this problem?  I added 
your snippets to the version I sent before, in what seemed like the 
natural way, and a simple test case worked fine.

> Also to simulate lazy evaluation (which is essential in this parser),
> I will need to change
>
>      datatype consumed a = Consumed of reply a
>                          | Empty of reply a
>
> to delay the replies
>
>      datatype consumed a = Consumed of unit ->  reply a
>                          | Empty of unit ->  reply a
>
> later on. These are higher order objects that I don't think could be
> removed completely during compiling?
>    

Yes, you won't be able to use that sort of parser type in server-side 
code.  It should work fine in client-side code, though, just as your 
original example should work fine there, AFAIK.

Why do you want lazy evaluation?  Can you give a minimal example 
demonstrating the need?



More information about the Ur mailing list