I'm working on a project that has a lot code that looks like this:
structure MyStruct = struct
datatype node
= A of Foo.t
| B
type t = node Wrap.t
fun layout myNode =
case node myNode of
A foo => Foo.bar foo
| B => "void"
end
Wrap
is defined elsewhere, but the main point is that it has one parametrized type, t
.
What is node
doing in the line case node myNode of
? It's not a type constructor, since t
isn't a type, and changing it to case (node myNode)
throws an error message for that reason. Additionally, if I write functions that look like this:
fun layout node myNode = ...
I get a type error because it doesn't have the type MyStruct.t -> Layout.t
but rather 'a -> MyStruct.node -> Layout.t
. If I do the same thing inside of a case statement, however, it's fine.
What's going on here?
There must be some function named node
defined in the program, whose type is u -> node
, for some u
. That function is applied here. From that, the layout
function then is simply inferred to have type u -> string
.