Type annotation for function does not recognize imported type

If I import the Set module and then use the Set type in a function definition I get an error that the type is not recognized.

import Set

checkSet : Set Char -> Char -> (Bool, Set Char)
checkSet s c =
  (False, s)

gives the error

I cannot find a `Set` type:

13| checkSet : Set Char -> Char -> (Bool, Set Char)
These names seem close though:


Hint: Read <https://elm-lang.org/0.19.1/imports> to see how `import`
declarations work in Elm.

However the same file with the same import CAN make use of a Set in a function without Set in the type annotation.

import Set

checkSetLen: String -> Bool
checkSetLen s =
  let len = Set.size (Set.fromList (String.toList s))
    len == String.length s

Is this a compiler bug?

By doing import Set you have imported the Set module but not the Set type.

You will need to import the type or used it as qualified.


import Set exposing (Set)

checkSet : Set Char

or (qualified)

import Set

checkSet : Set.Set Char

Thank you. Perhaps the compiler message could be improved when there is an import of a module with the same name as the type in question.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.