package mlvalue
This package contains classes for type safe manipulation of values stored in a running Isabelle process (managed by an instance of control.Isabelle). See MLValue for an introduction.
- Alphabetic
- By Inheritance
- mlvalue
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- final class FunctionConverter[D, R] extends Converter[(D) => R]
- Annotations
- @inline()
- trait FutureValue extends AnyRef
- final class ListConverter[A] extends Converter[List[A]]
- Annotations
- @inline()
- class MLFunction[D, R] extends MLValue[(D) => R]
An MLValue that refers to an ML function in the Isabelle process.
An MLValue that refers to an ML function in the Isabelle process. This class extends
MLValue[D => R]
(which by definition refers to an ML function) but provides additional methods for invoking the function. Given anMLValue[D => R]
, you can convert it to an MLFunction using MLValue.function. - class MLFunction2[D1, D2, R] extends MLFunction[(D1, D2), R]
A refinement of MLFunction (see there).
A refinement of MLFunction (see there). If the function takes a pair
(d1,d2)
as an argument, then we can treat it as a function with two argumentsd1
andd2
. Thus this class adds additional method for invoking the function with two arguments instead of a tuple. An MLValue (or MLFunction) can be converted into an MLFunction2 using MLValue.function2. - class MLFunction3[D1, D2, D3, R] extends MLFunction[(D1, D2, D3), R]
Analogue to MLFunction2 but for three arguments.
Analogue to MLFunction2 but for three arguments. See MLFunction2.
- class MLFunction4[D1, D2, D3, D4, R] extends MLFunction[(D1, D2, D3, D4), R]
Analogue to MLFunction2 but for four arguments.
Analogue to MLFunction2 but for four arguments. See MLFunction2.
- class MLFunction5[D1, D2, D3, D4, D5, R] extends MLFunction[(D1, D2, D3, D4, D5), R]
Analogue to MLFunction2 but for five arguments.
Analogue to MLFunction2 but for five arguments. See MLFunction2.
- class MLFunction6[D1, D2, D3, D4, D5, D6, R] extends MLFunction[(D1, D2, D3, D4, D5, D6), R]
Analogue to MLFunction2 but for six arguments.
Analogue to MLFunction2 but for six arguments. See MLFunction2.
- class MLFunction7[D1, D2, D3, D4, D5, D6, D7, R] extends MLFunction[(D1, D2, D3, D4, D5, D6, D7), R]
Analogue to MLFunction2 but for seven arguments.
Analogue to MLFunction2 but for seven arguments. See MLFunction2.
- class MLRetrieveFunction[A] extends AnyRef
- class MLStoreFunction[A] extends AnyRef
- class MLValue[A] extends FutureValue
A type safe wrapper for values stored in the Isabelle process managed by Isabelle.
A type safe wrapper for values stored in the Isabelle process managed by Isabelle.
As explained in the documentation of Isabelle, the Isabelle process has an object store of values, and the class Isabelle.ID is a reference to an object in that object store. However, values of different types share the same object store. Thus Isabelle.ID is not type safe: there are compile time guarantees that the value referenced by that ID has a specific type.
MLValue[A] is a thin wrapper around an ID id (more precisely, a future holding an ID). It is guaranteed that id references a value in the Isabelle process of an ML type corresponding to
A
(or throw an exception). (It is possible to violate this guarantee by type-casting the MLValue though.) For supported typesA
, it is possible to automatically translate a Scala valuex
of typeA
into anMLValue[A]
(which behind the scenes means thatx
is transferred to the Isabelle process and added to the object store) and also to automatically translate anMLValue[A]
back to a Scala value of typeA
. Supported types are Int, Long, Boolean, Unit, String, and lists and tuples (max. 7 elements) of supported types. (It is also possible forA
to be the typeMLValue[...]
, see MLValueConverter for explanations (TODO add these explanations).) It is possible to add support for other types, see MLValue.Converter for instructions (TODO add these instructions). Using this mechanism, support for the terms, types, theories, contexts, and theorems has been added in package de.unruh.isabelle.pure.In more detail:
- For any supported Scala type
A
there should be a unique corresponding ML typea
. (This is not enforced if we add support for new types, but if we violate this, we loose type safety.) - Several Scala types
A
are allowed to correspond to the same ML typea
. (E.g., both Long and Int correspond to the unboundedint
in ML.) - For each supported type
A
, the following must be specified (via an implicit MLValue.Converter):- an encoding of
a
as an exception (to be able to store it in the object store) - ML functions to translate between
a
and exceptions and back - retrieve function: how to retrieve an exception encoding an ML value of type
a
and translate it into anA
in Scala - store function: how to translate an
A
in Scala into an an exception encoding an ML value of typea
and store it in the object store.
- an encoding of
MLValue(x)
automatically translatesx:A
into a value of typea
(using the retrieve function) and returns anMLValue[A]
.- If
m : MLValue[A]
, thenm.
retrieve (asynchronous) andm.
retrieveNow (synchronous) decode the ML value in the object store and return a Scala value of typeA
. - ML code that operates on values in the Isabelle process can be specified using MLValue.compileValue
and MLValue.compileFunction[D,R]*. This ML code directly operates on the corresponding ML type
a
and does not need to consider the encoding of ML values as exceptions or how ML types are serialized to be transferred to Scala (all this is handled automatically behind the scenes using the information provided by the implicit MLValue.Converter). - To be able to use the automatic conversions etc., converters need to be imported for supported types.
The converters provided by this package can be imported by
import de.unruh.isabelle.mlvalue.Implicits._
.
Note: Some operations take an Isabelle instance as an implicit argument. It is required that this instance the same as the one relative to which the MLValue was created.
A full example:
implicit val isabelle: Isabelle = new Isabelle(...) import scala.concurrent.ExecutionContext.Implicits._ // Create an MLValue containing an integer val intML : MLValue[Int] = MLValue(123) // 123 is now stored in the object store // Fetching the integer back val int : Int = intML.retrieveNow assert(int == 123) // The type parameter of MLValue ensures that the following does not compile: // val string : String = intML.retrieveNow // We write an ML function that squares an integer and converts it into a string val mlFunction : MLFunction[Int, String] = MLValue.compileFunction[Int, String]("fn i => string_of_int (i*i)") // We can apply the function to an integer stored in the Isabelle process val result : MLValue[String] = mlFunction(intML) // The result is still stored in the Isabelle process, but we can retrieve it: val resultHere : String = result.retrieveNow assert(resultHere == "15129")
Not that the type annotations in this example are all optional, the compiler infers them automatically. We have included them for clarity only.
- A
the Scala type corresponding to the ML type of the value referenced by id
- For any supported Scala type
- final class MLValueConverter[A] extends Converter[MLValue[A]]
- Annotations
- @inline()
- final class OptionConverter[A] extends Converter[Option[A]]
- Annotations
- @inline()
- final class Tuple2Converter[A, B] extends Converter[(A, B)]
- Annotations
- @inline()
- final class Tuple3Converter[A, B, C] extends Converter[(A, B, C)]
- Annotations
- @inline()
- final class Tuple4Converter[A, B, C, D] extends Converter[(A, B, C, D)]
- Annotations
- @inline()
- final class Tuple5Converter[A, B, C, D, E] extends Converter[(A, B, C, D, E)]
- final class Tuple6Converter[A, B, C, D, E, F] extends Converter[(A, B, C, D, E, F)]
- Annotations
- @inline()
- final class Tuple7Converter[A, B, C, D, E, F, G] extends Converter[(A, B, C, D, E, F, G)]
- Annotations
- @inline()
Value Members
- object BooleanConverter extends Converter[Boolean]
- object Implicits
- object IntConverter extends Converter[Int]
- object LongConverter extends Converter[Long]
- object MLFunction
- object MLFunction2
- object MLFunction3
- object MLFunction4
- object MLFunction5
- object MLFunction6
- object MLFunction7
- object MLRetrieveFunction
- object MLStoreFunction
- object MLValue extends OperationCollection
- object StringConverter extends Converter[String]
- object UnitConverter extends Converter[Unit]