9. 1. Introduction
2. Type Classes in Haskell
1. Single-parameter type classes
2. Common extensions
3. Implicits
1. Implicits in Scala
2. Implicits as the missing link
4. The CONCEPT Pattern
1. Concepts: type-class-style interfaces in OO
5. Applications and Comparison with Type Classes
1. Ordering concept
2. Abstract data types
3. Statically-typed printf
4. Type class programs are OO programs
10. 1. Advanced Uses of Type Classes
1. Associated types in GHC Haskell
2. Implicits and type members
3. Session types
4. Arity-polymorphic ZipWith in Scala
5. ZipWith using prioritised overlapping implicits
6. Encoding generalized constraints
7. Type theories using implicits
2. Discussion and Related Work
1. Real-world applications
2. Type classes, JavaGI and concepts
3. Generic programming in the large
3. Conclusion
11. 6.6 Encoding generalized constraint
sealed abstract class <:< [-S,+T ] extends (S => T)
implicit def conforms [A]: A <:< A = new (A <:< A) {
def apply (x : A) = x
}
trait Traversable[T ] {
type Coll[X ]
def atten [U ] (implicit w : T <:< Traversable[U ]): Coll[U ]
}
15. Equiv (数学的な意味での)同値関係
scaladocをコピペ
● A trait for representing equivalence relations. It is
important to distinguish between a type that can be
compared for equality or equivalence and a
representation of equivalence on some type. This trait is
for representing the latter.
● An equivalence relation is a binary relation on a type.
This relation is exposed as the equiv method of
the Equiv trait. The relation must be
http://en.wikipedia.org/wiki/Equivalence_relation
http://ja.wikipedia.org/wiki/同値関係
http://www.scala-lang.org/api/current/index.html#scala.math.Equiv
16. Equiv
1 reflexive: 反射律
equiv(x, x) == true for any x of type T.
2 symmetric: 対称律
equiv(x, y) == equiv(y, x) for any x and y of type T.
3 transitive: 推移律
if equiv(x, y) == true and equiv(y, z) == true,
then equiv(x, z) == true for any x, y, and z of type T
17. Ordering 順序付け可能な集合(?)
● A trait for representing total orderings. It is important to
distinguish between a type that has a total order and a
representation of total ordering on some type. This trait
is for the latter.
● A ordering is a binary relation on a type T that is also an
equivalence relation and partial ordering on values of
type T. This relation is exposed as the compare method
of the Ordering trait.
http://en.wikipedia.org/wiki/Total_order
http://ja.wikipedia.org/wiki/順序集合
http://www.scala-lang.org/api/current/index.html#scala.math.Ordering
18. Ordering
This relation must be:
● reflexive: 反射律
x == x
● antisymmetric: 推移律
if x <= y && y <= x, then x == y
● transitive: 反対称律
if x <= y && y <= z, then x <= z
19. PartialOrdering
● A trait for representing partial orderings. It is important
to distinguish between a type that has a partial order
and a representation of partial ordering on some type.
This trait is for representing the latter.
● A partial ordering is a binary relation on a type T that is
also an equivalence relation on values of type T. This
relation is exposed as the lteqmethod of
the PartialOrdering trait.
http://en.wikipedia.org/wiki/Partial_order
20. PartialOrdering
This relation must be:
● reflexive:反射律
lteq(x, x) == true, for any x of type T.
● anti-symmetric:反対称律
lteq(x, y) == true and lteq(y, x) == true
then equiv(x, y), for any x and y of type T.
● transitive:推移律
if lteq(x, y) == true and lteq(y, z) == true
then lteq(x, z) == true,
for any x, y, and z of type T.
21. Numeric 数値
Scaladoc何も書いてないェ・・・
抽象メソッド達↓
def plus(x: T, y: T): T
def minus(x: T, y: T): T
def times(x: T, y: T): T
def negate(x: T): T
def fromInt(x: Int): T
def toInt(x: T): Int
def toLong(x: T): Long
def toFloat(x: T): Float
def toDouble(x: T): Double