0

I have a module whose name ends with Data.List. Inside it i want to import module Data.List from the base library.

module Foo.Data.List
import Data.List

If i invoke idris from folder Foo then compiler complains:

[Foo]$ idris --check Data/List.idr
Cycle detected in imports: Data/List.idr -> Data/List -> Data/List

I guess because it prefers the module being in the current source folder, that is the module just being defined.

How can i refer to the one Data.List which is in the base library?

My little source file in its full:

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 

Updated:

If i invoke idris from the folder containing Foo,

idris --check Foo/Data.List.idr

then I get the error message:

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)

Which implies that the compiler considers S.last as Foo.Data.List.last instead of base.Data.List.last.

Cactus
  • 27,075
  • 9
  • 69
  • 149
libeako
  • 2,324
  • 1
  • 16
  • 20

2 Answers2

0

Given the following directory structure:

[idris-stuff]$ tree
.
└── myproject
    └── Foo
        └── Data
            └── List.idr

you will need to run idris in the myproject directory, not myproject/Foo:

[idris-stuff]$ cd myproject
[myproject]$ idris --check Foo/Data/List.idr

If you try to run it from Foo, it will fail because your local Data/List.idr file will be picked over the standard library one:

[myproject]$ cd Foo/
[Foo]$ idris --check Data/List.idr
Cycle detected in imports: Data/List.idr -> Data/List -> Data/List
Cactus
  • 27,075
  • 9
  • 69
  • 149
  • What would be a solution is for example ability to refer to standard lib with a unique path prefix, like "base". – libeako Feb 28 '16 at 07:16
  • It will not pick `Foo.Data.list` when you `import Data.List` in your other modules, unless you mistakenly try to compile those other modules from inside `Foo` as well. – Cactus Feb 28 '16 at 07:37
0

Your second problem is caused simply by the fact that S.last is not in scope, since there is no definition with the name Data.List.last. The error message you get is very confusing and might be worth reporting as an Idris bug; a much better error message would be one that complains about S.last not being in scope.

To wit, the following version typechecks and works as expected:

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
Cactus
  • 27,075
  • 9
  • 69
  • 149
  • It does not matter if base/Data.Last.last exists or not. The compiler does find S.last as Foo.Data.List.last - this of course leads to type error. The problem is that S = Foo.Data.List instead of base/Data.List. – libeako Mar 03 '16 at 19:56