HPInc / HP-Digital-Microfluidics

HP Digital Microfluidics Software Platform and Libraries
MIT License
2 stars 0 forks source link

Explicit type casting in macro language #245

Open EvanKirshenbaum opened 5 months ago

EvanKirshenbaum commented 5 months ago

If we add coordinates to the macro language (#243), we run into the problem that, even though it will be possible to convert from a coord to a pad, there will be situations in which we may want to be sure that we are talking about the pad rather than the coord. Similarly, we may want to be sure that we're talking about a pad rather than a drop that can convert to a pad.

Three situations spring to mind:

  1. If you declare a variable with local, the type is inferred from the expression, so you may get a type different from what you expect:
    local p = (0, 0);

    This isn't so bad with coord and pad, since you will be able to convert in either direction, but if you try it with a drop, you'll get a drop variable, which can't be assigned a pad.

  2. Similarly, if you introduce a variable in an interactive context, you might get the wrong type.
  3. If you try to pass in a parameter to a built-in that's overloaded for coord and pad (or, in the future, when we support overloading (#160)), you may get the wrong one.
    built-in-foo((1,1));

You can get around this by assigning to a variable whose type is explicit:

pad p = (1,1)
built-in-foo(p)

but it is probably worthwhile to be able to explicitly cast. The syntax I'm leaning toward is

built-in-foo((1,1) as a pad)
Migrated from internal repository. Originally created by @EvanKirshenbaum on Feb 11, 2023 at 4:55 PM PST.