Search code examples
smlfunctor

Can SML functors take non-structure arguments (Ullman 8.3.4)?


I just want to check my understanding here, I'm working through the functor chapter of Elements of ML Programming as a refresh and one of the problems requires writing a functor that "takes only an integer b as input." I can write a functor which is applied as follows:

structure HashFn100 = MakeHashFn(struct val i = 100 end);

but not

structure HashFn100 = MakeHashFn(100);

as the problem statement seems to imply. Is the wording confusing me and my current functor is correct or is there a way to apply a functor to a non-struct that I'm missing? Unfortunately this exercise does not have an answer in the solutions manual.


Solution

  • You can write

    structure HashFn100 = MakeHashFn(val i = 100)
    

    which is syntactic sugar for the first form you showed. The second isn't legal -- syntactically, a functor argument must either be a module (structure or identifier) or a sequence of declarations (as a shorthand for a structure).