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
- Alphabetic
- By Inheritance
- AdHocConverter
- OperationCollection
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new AdHocConverter(mlType: String)
- mlType
The ML type for which to create a Scala wrapper type
- Attributes
- protected
Type Members
- class Ops extends AnyRef
- Attributes
- protected
- 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) isEXN x
whereEXN
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
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- 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 ofObs
is created (using theec
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
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exceptionName(implicit isabelle: Isabelle, ec: ExecutionContext): String
The name of the exception that encodes ML values of type mlType.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- 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/orexecutionContext
.- Definition Classes
- OperationCollection
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val mlType: String
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- 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
- AdHocConverter → OperationCollection
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- 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).