[Ur] using argument's field name in a functor signature

Adam Chlipala adamc at impredicative.com
Fri Oct 21 08:42:28 EDT 2011


Gergely Buday wrote:
> I have the following error message for the following code. The problem
> is with the M.fieldName. Is it not allowed to use a long identifier
> for a field name in functor signature? The functor implementation is
> clearly wrong, that is just to have a full functor definition.
>    

I hadn't documented a limitation in the parser, affecting how field 
names within record literals may be written.  I just added a note about 
that.  In particular, projections from modules are not allowed.  (I 
can't figure out how to make ml-yacc accept such terms without breaking 
parsing of other forms.)

Here is a (not entirely satisfactory, but not crazy either) "fix" that 
gets your code to parse:

functor DummyF (M : sig
                     con fieldName :: Name
                 end) :
         sig
         con fieldName = M.fieldName
             val foo : {} -> $(mapU {fieldName : int} roles)
         end = struct
             con fieldName = _
             fun foo () = 2
         end

Or, a version with more up-front cost, but that scales better to mention 
of more field names from [M]:

signature S = sig
     con fieldName :: Name
end

functor DummyF (M : S) :
         sig
         include S
             val foo : {} -> $(mapU {fieldName : int} roles)
         end = struct
             open M
             fun foo () = 2
         end




More information about the Ur mailing list