Class

info.hupel.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
  3. abstract val mlType: String

    Permalink

    String representation of the type corresponding to T in Isabelle/ML.

    String representation of the type corresponding to T in Isabelle/ML.

    Definition Classes
    Codec

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. final def decodeOrThrow(tree: Tree): A

    Permalink
    Definition Classes
    Codec
  8. 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
  9. final def eq(arg0: AnyRef): Boolean

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

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

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

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

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

    Permalink
    Definition Classes
    Any
  15. 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
  16. final def ne(arg0: AnyRef): Boolean

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  21. 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
  22. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  23. def transform[U](f: (A) ⇒ U, g: (U) ⇒ A, mlType0: String): 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
  24. 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
  25. final def wait(): Unit

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

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

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

Inherited from Codec[A]

Inherited from AnyRef

Inherited from Any

Ungrouped