Packages

c

de.unruh.isabelle.mlvalue

AdHocConverter

abstract class AdHocConverter extends OperationCollection

This class allows to add support for Isabelle ML types in Scala in a quick ad-hoc way.

Let something be an ML type. To support values of ML type type in Scala, write

object Something extends AdHocConverter("something")

(Here Something is an arbitrary identifier that should preferably remind of the ML type something.) Then ML values of type something stored in the Isabelle process can be used in Scala as objects of type Something.T. That is, an Something.T is a thin wrapper around an MLValue that references values of type something. The actual ML value is never transferred from Isabelle.

An MLValueConverter is automatically available for type Something.T, thus, e.g., MLValue.apply and MLValue.retrieveNow and related functions work properly to translate between Something.T and MLValue[Something.T].

Note: This is only intended for local use. That is, if some Scala code needs to handle ML values for which there is no proper support, and that just need to be passed around between different ML functions, then it is possible to use this class for supporting them with minimal boilerplate. However, if the Scala types representing the ML values are supposed to be used on a larger scale or exported from a library, or are supposed to be extended, then it is recommended to use a more flexible mechanism such as MLValueWrapper for creating wrapper classes for ML values.

Note: object ... extends AdHocConverter(...) creates a new exception type in ML when it is created. Thus this declaration should only be used in a static context (toplevel/inside an object) or in classes that are instantiated very rarely (or in OperationCollection.Ops in a static object).

Usage example: Say we want to use the ML function Simplifier.pretty_simpset: bool -> Proof.context -> Pretty.T. This function returns a Pretty.T which is not (currently) directly supported by this library. But we simply want to pass it on to Pretty.unformatted_string_of: Pretty.T -> string. So we can declare

object Pretty extends AdHocConverter("Pretty.T")
val pretty_simpset = MLValue.compileFunction[Boolean, Context, Pretty.T]("Simplifier.pretty_simpset")
val unformatted_string_of = MLValue.compileFunction[Pretty.T, String]("Pretty.unformatted_string_of")

and then pretty print the simpset of a context ctxt by

val string : String = unformatted_string_of(pretty_simpset(false, ctxt).retrieveNow).retrieveNow

(Or without the first .retrieveNow.)

Source
AdHocConverter.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AdHocConverter
  2. OperationCollection
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new AdHocConverter(mlType: String)

    mlType

    The ML type for which to create a Scala wrapper type

    Attributes
    protected

Type Members

  1. class Ops extends AnyRef
    Attributes
    protected
  2. final class T extends FutureValue

    Represents an ML Value of ML type mlType.

    Represents an ML Value of ML type mlType. The representation of an ML value x as an exception (see explanations in MLValue) is EXN x where EXN is what exceptionName returns.

    An MLValue containing this can be obtained from mlValue. (Both this and mlValue refer to essentially the same object, conversion is cheap. No data is transferred from/to the Isabelle context.)

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. def Ops(implicit isabelle: Isabelle, ec: ExecutionContext): Ops

    Returns an instance of type Ops.

    Returns an instance of type Ops. It is guaranteed that for each instance isabelle, exactly one instance of Obs is created (using the ec from the first such invocation). (If you see this doc string in a class different from OperationCollection but no definition of the class Ops, treat this function as if it was private.)

    Definition Classes
    OperationCollection
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. def exceptionName(implicit isabelle: Isabelle, ec: ExecutionContext): String

    The name of the exception that encodes ML values of type mlType.

    The name of the exception that encodes ML values of type mlType. (See MLValue for explanations.) The name is guaranteed not to conflict with existing names (randomized name). And the exception is guaranteed to be declared in ML when this function returns.

  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  12. def init()(implicit isabelle: Isabelle, executionContext: ExecutionContext): Unit

    Makes sure an Ops instance for the instance isabelle is initialized.

    Makes sure an Ops instance for the instance isabelle is initialized. This is useful when code needs to be sure that the global initialization inside the Ops class has happened (e.g., declarations of ML types via Isabelle.executeMLCodeNow) even if it does not access any of the fields in the Ops class.

    Can safely be called several times with the same isabelle and/or executionContext.

    Definition Classes
    OperationCollection
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. val mlType: String
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. def newOps(implicit isabelle: Isabelle, ec: ExecutionContext): Ops

    Should construct an instance of type Ops

    Should construct an instance of type Ops

    Attributes
    protected
    Definition Classes
    AdHocConverterOperationCollection
  17. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  18. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  19. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  20. def toString(): String
    Definition Classes
    AnyRef → Any
  21. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  23. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  24. implicit object converter extends Converter[T]

    MLValueConverter for T.

    MLValueConverter for T. This MLValueConverter does not need to be explicitly imported to be available for implicit instances of MLValueConverter[T] because it is in the "implicit scope" of T (cf. the Scala spec).

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from OperationCollection

Inherited from AnyRef

Inherited from Any

Ungrouped