You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another Practical Guide to Levitation–related bug. Here are some auxiliary definitions:
dataDesc:Type->TypewhereRet: ix -> Desc ix
Arg: (a : Type) -> (a -> Desc ix) -> Desc ix
Rec: ix -> Desc ix -> Desc ix
Synthesise: Desc ix -> (ix ->Type) -> ix ->TypeSynthesise (Ret j) x i = (j = i)
Synthesise (Rec j d) x i = (rec: x j ** Synthesise d x i)
Synthesise (Arg a d) x i = (arg: a ** Synthesise (d arg) x i)
dataData: {ix : Type} -> Desc ix -> ix ->TypewhereCon: {d : Desc ix} -> {i : ix}
->Synthesise d (Data d) i ->Data d i
CLabel:TypeCLabel=StringCEnum:TypeCEnum=ListCLabelVecCtors: CEnum
VecCtors= ["Nil", "Cons"]
dataTag: CLabel -> CEnum ->TypewhereTZ: Tag l (l :: e)
TS: Tag l e -> Tag l (l' :: e)
SPi: (e : CEnum)
-> ((l: CLabel) -> Tag l e ->Type)
->TypeSPi [] _=()SPi (l :: e) prop = (prop l TZ, SPi e $\l' =>\t => prop l' $TS t)
switch: (e : CEnum)
-> (prop: (l : CLabel) -> (t : Tag l e) ->Type)
->SPi e prop
-> (l': CLabel) -> (t' : Tag l' e) -> prop l' t'
-- NB: Don't use the name "l'" for the first element of the CEnum, or you'll-- trigger https://github.com/idris-lang/Idris-dev/issues/3651
switch (l :: e) prop (propz, props) l TZ= propz
switch (l :: e) prop (propz, props) l' (TS t') =
switch e (\l =>\t => prop l (TS t)) props l' t'
VecDesc:Type-> Desc NatVecDesc a =ArgCLabel$\l =>Arg (Tag l VecCtors) $
switch VecCtors (\_=>\_=>DescNat)
( RetZ
, ( ArgNat$\n =>Arg a $\_=>Rec n $Ret$S n
, ()
)
) l
Vec: (a : Type) ->Nat->TypeVec a n =Data (VecDesc a) n
If you try defining a Vec value like this, it typechecks:
But if you try to abstract out the Nil and Cons operations like this:
Nil: {a : Type} -> Vec a Z
Nil=Con ("Nil"** (TZ**Refl))
Cons: {a : Type} -> {n : Nat}
-> a ->Vec a n ->Vec a (S n)
Cons {n} x xs =Con ("Cons"** (TSTZ** (n ** (x ** (xs **Refl)))))
exampleVecIdeal: Vec Nat 3
exampleVecIdeal =Cons1$Cons2$Cons3Nil
Then exampleVecIdeal fails to typecheck!
Type checking ./Ch2_2.idr
Ch2_2.idr:77:17:
When checking right hand side of exampleVecIdeal with expected type
Vec Nat 3
Type mismatch between
Vec Integer 3 (Type of Cons 1 (Cons 2 (Cons 3 [])))
and
Data (VecDesc Nat) (fromIntegerNat 3) (Expected type)
Specifically:
Type mismatch between
switch ["Nil", "Cons"]
(\underscore1, underscore2 => Desc Nat)
(Ret 0,
Arg Nat (\n => Arg Integer (\underscore => Rec n (Ret (S n)))),
())
v0
and
switch ["Nil", "Cons"]
(\underscore1, underscore2 => Desc Nat)
(Ret 0,
Arg Nat (\n => Arg Nat (\underscore => Rec n (Ret (S n)))),
())
v0
The workaround is to provide a type ascription on every single occurrence of Cons:
I think the issue here is that Idris apparently does not detect that Cons and Nil are properly injective, and so does not try to nicely unify the type arguments. I would hope this would get fixed as well at some point.
@edwinb I think it could work if one only translated each numeral n to fromInteger n, instead of guessing the type of a numeral to be Integer too eagerly.
Another Practical Guide to Levitation–related bug. Here are some auxiliary definitions:
If you try defining a
Vec
value like this, it typechecks:But if you try to abstract out the
Nil
andCons
operations like this:Then
exampleVecIdeal
fails to typecheck!The workaround is to provide a type ascription on every single occurrence of
Cons
:The text was updated successfully, but these errors were encountered: