Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Is there a name for this trick in programming with dependent types?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Is there a name for this trick in programming with dependent types?


Chronological Thread 
  • From: Lily Chung <ikdc AT mit.edu>
  • To: <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Is there a name for this trick in programming with dependent types?
  • Date: Thu, 28 Feb 2019 13:15:00 -0500
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=ikdc AT mit.edu; spf=Pass smtp.mailfrom=ikdc AT mit.edu; spf=Pass smtp.helo=postmaster AT NAM05-DM3-obe.outbound.protection.outlook.com
  • Importance: Normal
  • Ironport-phdr: 9a23:i+me0BYCevo23QqGATzxKu//LSx+4OfEezUN459isYplN5qZoMq5bnLW6fgltlLVR4KTs6sC17KG9fi4EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCa+bL9oMBm6sRjau9ULj4dlNqs/0AbCrGFSe+RRy2NoJFaTkAj568yt4pNt8Dletuw4+cJYXqr0Y6o3TbpDDDQ7KG81/9HktQPCTQSU+HQRVHgdnwdSDAjE6BH6WYrxsjf/u+Fg1iSWIdH6QLYpUjmk8qxlSgLniD0fOjA37W/Zic5/gqJFrh2ivRJwwoHbb52aOvdlfqPSZskXSXZdUspNVSFMBJ63YYsVD+oGOOZVt4/zp1oKrRq+GAKhGuPvyiJOhn/5wKY31OUhEQLb0wM8BN8OtXXUrMnvOKgMTO+10bDFwDPeZP1Y3jf97ZLHchEnofyUUrJwcNbRyUkyFwzelFmftYvlPzaT2+8QsGab9/JtWO2zh2I9tg19vjqiyt0uh4THnI4Z107I+TlhzIooJtC0UkB2bcK+HJZUtiyWLZZ6Tt8+T2xupS000KcJuYShcygP0JknxwDQa/iAc4WQ+hzuSOGfLSt4iX58dryxgBi//VGnyuLnSMa4ylFKrjdZktbXsXANyhrT5dWdRvtl5Eeh3iqP2B7P5eFYIEA0kqzbJ4Qmwr4tipoTtUPDHij1mEnskKCWcUAk9vCp6+ThfLrmuoeROoBohg3kL6gihs6yDf46PwUARWSX5Pqw2KH78U38WrpKj/k2kqfDsJDdIMQWvq+5AwxI3Yk/8Bu/Cjam0MgCkXYZMV1FZQqLj5L1NFHWPPD4EfC/jkywnzds3vDKJ6HuApHQLnfYi7rhZrZ860tEyAUp19xf5pRUCqsAIP3pQEPxusbYXVcFNFngyOH+Td55y4k2WGSVA6bfPrmE4nGS4ed6B+iIdcc+uCv7JLBx5v3ihlc8mENbcKW0i8hEIEukF+hrdh3KKUHnhc0MRD9T71gOCdfygVjHagZ9InO7XqYy/DY+WdCjDJuFS4yw0uXYgHWLW6ZOb2UDMWiiVG/yftTWXvYQLi+eP505y2FWZf2aU4YkkCqWmkr6xr5gcrWG3AQ97c+m+P0uourZmFc16CB+CNmb3yeVVWZok2gURjgwmqdivUh6zVTF2q990aVV

Seems to me that this is exactly the convoy pattern, just with a different proposition than equality.

On Feb 28, 2019 12:48, Shengyi Wang <txyyss AT gmail.com> wrote:
Hi,

Inspired by the definition of addvect in https://github.com/coq-contribs/matrices/blob/master/operators.v , I made a definition of head for length-indexed lists as follows:

Require Import Coq.Arith.PeanoNat.

Section ilist.

  Variable A : Set.
  
  Inductive ilist : nat -> Set :=
  | Nil : ilist O
  | Cons : forall n, A -> ilist n -> ilist (S n).

  Definition ihd {n: nat} (l: ilist (S n)): A :=
    match l in (ilist m) return (O < m -> A) with
    | Nil => fun p => False_rect _ (Nat.nle_succ_0 _ p)
    | Cons _ h _ => fun _ => h
    end (Nat.lt_0_succ n).

End ilist.

This definition introduces an extra parameter "O < m"  in return clause and applies the whole match to the proof "(Nat.lt_0_succ n)" to eliminate the parameter. With this trick we can claim false for the impossible branch.

I'm curious if there is a name for this trick like the "convoy pattern" trick named in Adam Chlipala's "Certified Programming with Dependent Types".

Thank you very much,

Shengyi Wang

Cell: +65-83509639




Archive powered by MHonArc 2.6.18.

Top of Page