object StringInterpolators extends OperationCollection
Provides string interpolators for conveniently creating Isabelle terms and types.
It allows us to write, e.g., term"x+y" to parse the term x+y.
Or typ"nat" to parse the type nat
In addition, subterms of terms can refer to already existing Term objects,
e.g., term"x+$term" for a Scala variable term of type Term.
We can also refer to existing Typ objects, both in terms and types.
E.g., term"x :: $typ or typ"$typ => $typ" for a Scala variable of type Typ.
The support for the interpolators is activated by importing the implicits import de.unruh.isabelle.pure.Implicits._.
To use the interpolators, an implicit Isabelle instance, an implicit ExecutionContext, and an implicit Context must be given. (The latter provides the theory context in which to parse the terms/types.)
Parsing happens at runtime, there is no compile-time validation of the terms/types.
An example how to use type and term interpolators:
import de.unruh.isabelle.pure.Implicits._ import scala.concurrent.ExecutionContext.Implicits.global implicit isabelle = new Isabelle(...) implicit context = Context("Main") // Parsing w.r.t. Isabelle theory Main val typ1 = typ"nat" // type nat val typ2 = typ"$typ1 => $typ1" // type nat => nat val term1 = term"f :: $typ2" // term f :: nat => nat val term2 = term"$term1 1" // term (f :: nat => nat) (1 :: nat) (by type inference)
The interpolators can also be used for pattern matching.
That is, term"..." and typ"..." can appear in the pattern in a Scala pattern match.
Example:
// implicits as above val term = term"1 + (2::nat)" term match { case term"$t + (_::$u::plus)" => (t,u) // t : Term is "1::nat", u : Typ is "nat" } val typ = typ"nat => nat" typ match { case typ"$t => $dummy" => t // t : Typ is "nat" }
(Note: A subtlety is that we write $u::plus instad of just $u in the pattern above.
This is because Isabelle otherwise refuses to parse the term: a schematic type variable (into which $u is converted for
parsing purposes) needs to be annotated with a sort that makes the overall term well-typed.)
(Note: Another subtlety is that we use $dummy instead of _ to indicate a wildcard in typ"$t => $dummy".
This is because Isabelle does not support _ in pattern matches for types.
We could also write $_ instead of $dummy here because then _ is a Scala-wildcard, not an Isabelle wildcard.)
Invalid (i.e., unparseable) strings raise an IsabelleException.
This also applied if ... in patterns term"..." or typ"..." cannot be parsed.
- Alphabetic
- By Inheritance
- StringInterpolators
- OperationCollection
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
final
class
Ops extends AnyRef
- Attributes
- protected
-
implicit final
class
TermInterpolator extends AnyRef
See StringInterpolators for an explanation.
-
type
TermOrTyp = FutureValue with PrettyPrintable
Best approximation to the union type of Term and Typ that we can easily manage.
-
implicit final
class
TypInterpolator extends AnyRef
See StringInterpolators for an explanation.
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 ofObsis created (using theecfrom 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( ... ) @native() @HotSpotIntrinsicCandidate()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- 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
isabelleis initialized.Makes sure an Ops instance for the instance
isabelleis 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
isabelleand/orexecutionContext.- Definition Classes
- OperationCollection
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
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
- StringInterpolators → 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( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
object
PrivateImplementation
This object should be considered private.
This object should be considered private. (It is only visible to be accessible in macro code.)