Packages

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.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. mlvalue
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. final class FunctionConverter[D, R] extends Converter[(D) => R]
    Annotations
    @inline()
  2. trait FutureValue extends AnyRef
  3. final class ListConverter[A] extends Converter[List[A]]
    Annotations
    @inline()
  4. 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 an MLValue[D => R], you can convert it to an MLFunction using MLValue.function.

  5. 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 arguments d1 and d2. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. class MLRetrieveFunction[A] extends AnyRef
  12. class MLStoreFunction[A] extends AnyRef
  13. 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 types A, it is possible to automatically translate a Scala value x of type A into an MLValue[A] (which behind the scenes means that x is transferred to the Isabelle process and added to the object store) and also to automatically translate an MLValue[A] back to a Scala value of type A. Supported types are Int, Long, Boolean, Unit, String, and lists and tuples (max. 7 elements) of supported types. (It is also possible for A to be the type MLValue[...], 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 type a. (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 type a. (E.g., both Long and Int correspond to the unbounded int 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 an A in Scala
      • store function: how to translate an A in Scala into an an exception encoding an ML value of type a and store it in the object store.
    • MLValue(x) automatically translates x:A into a value of type a (using the retrieve function) and returns an MLValue[A].
    • If m : MLValue[A], then m.retrieve (asynchronous) and m.retrieveNow (synchronous) decode the ML value in the object store and return a Scala value of type A.
    • 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

  14. final class MLValueConverter[A] extends Converter[MLValue[A]]
    Annotations
    @inline()
  15. final class OptionConverter[A] extends Converter[Option[A]]
    Annotations
    @inline()
  16. final class Tuple2Converter[A, B] extends Converter[(A, B)]
    Annotations
    @inline()
  17. final class Tuple3Converter[A, B, C] extends Converter[(A, B, C)]
    Annotations
    @inline()
  18. final class Tuple4Converter[A, B, C, D] extends Converter[(A, B, C, D)]
    Annotations
    @inline()
  19. final class Tuple5Converter[A, B, C, D, E] extends Converter[(A, B, C, D, E)]
  20. final class Tuple6Converter[A, B, C, D, E, F] extends Converter[(A, B, C, D, E, F)]
    Annotations
    @inline()
  21. final class Tuple7Converter[A, B, C, D, E, F, G] extends Converter[(A, B, C, D, E, F, G)]
    Annotations
    @inline()

Value Members

  1. object BooleanConverter extends Converter[Boolean]
  2. object Implicits
  3. object IntConverter extends Converter[Int]
  4. object LongConverter extends Converter[Long]
  5. object MLFunction
  6. object MLFunction2
  7. object MLFunction3
  8. object MLFunction4
  9. object MLFunction5
  10. object MLFunction6
  11. object MLFunction7
  12. object MLRetrieveFunction
  13. object MLStoreFunction
  14. object MLValue extends OperationCollection
  15. object StringConverter extends Converter[String]
  16. object UnitConverter extends Converter[Unit]

Inherited from AnyRef

Inherited from Any

Ungrouped