Contains metadata extracted from apply
method of companion object of some record (case-class like) type.
Contains metadata extracted from apply
method of companion object of some record (case-class like) type.
symbol of the apply
method parameter or case class constructor parameter
(if apply
is auto-generated for case class companion object)
tree that evaluates to default value of the apply
parameter or EmptyTree
tree that evaluates to type class instance for type of this parameter
Contains metadata extracted from one of the case subtypes in a sealed hierarchy.
Contains metadata extracted from one of the case subtypes in a sealed hierarchy.
the case subtype itself
tree that evaluates to type class instance for this subtype
Derives type class instance for record type.
Derives type class instance for record type. Record type is a class/trait whose companion object has
matching apply
and unapply
methods. In particular, every case class is a proper record type.
the record type
symbol of the apply
method in companion object
symbol of the unapply
method in companion object
metadata for parameters of apply
method
Derives type class instance for union type (sealed hierarchy in which every non-abstract subtype has the type class instance of its own or can also be automatically derived).
Derives type class instance for union type (sealed hierarchy in which every non-abstract subtype has the type class instance of its own or can also be automatically derived).
type of the sealed class/trait
metadata for all direct non-abstract subtypes of this sealed class/trait
Derives type class instance for singleton type (i.e.
Derives type class instance for singleton type (i.e. an object
or this
)
the singleton type
a tree that evaluates to the sole value of the singleton type
Derives type class instance for arbitrary type which is neither a singleton, record nor union type.
Derives type class instance for arbitrary type which is neither a singleton, record nor union type.
Usually, you want to throw a TypecheckException
to indicate that type class instance cannot be derived
for this type. You can use typecheckException method for this.
Returns tree that instantiates a "deferred instance" of this type class.
Returns tree that instantiates a "deferred instance" of this type class. Deferred instance
is a special implementation of the type class which implements the com.avsystem.commons.derivation.DeferredInstance
trait and wraps an another, actual instance of the type class and delegates all operations to that
wrapped instance. The wrapped instance itself is supplied later, by assigning a var available on the deferred
instance.
This is all necessary to handle automatic derivation for recursively-defined types like:
case class Tree(children: List[Tree])
EXAMPLE:
Let's assume a type class Traverser
defined like this:
trait Traverser[T] { def traverse(value: T): Unit } object Traverser { class Deferred[T] extends DeferredInstance[Traverser[T]] with Traverser[T] { def traverse(value: T) = underlying.traverse(value) } implicit def forList[T](implicit forElement: Traverser[T]): Traverser[List[T]] = new Traverser[List[T]] { def traverse(value: List[T]) = value.foreach(forElement.traverse) } }
Automatically derived type class instance for Tree
would then look somewhat like this:
val tcTree: Traverser[Tree] = { val deferred: DeferredInstance[Traverser[Tree]] with Traverser[Tree] = new Traverser.Deferred[T] deferred.underlying = new Traverser[Tree] { val forChildren = Traverser.forList[Tree](deferred) def traverse(value: Tree) = value.children.foreach(forChildren.traverse) } deferred.underlying }
Returns a Tree
that should typecheck to the type passed as argument (without using TypeTree
).
Returns a Tree
that should typecheck to the type passed as argument (without using TypeTree
).
A tree that represents type constructor of the type class to be derived.
A tree that represents type constructor of the type class to be derived.
Human-friendly name of the type class.
Human-friendly name of the type class. Used in error messages.
Wraps the tree that evaluates to some instance of the type class into a tree that evaluates to an "auto" version of this type class.
Wraps the tree that evaluates to some instance of the type class into a tree that evaluates to an "auto" version of this type class.
Author: ghik Created: 10/12/15.