如何在 Idris REPL 中创建一个空列表?
How to create an empty list in Idris REPL?
我想在 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]
不匹配是因为:let myEmptyList : List Integer = []
没有定义myEmptyList
,它只声明了它的类型List Integer = []
,一个相等类型,这是错误类型因为[]
和 List Integer
有不同的类型。
您可以定义 myEmptyList
如下::let myEmptyList : List Integer; myEmptyList = []
,或者 :let myEmptyList = the (List Integer) []
.
我想在 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]
不匹配是因为:let myEmptyList : List Integer = []
没有定义myEmptyList
,它只声明了它的类型List Integer = []
,一个相等类型,这是错误类型因为[]
和 List Integer
有不同的类型。
您可以定义 myEmptyList
如下::let myEmptyList : List Integer; myEmptyList = []
,或者 :let myEmptyList = the (List Integer) []
.