Closed j14159 closed 6 years ago
You cannot do this in Elm or OCaml because all unions must be explicitly qualified, e.g.
type expr = int_exp | float_exp | string_exp | symbol
Is invalid - you'd have to write something like:
type expr = IntExpr of int_expr | FloatExpr of float_expr (* etc *)
If the line
was outside the symbol, say as part of a tuple, you could have a generic function that takes a two-tuple, something of type:
fn (symbol, int) -> int
As far as I'm aware none of the MLs with ADTs support this sort of construct. Perhaps it could be achieved with typeclasses but you'd still need to extract the data for each union first in a pattern match or some such.
Makes sense to me, thanks. Maybe leaving the type error in place is better than trying to satisfy that union.
Excerpt from an Alpaca-native AST that demonstrates the unification failure:
This will fail, reporting that the typer cannot unify
int_exp
andfloat_exp
. I'm reasonably certain that this is happening becausealpaca_typer:unify_adt/6
sees two different ADTs, the only thing it tries to do is see if one fits inside of the other. In principle this shouldn't be too hard to fix but there might be performance considerations.Things I don't know yet:
type t = int | float
as checking unions/sums like the above example could get expensive.