如何在Idris REPL中创建一个空列表?

时间:2018-09-25 13:26:38

标签: list read-eval-print-loop typechecking idris dependent-type

我想在REPL中创建myEmptyListmyNonemptyList。但是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]

1 个答案:

答案 0 :(得分:4)

不匹配是因为:let myEmptyList : List Integer = []没有定义myEmptyList,它仅将其类型声明为List Integer = [],这是一个相等类型,由于[]和{ {1}}具有不同的类型。

您可以如下定义List IntegermyEmptyList,或者:let myEmptyList : List Integer; myEmptyList = []