Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] FMap with abstract data type

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] FMap with abstract data type


Chronological Thread 
  • From: Jasper Hugunin <jasperh AT cs.washington.edu>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] FMap with abstract data type
  • Date: Fri, 24 May 2019 14:06:18 -0700
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jasperh AT cs.washington.edu; spf=None smtp.mailfrom=jasperh AT cs.washington.edu; spf=None smtp.helo=postmaster AT mail-ot1-f45.google.com
  • Ironport-phdr: 9a23:7N3LuxAyVr2vlNpjmTmXUyQJP3N1i/DPJgcQr6AfoPdwSPT6oMbcNUDSrc9gkEXOFd2Cra4d0qyP6v6rADFfqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjWwba5vIBmssAndq8gbjYR/JqsxyBbCv2dFdflRyW50P1yYggzy5t23/J5t8iRQv+wu+stdWqjkfKo2UKJVAi0+P286+MPkux/DTRCS5nQHSWUZjgBIAwne4x7kWJr6rzb3ufB82CmeOs32UKw0VDG/5KplVBPklCEKPCM//WrKiMJ/kbhbrQquqBxxwYHaYI+bOvljcK3DYdwXXnBOUtpLWiFbHo+wc4kCAuwcNuhYtYn9oF4OoAO6Cwa2H+Pv0iFHhmXr1qM4zuQhHhzG3AohH9IIrX/Zq9f1O70JUeCt0qbI1zXDYuhK1jfm8oTJfAouoeqMXbJxd8rRxlUvFwTDjlmKt4PqIi6V2/0LvmOG4eRgUuevhHQmqwF3ujWvwNkji4fTiYIP1lDE9D55z5wzJd2jUkJ0fdmkEJ5IuyGcLYR2R90tT3h0tyY90LIJpZ67cDIWx5Qgwh7SbeGMfYuQ4h/7SuqdPTN1iGhmdb+/nRq+71WsxvHmWsS70FtHqDdOnMPWuXAXzRPT79CKSvtj8Uel3jaCzwXT5ftFIUAwjKbbLIIhzqMpmpodvknOHjX6mErxjK+ReUUk/van5/77bbXho5+QL450igfgPaQygsGzH/g0PwwUU2WY+emwzqPv8VDlTLlQgfA7krHVsJXAKsQaoq65DRVV0oEm6xunDTepys8YnWEZI1JfeBKKlJTmO0rULPH2F/i/mFSskDZtx/DJIr3hBZPNImLdn7j8YLZx81RcxxYrzdBD+5JUDakML+70Wk/ordDXEhs5MxGvzOv8E9V81oYeWXqVDaODMaPSt0WI5uM1LOWWao8VomW1F/9w7Pn3yHQ9hFU1fK+z3JJRZmrrMO5hJhC7aGH0j81JMXoFoww/SqS+ilSZSTNJZ165ROQj7yo7CYSpEYDFAI2hnerSj2+AApRKazUeWRi3GnDyetDcAqpeWGepOsZk1wc8e/2hRosmj0z8sQb7z/9gMrOR9HFF853k09dx6qvYkhRgrWUoXfTY6HmESiRPpk1NXyU/hfEtqlc71V6Y0al+jOBfE5pe6+4bCl5rZ66Z9PRzDpXJYiyEe96ITFi8RdD/UGM6VZQuysQOYkByB9KkyB3PwnjyDg==

You can use

From Coq Require OrderedTypeEx FMapAVL FMapFacts.
Module Map := FMapAVL.Make OrderedTypeEx.Nat_as_OT.
Check Map.t : Type -> Type. (* The values can be anything you like *)
Check Map.Equiv : forall X, (X -> X -> Prop) -> (Map.t X -> Map.t X -> Prop).

(* You get a relation Map.Equiv for any relation between elements. Proving it is a congruence relation shouldn't be hard, but I'm not sure is in the standard library. *)
(* If the equality on values is Init.Logic.eq, i.e. a1 = a2, then you can instead use Map.Equal, which does have Proper instances proven in MapProperties. *)

Module MapProperties := FMapFacts.Properties Map.
(* Also MapProperties.F has useful stuff. *)

(* This can be used as *)
Axiom A : Type.
Check Map.t A. (* This is the type of maps with keys in nat and values in A. *)

- Jasper Hugunin

On Fri, May 24, 2019 at 11:51 AM Vadim Zaliva <vzaliva AT cmu.edu> wrote:

I am trying to figure out how to use FMap with abstract data type and
equality. I need a map where the keys are natural numbers, but values belong to an abstract type A. I can assume that this type has an equality Ae which is decidable, and a strict ordering.

I will need to have an Equiv relation between two maps (backed up by
Ae for elements). Finally, I would like to be able to prove Proper
instances for basic operations, like:

Instance MapsTo_A_proper:
  Proper ((eq) ==> (equiv) ==> (equiv) ==> iff) (NM.MapsTo).

Instance find_A_proper:
  Proper ((eq) ==> (equiv) ==> (equiv)) (NM.find (elt:=A)).

It looks like the map needs to be abstracted over A using a module.
This post http://www.newartisans.com/2016/10/using-fmap-in-coq/ gives
some good intro but stop shorts from abstracting values. It also looks
like I will need to use Sord functor from FMapInterface. I feel
like all pieces are there but having difficulty putting it all
together. I have not been able to find any relevant examples. Could
somebody please point me in the right direction? Thanks!



Vadim Zaliva A button for name playback in email signature
CMU ECE Ph.D. candidate
Mobile/Signal/WhatsApp: +1(510)220-1060




Archive powered by MHonArc 2.6.18.

Top of Page