在Coq 8.6中使用FMap的正确方法?

时间:2017-01-07 14:56:48

标签: dictionary coq

我正在尝试在Coq中使用基于树的地图,特别是Coq.FSets.FMapAVL

我发现了这个4岁的问题:Finite map example

查看评论中引用的标准lib文档,我看到了这个注释:

  

注意:此文件仅用于与早期版本的FSets和FMap兼容。请立即使用Structures / Orders.v。

这是什么意思?当我google" Structures.v"或" Orders.v"我总是在其他文档页面上找到相关的弃用警告。

在Coq 8.6中使用FMap的正确,不推荐的方法是什么?

1 个答案:

答案 0 :(得分:3)

由于OrderedTypeEx模块已弃用,我们不会使用其中定义的Nat_as_OT

Nat_as_OT中有OrdersEx(只是PeanoNat.Nat的同义词),这对我们来说非常有用。

不幸的是,以下代码

Require Import Coq.Structures.OrdersEx.
Module M := FMapAVL.Make Nat_as_OT.

无法正常工作,因为签名OrderedType.OrderedType(目前由FMapAVL使用)和Orders.OrderedType不兼容。

但是,OrdersAlt模块包含仿函数,这些仿函数允许从另一个类型构建一个类型的模块。在这种情况下,我们对Backport_OT感兴趣。以下代码显示了如何使用FMapAVL.Make,其余代码可以从链接的问题中复制:

From Coq Require Import
FSets.FMapAVL Structures.OrdersEx Structures.OrdersAlt.

Module backNat_as_OT := Backport_OT Nat_as_OT.
Module M := FMapAVL.Make backNat_as_OT.

Pierre {4}}在this Coq-Club post解释了FMapAVL的情况:

  

旧式OrderedType与新式FMaps之间的过渡并非如此   已完成(例如,OrderedType仍有一些工作要做),   我们不能简单地删除旧式 func createPDF() { var html = "<b>Hello <i>World!</i></b> <p>Generate PDF file from HTML in Swift</p><html><head><title><h2>Form Data</h2></title><style>table {font-family: arial, sans-serif;border-collapse: collapse;width: 100%;}td, th {border: 1px solid #dddddd;text-align: left;padding: 8px;}tr:nth-child(even) {background-color: #dddddd;}</style></head><body><img src='test.jpg' alt='Red dot' /><table><tr><th>Company</th><th>Contact</th><th>Country</th></tr><tr><td>This column is for testing the width and the wrapping of the text so that i can use this format for preparing the table for my project.</td><td>Maria Anders</td><td>Germany</td></tr><tr><td>Centro comercial Moctezuma</td><td>Francisco Chang</td><td>Mexico</td></tr><tr><td>Ernst Handel</td><td>Roland Mendel</td><td>Austria</td></tr><tr><td>This column is for testing the width and the wrapping of the text so that i can use this format for preparing the table for my project.</td><td>Maria Anders</td><td>Germany</td></tr><tr><td>Centro comercial Moctezuma</td><td>Francisco Chang</td><td>Mexico</td></tr><tr><td>Ernst Handel</td><td>Roland Mendel</td><td>Austria</td></tr><tr><td>This column is for testing the width and the wrapping of the text so that i can use this format for preparing the table for my project.</td><td>Maria Anders</td><td>Germany</td></tr><tr><td>Centro comercial Moctezuma</td><td>Francisco Chang</td><td>Mexico</td></tr><tr><td>Ernst Handel</td><td>Roland Mendel</td><td>Austria</td></tr><tr><td>This column is for testing the width and the wrapping of the text so that i can use this format for preparing the table for my project.</td><td>Maria Anders</td><td>Germany</td></tr><tr><td>Centro comercial Moctezuma</td><td>Francisco Chang</td><td>Mexico</td></tr><tr><td>Ernst Handel</td><td>Roland Mendel</td><td>Austria</td></tr><tr><td>This column is for testing the width and the wrapping of the text so that i can use this format for preparing the table for my project.</td><td>Maria Anders</td><td>Germany</td></tr><tr><td>Centro comercial Moctezuma</td><td>Francisco Chang</td><td>Mexico</td></tr><tr><td>Ernst Handel</td><td>Roland Mendel</td><td>Austria</td></tr><tr><td>This column is for testing the width and the wrapping of the text so that i can use this format for preparing the table for my project.</td><td>Maria Anders</td><td>Germany</td></tr><tr><td>Centro comercial Moctezuma</td><td>Francisco Chang</td><td>Mexico</td></tr><tr><td>Ernst Handel</td><td>Roland Mendel</td><td>Austria</td></tr><tr><td>This column is for testing the width and the wrapping of the text so that i can use this format for preparing the table for my project.</td><td>Maria Anders</td><td>Germany</td></tr><tr><td>Centro comercial Moctezuma</td><td>Francisco Chang</td><td>Mexico</td></tr><tr><td>Ernst Handel</td><td>Roland Mendel</td><td>Austria</td></tr><tr><td>This column is for testing the width and the wrapping of the text so that i can use this format for preparing the table for my project.</td><td>Maria Anders</td><td>Germany</td></tr><tr><td>Centro comercial Moctezuma</td><td>Francisco Chang</td><td>Mexico</td></tr><tr><td>Ernst Handel</td><td>Roland Mendel</td><td>Austria</td></tr><tr><td></td><button type='button'>B1tton1</button><td></td></tr></table></body></html>" var myData: String = "" for i in 1...50 { myData = myData + "Value is : \(i)" } html = html + myData let fmt = UIMarkupTextPrintFormatter(markupText: html) // 2. Assign print formatter to UIPrintPageRenderer let render = UIPrintPageRenderer() render.addPrintFormatter(fmt, startingAtPageAt: 0) // 3. Assign paperRect and printableRect let page = CGRect(x: 0, y: 0, width: 595.2, height: 841.8) // A4, 72 dpi let printable = page.insetBy(dx: 0, dy: 0) render.setValue(NSValue(cgRect: page), forKey: "paperRect") render.setValue(NSValue(cgRect: printable), forKey: "printableRect") // 4. Create PDF context and draw let pdfData = NSMutableData() UIGraphicsBeginPDFContextToData(pdfData, CGRect.zero, nil) for i in 1...render.numberOfPages { UIGraphicsBeginPDFPage(); let bounds = UIGraphicsGetPDFContextBounds() render.drawPage(at: i - 1, in: bounds) } UIGraphicsEndPDFContext(); // 5. Save PDF file let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] print(documentsPath) //let bundlePath = Bundle.main.bundlePath+"/PdfFiles/" pdfData.write(toFile: "\(documentsPath)/file3.pdf", atomically: true) }