This commit is contained in:
Alexander Nozik 2020-10-24 13:05:36 +03:00
parent f7614da230
commit 94df61cd43
2 changed files with 7 additions and 8 deletions

View File

@ -10,7 +10,6 @@ import kotlin.properties.ReadOnlyProperty
public interface Symbol { public interface Symbol {
/** /**
* Identity object for the symbol. Two symbols with the same identity are considered to be the same symbol. * Identity object for the symbol. Two symbols with the same identity are considered to be the same symbol.
* By default uses object identity
*/ */
public val identity: String public val identity: String
} }
@ -33,8 +32,6 @@ public fun interface Expression<T> {
* @return the value. * @return the value.
*/ */
public operator fun invoke(arguments: Map<Symbol, T>): T public operator fun invoke(arguments: Map<Symbol, T>): T
public companion object
} }
/** /**
@ -81,17 +78,13 @@ public interface ExpressionAlgebra<in T, E> : Algebra<E> {
public fun const(value: T): E public fun const(value: T): E
} }
//public interface ExpressionBuilder<T, E, A : ExpressionAlgebra<T, E>> {
// public fun expression(block: A.() -> E): Expression<T>
//}
/** /**
* Bind a given [Symbol] to this context variable and produce context-specific object. * Bind a given [Symbol] to this context variable and produce context-specific object.
*/ */
public fun <T, E> ExpressionAlgebra<T, E>.bind(symbol: Symbol): E = public fun <T, E> ExpressionAlgebra<T, E>.bind(symbol: Symbol): E =
bindOrNull(symbol) ?: error("Symbol $symbol could not be bound to $this") bindOrNull(symbol) ?: error("Symbol $symbol could not be bound to $this")
public val symbol: ReadOnlyProperty<Any?, Symbol> = ReadOnlyProperty { _, property -> public val symbol: ReadOnlyProperty<Any?, StringSymbol> = ReadOnlyProperty { _, property ->
StringSymbol(property.name) StringSymbol(property.name)
} }

View File

@ -7,6 +7,12 @@ import kscience.kmath.operations.Space
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract
//public interface ExpressionBuilder<T, E, A : ExpressionAlgebra<T, E>> {
// public fun expression(block: A.() -> E): Expression<T>
//}
/** /**
* Creates a functional expression with this [Space]. * Creates a functional expression with this [Space].
*/ */