Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8588747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:52:47+00:00 2026-06-11T22:52:47+00:00

I trying to use coq as a programming language with dependent type. I created

  • 0

I trying to use coq as a programming language with dependent type. I created the following small program:

Inductive Good : list nat -> Set := 
  | GoodNonEmpty : forall h t, Good (h :: t).

Definition get_first(l : list nat)(good : Good l) : nat := 
  match l with
    | h :: t => h
    | nil => 
      match good with 
      end
  end. 

I defined a type for non empty list and create a function which gets the first element of such a list provided there’s a proof that it’s not empty. I handle well the case where head items consists of two items, but I can’t handle the impossible case of empty list. How can I do this in coq?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:52:49+00:00Added an answer on June 11, 2026 at 10:52 pm

    One way to do it that is simpler than your try is:

    Definition get_first (l : list nat) (good : Good l) : nat :=
      match good with
      | GoodNonEmpty h _ => h
      end.
    

    Here is a way to do it in the way you wanted to do it. You’ll notice it is very verbose to prove that “Good nil” does not exist, inlined.

    Definition get_first (l : list nat) (good : Good l) : nat :=
      (
        match l as l' return (Good l' -> nat) with
        | nil =>
          fun (goodnil : Good nil) =>
            (
              match goodnil in (Good l'') return (nil = l'' -> nat) with
              | GoodNonEmpty h t =>
                fun H => False_rect _ (nil_cons H)
              end
            )
            (@eq_refl _ nil)
        | h :: _ => fun _ => h
        end
      ) good.
    

    You can surely define some of that outside and reuse it. I am not aware of the best practices though. Maybe someone can come with a shorter way to do the same thing.


    EDIT:

    By the way, you can get to pretty much the same result, in a much easier way, in proof mode:

    Definition get_first' (l : list nat) (good : Good l) : nat.
    Proof.
      destruct l. inversion good. exact n.
    Defined.
    

    You can then:

    Print get_first'.
    

    To see how Coq defines it. However, for more involved things, you might be better off following what gdsfhl from the #coq IRC channel proposed as a solution:

    http://paste.in.ua/4782/

    You can see that he uses the refine tactic to provide part of the skeleton of the term to write, and defer the missing proofs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
trying to use hibernate with my web app and getting following exception: Initial SessionFactory
I'm trying to use coq with ProofGeneral, but the built-in Verilog mode shadows *.v
I'm trying use double type in openCL, but doesn't work anyway, i want use
I am trying use jQuery to poll dynamic DOM nodes, created outside of the
Trying to use WMI to obtain a list of installed programs for Windows XP.
I am trying use the django ORM to get a list by year of
I revieving the following error when trying use mysql_real_escape() function Fatal error: Call to
i'm trying use facebook API to upload photo in my fan page. I downloaded
I am trying use gem tire to search in my application. I have tables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.