Where do I import Cons from?

I am working through Chapter 3 of the PureScript Book and I have a possibly very silly question: How do I import the list Constructor Cons?

I tried in the REPL:

> import Data.List (Cons)     

But I get the following error:

> Error found:
in module $PSCI
at :1:19 - 1:23 (line 1, column 19 - line 1, column 23)

  Cannot import type Cons from module Data.List
  It either does not exist or the module does not export it.

This is very strange to me. Pursuit lists Cons as part of Data.List (but only very briefly - probably because it is not a function), but somehow I cannot import it.

data constructors are imported via the type they construct:

import Data.List (List(Cons, Nil))
-- or more commonly used
import Data.List (List(..))
1 Like

Thanks for chiming in!

Ok, i just tried it, but I get

> Unexpected token 'import' at line 1, column 1

Actually, looking at some sample code I noticed there it written with only two periods:

import Data.List (List(..))

Now I don’t get an error and Cons is available. Super thanks!


Oh, sorry that was a typo. I’ve edited the original response. Thanks!

FWIW this is not a silly question at all, it’s a common source of confusion, and I think the compiler should do more to explain what’s happened and suggest what you probably wanted to write; see Add hint when trying to import a data constructor as if it is a type · Issue #3925 · purescript/purescript · GitHub