Packages

trait RuleSet extends AnyRef

This trait abstracts over the various ways how the laws of a type class can depend on the laws of other type classes. An instance of this trait is called a rule set.

For that matter, we divide type classes into kinds, where the classes of one kind share the number of operations and meaning. For example, Semigroup, Monoid and Group all belong to the same kind. On the other hand, their additive variants also belong to a common kind, but to a different one.

Users of this trait should extend the outer trait Laws and create specialized subtypes for each kind of type class. (See DefaultRuleSet for an example.)

Consider this example hierarchy:

Semigroup
    |   \
 Monoid   AdditiveSemigroup
    |   \        |
 Group     AdditiveMonoid
        \        |
           AdditiveGroup
They all define their own laws, as well as a couple of parent classes. If we want to check the laws of AdditiveGroup, we want to avoid checking properties twice, i.e. do not want to check Monoid laws via Group and also via AdditiveMonoid.

To address this problem, we define the parent in the same kind as parent, and other parents as bases. In this example, the parent of AdditiveGroup is Group, and its only basis is Group. On the other hand, the parent of Group is Monoid, and it does not have any bases.

The set of all properties of a certain class is now defined as union of these sets:

  • the properties of the class itself
  • recursively, the properties of all its parents (ignoring their bases)
  • recursively, the set of all properties of its bases

Looking at our example, that means that AdditiveGroup includes the Monoid law only once, because it is the parent of its basis. The same laws are ignored by its parent AdditiveMonoid, hence no redundant checks occur.

Of course, classes can have multiple parents and multiple (named) bases. The only requirement here is that inside one kind, the identifier of a property is unique, since duplicates are eliminated. To avoid name clashes between different kinds, the names of properties pulled in via a basis are prefixed with the name of the basis.

For better type-safety, parents are only allowed to come from the same outer instance of Laws, whereas bases are allowed to come from anywhere.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. RuleSet
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def bases: Seq[(String, RuleSet)]
  2. abstract def name: String
  3. abstract def parents: Seq[RuleSet]
  4. abstract def props: Seq[(String, Prop)]

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def all: Properties

    Assembles all properties.

    Assembles all properties. For the rules, see RuleSet.

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  16. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  17. def toString(): String
    Definition Classes
    AnyRef → Any
  18. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped