Inconvenient definition for NDBType.asType

Aperta
#154 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Ambito
documentation

Direzione di ricerca

Inizia con l’esercizio Typed Queries e confronta la definizione condizionale di NDBType.asType con l’alternativa basata sul pattern matching mostrata nell’issue. Controlla l’implementazione correlata di NDBType.beq e il resto dell’esercizio nullable-types. Il lavoro è completo quando la definizione supporta confronti diretti tramite pattern matching senza i casts o i workaround con le tactic segnalati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Lean
Stelle
211
Fork
83
Merge medio
8m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di leanprover/fp-lean

Tutte le issue di leanprover/fp-lean

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.