Coming back to Scala after a spell writing Haskell, I've started using the type keyword to make my class definitions a bit more readable, eg:
type RestfulParams = Map[String, String]
def canonicalize(params: RestfulParams): String = { ... }
The trouble I've run into is that these type definitions need to live inside a class or object - they're not "first class citizens" like they are in Haskell. If I try to define a type outside of a class or object, I get a compiler expected class or object definition
.
My problem then is how to use these types across multiple classes and objects in a package? What I've done now seems quite ugly:
object RestfulTypes { type RestfulParams = Map[String, String] etc }
And then in another class file:
import utils.{RestfulTypes => RT}
def get(resource: String, params: RT.RestfulParams): String = { ... }
Is there a nicer way of doing this - and incidentally do the Scala gurus think it's a good thing or a bad thing that types can only be defined inside classes/objects?