When you're declare your structure, you're doing so using opaque signature matching (:>
).
What opaque signature matching means is, the underlying type behind any types declared inside of the structure is hidden.
You can use transparent signature matching (:
) if you don't wish for this to be the case.
Example with transparent signature matching:
structure Stack : STACK = struct
type 'a stack = 'a list
end;
Before you do this, consider the advantages of not doing so: If you use opaque signature matching, the underlying implementation is hidden. If you wish to change the underlying implementation (to a tree structure, for instance), you could do so knowing that nothing outside of the structure can use any other functions than the ones you provide.
You may wish to instead provide a toList
and fromList
function to perform the conversion:
(* in the signature *)
val toList : 'a stack -> 'a list
val fromList : 'a list -> 'a stack
(* in your structure *)
fun toList s = s
fun fromList s = s
If you then change your underlying implementation, you would only have to change these two functions, rather than having to make changes all over your program.