[Ur] common type for different functor instantiations

Gergely Buday gbuday at gmail.com
Wed Nov 2 05:10:02 EDT 2011


Adam wrote:

> It _is_ suspicious that you seem to be writing a functor designed only to be
> used on one of three arguments.  I'd consider using polymorphism to permit
> the functor to work in more cases, even if you only plan to apply it to
> three known arguments.

This is indeed reasonable, but I have a problem, probably I do not
understand your thought fully.

Let me have a functor, where I provide polymorphism by having a free
type argRecord in the argument signature:

datatype generalRecord = ...

functor myFunctor(
  sig
    type argRecord
  end)
  : sig
      ...
      getRecord : data -> generalRecord
      computeXml : generalRecord -> generalRecord -> xbody
    end

You suggest that, if I want to have a generic record type which can be
used at any functor instantiation, even cross-instantiation

 I1 = myFunctor(A1)
 I2 = myFunctor(A2)

r = I1.getRecord
...

rOld <- get rStore;
xml = I2.computeXml rOld r

then I should define it outside of the functor. But how can I give a
general type for the record if I do not know the arguments in advance?
What am I missing here? Even moving computeXml out of the functor
would not solve the problem.

- Gergely



More information about the Ur mailing list