info.hupel.isabelle.Codec

Variant

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
Codec[A], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Variant
  2. Codec
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Variant(tag: String)

Abstract Value Members

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

    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)

    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

    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: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

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

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

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

    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

  9. final def decodeOrThrow(tree: Tree): A

    Definition Classes
    Codec
  10. def encode(a: A): Tree

    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
  11. final def eq(arg0: AnyRef): Boolean

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

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

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

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

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

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

    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
  18. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  19. final def notify(): Unit

    Definition Classes
    AnyRef
  20. final def notifyAll(): Unit

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

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

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

    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
  24. def toString(): String

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

    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
  26. def tuple[U](that: Codec[U]): Codec[(A, U)]

    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
  27. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Codec[A]

Inherited from AnyRef

Inherited from Any

Ungrouped