Advertisement
norswap

SO Answer 1

Mar 8th, 2012
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 0.80 KB | None | 0 0
  1. Answer to Tomasz Nurkiewicz @ http://stackoverflow.com/questions/9619416/scala-implictly-convert-a-list
  2.  
  3. You only move the problem to the call site :/
  4.  
  5. As for elegance, I am interested in your opinion. The context is that I am building a compiler and have a mapping between identifiers and "identifiable objects" such as variables and types. So I have an Identifiable class and Variable, Type subclasses. When I lookup and identifier, I sometimes want to get a Type, sometimes a Variable. What I do is define implicit conversion from Identifiable to the subclasses, which check the types with "isInstanceOf". In case of mismatch (e.g. I get a variable when I want a type) I throw an exception, which will be caught upstream and converted to a compile error.
  6.  
  7. Do you think there's a more elegant way to do this ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement