全順序で任意のScalaタイプで機能する関数を作成したい(つまり、「<」を使用できる)。そのための構文は何ですか?私が思いついた最高のものは
def lessThan[T <: Ordered[T]](x: T, Y: T) = x < y
しかし、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))
基本的に、私はこのHaskellコードと同等のものが欲しいと信じています:
lessThan :: (Ord a) => a -> a -> Bool
lessThan x y = x < y
Debianシステムでscala2.7.3を使用しています。
何が欠けているのか、どこにあるのか?