|
From: Matthew F. <mat...@gm...> - 2025-07-24 12:57:25
|
Arnav,
Yes, in SXML ("Simply-typed" XML), there is no polymorphism whatsoever (for
functions or datatypes) and type parameters that do not contribute to the
representation of a datatype will have been eliminated.
Actually, the SimplfyTypes (http://mlton.org/XMLSimplifyTypes) XML
optimization will have already eliminated these unused type parameters,
before monomorphisation. The motivation for SimplifyTypes is to avoid code
duplication by monomorphisation that is unnecessary, due to type parameters
that may be present for high-level API reasons, but do not affect the
dynamics because they do not influence the data representation.
It may be that if you drop SimplifyTypes (compile with `-drop-pass
xmlSimplifyTypes`), then monomorphisation will force different "versions"
of your tagged datatypes to be separately monmorphised, though with the
current heuristics for naming monomorphised variants, you probably won't
get any evidence of the `zero` or `succ` type parameters remaining in the
SXML program.
Could you say a bit more about your goals? That might help to inform
whether there is a better way to accomplish what you are trying to do.
-Matthew
On Thu, Jul 24, 2025 at 5:24 AM Arnav Sabharwal <arn...@an...>
wrote:
> Hello,
>
> I'm trying to tag every instance of a recursive type in a type definition
> with a tag. This tag is essentially a "type-level natural number". By way
> of example, here's what I mean:
>
> datatype zero = Zero
> datatype 'n succ = Succ
>
> (* example: rose tree *)
> datatype ('tree, 'list) rose_tree = Node of int * ('list, 'tree) rose_list
> and ('list, 'tree) rose_list = Nil | Cons of int * ('tree, 'list) rose_list
>
> (* example: tree with int list data *)
> datatype 'list my_list = Nil | Cons of int * 'list my_list
> and ('tree, 'list) my_tree = Leaf | Node of ('tree, 'list) my_tree * 'list my_list * ('tree, 'list) my_tree
>
> As seen, each type is given as many type parameters as is necessary to
> instantiate its own tag as well as the tags of its "recursive
> sub-structures". The first type argument is meant for the tag of the
> recursive type currently being defined.
>
> Now, when I use MLton to compile this, the tag types seem to be removed
> during monomorphization. Thus,
>
> (zero, zero succ) rose_tree
> and
>
> (zero succ succ, zero succ succ succ) rose_tree)
> appear to be the same type in SXML. What are my options here, if I'd like
> to maintain such a type level distinction? Is XML necessarily the furthest
> down I can go in the compiler pipeline? I'd greatly appreciate some advice
> here!
>
> Thank you,
> Arnav.
> ,
>
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mlt...@ml....
> _______________________________________________
> MLton-user mailing list
> MLt...@li...; mlt...@ml...
> https://lists.sourceforge.net/lists/listinfo/mlton-user
>
To unsubscribe from this group and stop receiving emails from it, send an email to mlt...@ml....
|