On Mon, Apr 27, 2015 at 08:54:11AM -0700, Kevin Meredith wrote:
> Could this check be handled at compile-time? If so, how would you do it?
Hi Kevin,
In cases where the user instantiates JetDim with a constant value (for
example JetDim(3)), we could perform the check at compile-time.
In the general case (JetDim(x)) we cannot.
I think the right way to do this would be to create a macro which
expands into either the constructor call (if the constant is checked
and ok), a compile error (if the constant is checked and bad), or a
run-time check and constructor call (if the argument is not a
constant).
If the machinery were simple (or reusable) it would be nice to allow
these kind of compile-time checks in other places as well.
One thing to keep in mind is that the constructor itself probably
can't be a macro, so you'll need to write a factory constructor on the
JetDim companion object.
> Note - I'm asking for my own learning. Once I finish the ScalaCheck work
> (on Jet now), I'd be interested to work on this if that's OK.
You should definitely feel free to work on this.
I think it's important not to complicate the API too much, so we may
need to go through several iterations before we end up with something
that we can merge. But it's a great project to work on.
Thanks!
-- Erik