1

I'm trying to extract to Haskell a program in Coq that uses Z numbers. I want to map Coq's Z to Haskell's Integer.

I found some libraries for doing that aiming OCaml, but not aiming Haskell. There is no library for that?

I need the extractions (found here):

Extract Inductive positive => "Big.big_int"
 [ "Big.doubleplusone" "Big.double" "Big.one" ] "Big.positive_case".

Extract Inductive Z => "Big.big_int"
 [ "Big.zero" "" "Big.opp" ] "Big.z_case".

Extract Inductive N => "Big.big_int"
 [ "Big.zero" "" ] "Big.n_case".

but aiming Haskell.

I'll just ask: how to do it?.

But secondly, I should say why I couldn't do it myself:

I guess I can't come up with that myself possibly because I'm misunderstanding somethings, for example: why there is a empty string in the second definition? The definition of Z has three constructors: Z0, Zpos and Zneg. I don't see how "Big.zero" "" "Big.opp" is related with this.

Also, I didn't understand how the last string works: "...a final extra string that indicates how to perform pattern-matching over this inductive type." (found in documentation).

The chapter Extraction of S.F. says that "we give an OCaml expression that can be used as a "recursor" over elements of the type. (Think Church numerals.)".

How the code bellow is a recursor or does pattern-maching?

  "(fun zero succ n →
      if n=0 then zero () else succ (n-1))".

After I understand those things, I hope that I can create, myself, the extractions that I may ever need.

Rafael Castro
  • 579
  • 5
  • 14
  • 1
    You might want to take a peek at [extraction.v](https://github.com/antalsz/hs-to-coq/blob/832e281e98685cd4d2914fb62a475476d1d86fa4/core-semantics-no-values/extraction.v) of [hs-to-coq](https://github.com/antalsz/hs-to-coq). – Anton Trunov May 07 '18 at 17:43
  • you linked to the Coq v8.3 documentation - is that the version you're using? In that case you'll have to write the extraction commands yourself. – Tej Chajed May 07 '18 at 18:59
  • @TejChajed no, it's not. For some reason that was the documentation that I found. Search skills fault. – Rafael Castro May 07 '18 at 20:24
  • Not your fault! The Coq documentation can be quite hard to Google for. – Tej Chajed May 07 '18 at 21:35

1 Answers1

4

You can just import ExtrHaskellZInteger (documentation).

Tej Chajed
  • 3,749
  • 14
  • 18