top | item 27965596

(no title)

galimaufry | 4 years ago

You're not wrong. I guess what I'd like is the ability to apply (up to) two type annotations, with the second one a subtype of the first, and use the first for dispatch and the second for documentation/testing/static analysis...

... which actually seems like it might be doable with some macros? Those are beyond my ken right now, but the goal would be

  @doubly_typed f(x::Number|Integer) = x
  f(6.0)            # Same as g(x::Number) = x; g(6.0)
  @strictify f(6.0) # Same as g(x::Integer) = x; g(6.0)
Then you would use @strictify when running tests to ensure that the stricter types in your codebase are all compatible. But you'd still need to figure out what to do about return types and the help command...

discuss

order

No comments yet.