0

What is Ceylon's idiom for indicating that a function is not implemented? I often want to see if a design will typecheck before going through the trouble of implementing all the functions. Presumably, this means having the body throw an error, which has type Nothing and can be assigned to any function. This is also useful for sharing example code when the implementation does not matter.

It looks like some people use UnsupportedOperationException from Java like this:

Integer add(Integer a, Integer b) {throw UnsupportedOperationException();}

But that is too verbose to tack onto a bunch of class methods. I am looking for something similar to Scala's cutely named ??? as in:

def add(a: Int, b: Int): Int = ???
drhagen
  • 8,331
  • 8
  • 53
  • 82

1 Answers1

3

Actually, nothing is a built-in top-level getter you can invoke:

Integer add(Integer a, Integer b) => nothing;

It may look like an object being returned, but it actually throws a runtime exception as soon it is reached.

drhagen
  • 8,331
  • 8
  • 53
  • 82
  • 1
    Yeah, this is good because it will throw an exception when it's evaluated, and the IDE slaps a warning on it that serves as a reminder to implement it later. – gdejohn Oct 25 '14 at 18:59
  • I just want to add that `nothing` isn’t primitive at all: it’s a normal value, [implemented in regular Ceylon](https://github.com/ceylon/ceylon.language/blob/1.1.0/src/ceylon/language/nothing.ceylon), and you could also write your own. (The *type* `Nothing` is “primitive”, though – the only type in the language that can’t be expressed in Ceylon.) – Lucas Werkmeister Jul 22 '15 at 17:46
  • @lucas.werkmeister thank you, I edited my answer to clarify that. – drhagen Aug 07 '15 at 21:18