Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. data Last : List a -> a -> Type where
  2. LastOne : Last [val] val
  3. LastCons : (prf : Last xs val) -> Last (x :: xs) val
  4.  
  5. Uninhabited (Last [] val) where
  6. uninhabited LastOne impossible
  7. uninhabited (LastCons _) impossible
  8.  
  9. isLast : DecEq a => (xs : List a) -> (val : a) -> Dec (Last xs val)
  10. isLast [] val = No absurd
  11.  
  12. isLast [x] val = case decEq x val of
  13. Yes Refl => Yes LastOne
  14. No contra => No (notLastOne contra)
  15. where
  16. notLastOne : (contra : (y = v) -> Void) -> Last [y] v -> Void
  17. notLastOne contra LastOne = contra Refl
  18. notLastOne contra (LastCons prf) = uninhabited prf
  19.  
  20. isLast (x :: xs@(x' :: xs')) val = case isLast xs val of
  21. Yes prf => Yes (LastCons prf)
  22. No contra => No ?b -- (notLastCons contra)
  23. where
  24. notLastCons : (contra : Last ys v -> Void) -> Last (y :: ys) v -> Void
  25.  
  26. {-
  27. - + Errors (1)
  28. `-- CheckEqDec.idr line 84 col 56:
  29. When checking right hand side of Main.case block in isLast at CheckEqDec.idr:83:41-53 with expected type
  30. Dec (Last (x :: x' :: xs') val)
  31.  
  32. When checking argument prf to constructor Main.LastCons:
  33. Type mismatch between
  34. Last xs val (Type of prf)
  35. and
  36. Last (x' :: xs') val (Expected type)
  37.  
  38. Specifically:
  39. Type mismatch between
  40. xs
  41. and
  42. x' :: xs'
  43. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement