我有一个名称以Data.List
结尾的模块。
在其中我想从基础库中导入模块Data.List
。
module Foo.Data.List
import Data.List
如果我从文件夹Foo
调用idris,那么编译器会抱怨:
[Foo]$ idris --check Data/List.idr
Cycle detected in imports: Data/List.idr -> Data/List -> Data/List
我想因为它更喜欢当前源文件夹中的模块,即刚刚定义的模块。
我如何引用基础库中的Data.List
?
我的小源文件:
module Foo.Data.List
import Data.List as S
last : List e -> Maybe e
last l = case l of
(h::t) => Just (S.last (h::t))
_ => Nothing
更新
如果我从包含Foo
的文件夹中调用idris,
idris --check Foo/Data.List.idr
然后我收到错误消息:
When checking right hand side of Foo.Data.List.case block in last at ./Foo/Data/List.idr:6:15 with expected type
Maybe e
When checking argument x to constructor Prelude.Maybe.Just:
Type mismatch between
Maybe e (Type of last (h :: t))
and
e (Expected type)
这意味着编译器将S.last
视为Foo.Data.List.last
而不是base.Data.List.last
。
答案 0 :(得分:0)
给出以下目录结构:
[idris-stuff]$ tree
.
└── myproject
└── Foo
└── Data
└── List.idr
您需要在idris
目录中运行myproject
,而不是myproject/Foo
:
[idris-stuff]$ cd myproject
[myproject]$ idris --check Foo/Data/List.idr
如果您尝试从Foo
运行它,它将失败,因为您的本地Data/List.idr
文件将通过标准库1来挑选:
[myproject]$ cd Foo/
[Foo]$ idris --check Data/List.idr
Cycle detected in imports: Data/List.idr -> Data/List -> Data/List
答案 1 :(得分:0)
您的第二个问题仅仅是因为S.last
不在范围内,因为没有名称为Data.List.last
的定义。您收到的错误消息非常混乱,可能值得报告为Idris错误;一个更好的错误信息就是抱怨S.last
不在范围内。
即便如此,以下版本的类型检查并按预期工作:
module Foo.Data.List
import Prelude.List as S
last : List e -> Maybe e
last l = case l of
(h :: t) => Just (S.last (h::t))
_ => Nothing