dimitriv / Ziria

A domain-specific-language and compiler for low-level bitstream processing.
92 stars 18 forks source link

Length polymorphism in Comp language? #86

Open edsko opened 9 years ago

edsko commented 9 years ago

The following program does not type check:

fun comp f(a : arr int) {
  emit length(a);
}

fun comp test() {
  a <- take;
  emit a;
  f({1});
  f({1, 2});
} 

let comp main = read[int] >>> test() >>> write[int];

Do we not support length polymorphism in the comp language? (There is a TODO in the type checker code for this, too.)

edsko commented 9 years ago

This affects typechecking of map, too.

dimitriv commented 9 years ago

Yes, at the moment we don't support length-polymorphism at the computation level. We never needed it really so far, so I never bothered implementing (contrary to the expression-level polymorphism which turned out to be useful for @bradunov). But maybe it's actually not hard to implement now given all our refactorings? I would also not mind leaving this for later if there are more important things (e.g. optimization cleanup in PassFold, or the partial evaluator) in flux.

edsko commented 9 years ago

Let's talk about this later. There's a long email for you in my draft folder :)

edsko commented 9 years ago

Note that even if we say that comp functions cannot be length polymorphic, we should probably still deal with length polymorphic expression functions when they are called from the comp language (for instance, when they appear as a call to map).