当我尝试编译这个例子时
record R where
f: () -> {t: Type} -> t
我收到此错误:
Type mismatch between
() -> t1 (Type of f)
and
() -> t (Expected type)
Specifically:
Type mismatch between
t1
and
t
另一方面这个例子
record R where
f: {t: Type} -> () -> t
工作得很好。你能告诉我第一个出了什么问题吗?
答案 0 :(得分:1)
这是Idris中的错误:有时import random
# Sentences we'll respond with if the user greeted us
GREETING_KEYWORDS = ("hello", "hi", "greetings", "sup", "whats up", "You")
GREETING_RESPONSES = ["sup buddy", "Hola", "Halo", "Hi back?"]
def check_for_greeting(sentence):
"""If any of the words in the user's input was a greeting, return a greeting response"""
if sentence is not None:
for word in sentence:
if word.lower() in GREETING_KEYWORDS:
return random.choice(GREETING_RESPONSES)
else:
pass
elif sentence is None:
return "You got to say something if you want me to do the same."
else:
return "Something is wrong..."
def chat_input():
x = input("")
print(check_for_greeting(x))
# Run
print("chat with me...")
chat_input()
运算符不是右关联的:issue #4077。
要看到它,我们可以去掉记录语法:
->
现在我们需要手动实施data R : Type where
MkR : (() -> {t : Type} -> t) -> R
投影。事实证明
f
不类型检查,但是
f : R -> (() -> {t : Type} -> t)
f (MkR g) = g
确实
在我看来,Idris使用第一个变体将f : R -> () -> {t : Type} -> t
f (MkR g) = g
变为record
,因此出现了错误。