我想在REPL中创建myEmptyList
和myNonemptyList
。但是Idris报告了myEmptyList
的类型不匹配错误。为什么?
____ __ _
/ _/___/ /____(_)____
/ // __ / ___/ / ___/ Version 1.3.0
_/ // /_/ / / / (__ ) http://www.idris-lang.org/
/___/\__,_/_/ /_/____/ Type :? for help
Idris is free software with ABSOLUTELY NO WARRANTY.
For details type :warranty.
Idris> :let myEmptyList : List Integer = []
(input):1:33: When checking type of myEmptyList:
When checking argument y to type constructor =:
Type mismatch between
List elem (Type of [])
and
Type (Expected type)
(input):1:18:No type declaration for myEmptyList
Idris> :let myNonemptyList : List Integer = [42]
答案 0 :(得分:4)
不匹配是因为:let myEmptyList : List Integer = []
没有定义myEmptyList
,它仅将其类型声明为List Integer = []
,这是一个相等类型,由于[]
和{ {1}}具有不同的类型。
您可以如下定义List Integer
:myEmptyList
,或者:let myEmptyList : List Integer; myEmptyList = []
。