如何准确地选择cong?

时间:2018-10-02 02:40:03

标签: agda

我正在查看from tkinter import * from tkinter import ttk from tkinter.scrolledtext import ScrolledText import tkinter as tk from tkinter import Menu, filedialog root = Tk() root.title('To - Do List') root.state('zoomed') rows = 0 while rows < 50: root.rowconfigure(rows, weight = 1) root.columnconfigure(rows, weight = 1) rows = rows + 1 class Everything: def __init__(self, font, justify, size): self.font = font self.justify = justify self.size = size def CreateNewTaskFunction(self): ttk.frame() Notebook.add(ttk.frame(), text = 'First Note') # -------------------------------------------------------------------------------------------------------- x = 1 def NewInstance(): global x NewTaskDictionary = {"Task1":"Task1", "Task2":"Task2", "Task2":"Task2", "Task3":"Task3", "Task4":"Task4", "Task5":"Task5", "Task6":"Task6", "Task7":"Task7", "Task8":"Task8"} NewTaskDictionary["Task" + str(x)] = Notebook.add(ttk.Frame(), text = 'Welcome To Your Notes: Click Here') NewTxtDictionary = {"Txt1":"Txt1", "Txt2":"Txt2", "Txt3":"Txt3", "Txt4":"Txt4", "Txt5":"Txt5", "Txt6":"Txt6", "Txt7":"Txt7", "Txt8":"Txt8"} NewTxtDictionary["Txt" + str(x)] = tk.Text(NewTaskDictionary["Task" + str(x)]) NewTxtDictionary["Txt" + str(x)].grid(column = 1, row = 2, columnspan = 48, rowspan = 47, sticky = 'NESW') NewScrollDictionary = {"Scroll1":"Scroll142432423", "Scroll2":"Scroll2", "Scroll3":"Scroll3", "Scroll4":"Scroll4", "Scroll5":"Scroll5", "Scroll6":"Scroll6"} NewScrollDictionary["Scroll" + str(x)] = tk.Scrollbar(NewTaskDictionary["Task" + str(x)]) NewScrollDictionary["Scroll" + str(x)].grid(column = 50, row = 2, rowspan = 46, sticky = 'NESW') NewTxtDictionary["Txt" + str(x)]['yscrollcommand'] = NewScrollDictionary["Scroll" + str(x)].set print(NewScrollDictionary["Scroll" + str(x)]) NewScrollDictionary["Scroll" + str(1)] = "81290830912830912830912903" y = NewScrollDictionary["Scroll1"] print(y) x += 1 style = ttk.Style() current_theme =style.theme_use() style.theme_settings(current_theme, {"TNotebook.Tab": {"configure": {"padding": [20, 5], "background" : "white"}}}) style.theme_settings(current_theme, {"TNotebook" : {"configure" : {"tabposition" : "wn", "padding" : (0, 5)}}}) style.theme_settings(current_theme, {"TNotebook.Window" : {"configure" : {"width" : 500}}}) Notebook = ttk.Notebook(root) Notebook.grid(row = 1, column = 0, columnspan = 50, rowspan = 49, sticky = 'NESW') Photo2 = PhotoImage(file="Add Task Image Button.png") NewTaskButton = Button(root, image=Photo2, borderwidth=0, highlightthickness=0, command = NewInstance).grid(row=0, column=45, columnspan = 5, sticky="e", ipady = [5]) Photo1= PhotoImage(file="Final Logo.png") Label(image=Photo1, borderwidth=0, highlightthickness=0).grid(row=0, column=0, sticky=W, ipady = [5]) # Defaults root.mainloop() 的定义:

cong

而且我不明白为什么它的类型正确。特别是,似乎cong : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {x y} → x ≡ y → f x ≡ f y cong f refl = refl 的隐式参数必须同时为reflf x。为了使事情更清楚,我编写了一个非隐式的相等版本,并尝试复制该证明:

f y

这会导致类型错误:

data Eq : (A : Set) -> A -> A -> Set where
  refl : (A : Set) -> (x : A) -> Eq A x x

cong : (A : Set) -> (B : Set) -> (f : A -> B) -> 
       (x : A) -> (y : A) -> (e : Eq A x y) -> Eq B (f x) (f y)
cong A B f x y e = refl B (f x)

正如人们所期望的那样。除了x != y of type A when checking that the expression refl B (f x) has type Eq B (f x) (f y) ,我可能还有什么?我想念什么吗?

1 个答案:

答案 0 :(得分:5)

为您提供的相关模式匹配。

如果我们在您的cong上打了个洞

cong : (A : Set) -> (B : Set) -> (f : A -> B) ->
       (x : A) -> (y : A) -> (e : Eq A x y) -> Eq B (f x) (f y)
cong A B f x y e = {!refl B (f x)!}

仔细研究,我们将会看到

Goal: Eq B (f x) (f y)
Have: Eq B (f x) (f x)

所以值的确不同。但是一旦您在e上进行模式匹配,就可以:

cong : (A : Set) -> (B : Set) -> (f : A -> B) ->
       (x : A) -> (y : A) -> (e : Eq A x y) -> Eq B (f x) (f y)
cong A B f x y (refl .A .x) = {!refl B (f x)!}

揭示了xy相同的事实,并且上下文被无声重写:y的每次出现都被x代替,因此请仔细研究我们现在看到的洞

Goal: Eq B (f x) (f x)
Have: Eq B (f x) (f x)

请注意,我们可以写

cong A B f x .x (refl .A .x) = refl B (f x)

即根本不绑定y,而只是通过点模式说它与x相同。我们通过在e : Eq A x y上进行模式匹配获得了这些信息,因为一旦执行了匹配,我们便知道实际上是e : Eq A x x,因为这就是refl的类型签名所说的。 Eq A x yEq A x x的统一得出了一个简单的结论:y等于x,并相应地调整了整个上下文。

与Haskell GADT的逻辑相同:

data Value a where
  ValueInt  :: Int  -> Value Int
  ValueBool :: Bool -> Value Bool

eval :: Value a -> a
eval (ValueInt  i) = i
eval (ValueBool b) = b

当您在ValueInt上匹配并获得类型i的{​​{1}}时,您还会发现Int等于a并将此知识添加到上下文中(通过等式约束),使得Inta在以后无法确定。结果就是我们能够返回Int的原因:因为我们从上下文知道,所以类型签名中的ia完美地结合在一起。