# [MLton] Structures inside a function?

**Wesley W. Terpstra
**
terpstra@gkec.tu-darmstadt.de

*Wed, 19 Jan 2005 19:07:04 +0100*

Hi! I recently ran into a problem where I needed to use a structure inside a
function. However, this doesn't appear to be possible; what do I do instead?
Simplified problem:
signature RESIDUE_PARAM =
sig
structure Base: EUCLIDEAN_DOMAIN
val modulus: Base.t
end
functor Residue(P : RESIDUE_PARAM) : RING = ...
functor Math(R : RING) = ...
functor Factor(E : EUCLIDEAN_DOMAIN) =
struct
fun factor x =
let
structure R = Residue(struct structure Base = E val modulus = x)
structure M = Math(R)
open M
in
(* use various methods defined in Math to factor x *)
end
end
Normally, when you use a residue ring, it is a top-level construction.
Therefore, I haven't needed this before. However, I was implementing
Pollard's rho algorithm and then I suddenly needed a ring which was
parameterized by a function parameter!
I have run into this in several other places, but have always avoided
the problem. Here, I don't see any choice other than to redefine all the
methods I need from Math (lots) in local scope, which really sucks.
--
Wesley W. Terpstra