Class

edu.tum.cs.isabelle.Codec

Variant

Related Doc: package Codec

Permalink

abstract class Variant[A] extends Codec[A]

Template for a codec for a sum type A.

Each constructor of A should get assigned a unique index when implementing this class. It is used to tag XML trees, so that the correct decoding function can be chosen.

In addition to the contract of Codec, instances of this class must also preserve the index, that is, any index returned by enc must produce a valid decoding function in dec.

Using this is simple: Instead of creating a new Codec object, create an object extending from this class and implement enc and dec accordingly. It is automatically a Codec.

Example usage

new Variant[Option[A]]("option") {
  def enc(a: Option[A]) = a match {
    case Some(a) => (0, Codec[A].encode(a))
    case None    => (1, Codec[Unit].encode(()))
  }
  def dec(idx: Int) = idx match {
    case 0 => Some(Codec[A].decode(_).right.map(Some.apply))
    case 1 => Some(Codec[Unit].decode(_).right.map(_ => None))
    case _ => None
  }
}
Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Variant
  2. Codec
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Variant(tag: String)

    Permalink

Abstract Value Members

  1. abstract def dec(idx: Int): Option[(Tree) ⇒ XMLResult[A]]

    Permalink

    Given an index, produce the corresponding decoding function or nothing if the index is out of bounds.

    Given an index, produce the corresponding decoding function or nothing if the index is out of bounds.

    Attributes
    protected
  2. abstract def enc(a: A): (Int, Tree)

    Permalink

    Encode a value of the sum type into a tree and the index.

    Encode a value of the sum type into a tree and the index.

    Attributes
    protected

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def decode(tree: Tree): Either[(String, List[Tree]), A]

    Permalink

    Decode a value from an XML tree, or produce an error.

    Decode a value from an XML tree, or produce an error.

    Definition Classes
    VariantCodec
    See also

    XMLResult

  7. def encode(a: A): Tree

    Permalink

    Encode a value into an XML tree.

    Encode a value into an XML tree.

    You may want to use one of the two constructors elem and text.

    Definition Classes
    VariantCodec
  8. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. def list: Codec[List[A]]

    Permalink

    Codec for a list of Ts, tagged with the string list.

    Codec for a list of Ts, tagged with the string list.

    Definition Classes
    Codec
  15. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. def ptransform[U](f: (A) ⇒ Option[U], g: (U) ⇒ A): Codec[U]

    Permalink
    Definition Classes
    Codec
  19. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  20. def tagged(tag: String): Codec[A]

    Permalink

    Create an identical codec which adds (or expects, respectively) an additional top-level tag.

    Create an identical codec which adds (or expects, respectively) an additional top-level tag.

    The given tag can be anything acceptable as an XML attribute value, but should be globally unique. That is, no other codec should have the same tag. It is fine if there are multiple codecs for a type, as long as their tags are distinct, although that is not a requirement.

    Definition Classes
    Codec
  21. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  22. def transform[U](f: (A) ⇒ U, g: (U) ⇒ A): Codec[U]

    Permalink

    Transform a codec for a type T into a codec for a type U by applying one of the two specified conversions.

    Transform a codec for a type T into a codec for a type U by applying one of the two specified conversions.

    After creating a new instance using transform, it is recommended to add a new tag.

    Definition Classes
    Codec
  23. def tuple[U](that: Codec[U]): Codec[(A, U)]

    Permalink

    Codec for a pair of T and U, tagged with the string tuple.

    Codec for a pair of T and U, tagged with the string tuple.

    Definition Classes
    Codec
  24. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Codec[A]

Inherited from AnyRef

Inherited from Any

Ungrouped