Methods can enforce more complex type bounds via implicit parameters. For example, List supports sum on numeric contents but not on others. Alas, Scala's numeric types don't all share a superclass, so we can't just say T <: Number. Instead, to make this work, Scala's math library defines an implicit Numeric[T] for the appropriate types T. Then in List's definition uses it:
Read full article from Scala School - Advanced types
No comments:
Post a Comment