dependent-type

When calling a scala function with compile-time macro, how to failover smoothly when it causes compilation errors?

一世执手 提交于 2021-02-13 05:43:30
问题 Assuming that I intend to use the singleton/literal type feature in a scala program, this feature is provided in shapeless library in scala 2.12 (scala 2.13 supports native literal type but let's use shapeless as an example) In shapeless, literal type is represented as a path-dependent inner type of Witness object, which can be implicitly converted from a scala literal/const: import com.tribbloids.spike.BaseSpec import shapeless.Witness import scala.util.Random val w: Witness.Lt[Int] = 3 val

How can I have a method parameter with type dependent on an implicit parameter?

旧城冷巷雨未停 提交于 2021-02-05 05:53:05
问题 trait JsonOps[J] { type ObjectFields def partitionObjectFields(fields: ObjectFields, fieldNames: List[String]): (ObjectFields, ObjectFields) } def compilerNoLikey[J](stuff: ops.ObjectFields)(implicit ops:JsonOps[J]) = {} def compilerLikey[J](stuff: Any)(implicit ops:JsonOps[J]) = { val stuff2 = stuff.asInstanceOf[ops.ObjectFields] } You can see my intent here. I define a type in JsonOps to encapsulate a structure dependant on J. Then later when I want to use this, I have a function that

How can I glue/identify inclusions in two structures in MMT?

爱⌒轻易说出口 提交于 2021-01-28 01:16:01
问题 I'd like to formalize formal languages and their semantics in MMT and define a general notion of semantics equivalence of two semantics wrt. one syntax. Precisely, encoding the latter turns out to be an identification/glueing that I have no idea on how to do in MMT. Let me elaborate on my concrete formalization setup next. Below is a simplified formalization showing my approach. Based on a theory Meta aggregating both the logical framework LF and some logic, I start in Syntax defining a

Finding an implementation (of show) for an inductively defined type

荒凉一梦 提交于 2021-01-27 23:06:17
问题 The following snippet was from (https://stackoverflow.com/a/37461290/2129302): tensor : Vect n Nat -> Type -> Type tensor [] a = a tensor (m :: ms) a = Vect m (tensor ms a) I'd like to define the following: mkStr : (Show a) => tensor shape a -> String mkStr x = show x But instead this gives the following error: Can't find implementation for Show (tensor shape a) However, on the REPL I can run "show [some tensor value...]". Why is this and what can I do to fix it? 回答1: You're not showing a ,

Finding an implementation (of show) for an inductively defined type

前提是你 提交于 2021-01-27 21:50:49
问题 The following snippet was from (https://stackoverflow.com/a/37461290/2129302): tensor : Vect n Nat -> Type -> Type tensor [] a = a tensor (m :: ms) a = Vect m (tensor ms a) I'd like to define the following: mkStr : (Show a) => tensor shape a -> String mkStr x = show x But instead this gives the following error: Can't find implementation for Show (tensor shape a) However, on the REPL I can run "show [some tensor value...]". Why is this and what can I do to fix it? 回答1: You're not showing a ,

Can I get a Rust array's length with only a type, not a concrete variable?

纵然是瞬间 提交于 2020-12-06 07:06:52
问题 I want to rewrite the following C++ code into Rust: using storage = array<int, 3>; const size_t storage_len = sizeof(storage) / sizeof(storage::value_type); How can I get that constant length value without a concrete variable? As motivation, although it may seem trivial, I want to print the array's element count without declaring a variable. I know I could use a constant value or declare a dummy variable, but I wonder how Rust can preserve C++ code. I admit without a concrete variable is not