Inconvenient definition for NDBType.asType

Abierto
#154 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
45/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Estancado

Línea de trabajo

Comienza con el ejercicio Typed Queries y compara la definición condicional de NDBType.asType con la alternativa basada en pattern matching mostrada en el issue. Revisa la implementación relacionada de NDBType.beq y el resto del ejercicio nullable-types. Se considera terminado cuando la definición admite comparaciones directas mediante pattern matching sin los casts ni los workarounds de tácticas indicados.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

The following is given in the Typed Queries exercise

Nullable Types
Add support for nullable columns to the query language by representing database types with the following structure:

 structure NDBType where
   underlying : DBType
   nullable : Bool
 
 abbrev NDBType.asType (t : NDBType) : Type :=
   if t.nullable then
     Option t.underlying.asType
   else
     t.underlying.asType

Use this type in place of DBType in Column and DBExpr, and look up SQL's rules for NULL and comparison operators to determine the types of DBExpr's constructors.

It seems like Lean has issues seeing through this definition of .asType, which led to needing to use convoluted casting and tactics for the rest of the implementation.

For example, you can try to write NDBType.beq as:

def NDBType.beq (t : NDBType) (x y : t.asType) : Bool :=
  match t with
  | ⟨_, true⟩ => x == y
  | ⟨_, false⟩ => x == y

However, Lean gives the errors:

failed to synthesize instance
  BEq (asType { underlying := underlying✝, nullable := true })

failed to synthesize instance
  BEq (asType { underlying := underlying✝, nullable := false })

Instead, I needed to write it as:

def NDBType.beq (t : NDBType) (x y : t.asType) : Bool :=
  match t with
  | ⟨t', true⟩ =>
    let x' : Option t'.asType := x
    x' == y
  | ⟨t', false⟩ =>
    let x' : t'.asType := x
    x' == y

On the other hand, you can define NDBType.asType with:

abbrev NDBType.asType (t : NDBType) : Type :=
  match t with
  | ⟨t', true⟩ => Option t'.asType
  | ⟨t', false⟩ => t'.asType

At this point, the first declaration of NDBType.beq works, as do the natural modifications needed for the rest of the exercise.

Lenguaje dominante
Lean
Estrellas
211
Forks
83
Merge medio
8 min
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de leanprover/fp-lean

Todos los issues de leanprover/fp-lean

Issues similares

Más issues de Documentation

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.