Chcę napisać funkcję, która działa na dowolnym typie Scala z całkowitym uporządkowaniem (tzn. Mogę użyć "<" na nim). Jaka jest to składnia? Najlepsze, co wymyśliłem, to
def lessThan[T <: Ordered[T]](x: T, Y: T) = x < y
To jednak nie działa, gdy próbuję go używać z REPL:
scala> lessThan(1, 2)
<console>:8: error: inferred type arguments [Int] do not conform to method lessThan's type parameter bounds [T <: Ordered[T]]
lessThan(1, 2)
^
scala> import runtime._
import runtime._
scala> lessThan(new RichInt(1), new RichInt(2))
<console>:8: error: inferred type arguments [scala.runtime.RichInt] do not conform to method lessThan's type parameter bounds [T <: Ordered[T]]
lessThan(new RichInt(1), new RichInt(2))
Zasadniczo, myślę, że chcę odpowiednik tego kodu Haskella:
lessThan :: (Ord a) => a -> a -> Bool
lessThan x y = x < y
Używam scala 2.7.3 na systemie Debian.
Czego mi brakuje i gdzie?