Unable to import modules in haskell - haskell

I'm really new to haskell, and I'm having a problem importing any modules whatsoever.
When I load an .hs file that contains nothing but
import Data.list
it gives me an error of
file.hs:1:8: parse error on input Data.list
I know I must be making a really basic error somewhere, because imports seem to be working for everyone else, even in all the tutorials. Is it because I've changed my directory with :cd? Or is it how my GHCi was downloaded?

Modules start with capital letters
import Data.List

Module names are capitalized.
Capitalize the word "List".
import Data.List

Related

inspect.py file in folder makes importing pandas not work anymore

I am sorry if this is a silly question but I came across a wierd behaviour. I have a folder with some files, one of them named inspect.py
However, if I change the name inspect.py to somethingelse.py, importing pandas starts working.
I would really like to understand why this is. I assume it has something to do with the module called inspect which (I THINK??) comes by default installed.
Can anyone help me understand this, please?
Looking a np.ma.core.py I see
import builtins
import inspect
import operator
import warnings
import textwrap
import re
These are all base Python modules. Your local inspect.py gets imported instead, which messes with the importing the rest of np.ma.core, and numpy in turn. And pandas depends on numpy.

How to use hidden modules in haskell

I am trying to import ByteArray ,from the Cryptonite library.
My cabal file has cryptonite in the Build depends ,and my import statement looks like this
import Crypto.Internal.ByteArray (ByteArray, Bytes)
import qualified Crypto.Internal.ByteArray as B
The error I get is
Could not load module ‘Crypto.Internal.ByteArray’
it is a hidden module in the package ‘cryptonite-0.25’
I have seen other code examples which use this specific import statement ,what am I missing here?
As per GHC Docs, hidden modules
"cannot be imported, but they are still subject to the overlapping
constraint: no other package in the same program may provide a module
of the same name."

Haskell: dealing with ambiguous imports

I'm getting ambiguity warnings, sometimes errors, all the time. This is just a clear cut example. I'm using doctest:
$ stack exec doctest -- src/Main.hs
<interactive>:6:14:
Ambiguous occurrence ‘stdout’
It could refer to either ‘Turtle.stdout’,
imported from ‘Turtle’ at src/Main.hs:6:1-13
(and originally defined in ‘Turtle.Prelude’)
or ‘System.IO.stdout’,
imported from ‘System.IO’
(and originally defined in ‘GHC.IO.Handle.FD’)
...
Examples: 2 Tried: 2 Errors: 0 Failures: 0
It obviously works, at least for the time being, but these warnings are voluminous, annoying, and probably dangerous.
I tried to cope with hiding, like this (Main.hs, all the imports):
import Turtle
import Prelude hiding (FilePath)
import System.IO hiding (FilePath, stdout, stderr) -- trying to hide std...
import Text.Regex.TDFA
but it makes no difference.
Is there a correct general approach?
Well you could edit your .ghci file and include
:m - Prelude
this way GHCi should not preload the Prelude but like Jubobs I would suggest that you don't reuse those names in the first place or that you import (qualified) with some combination of
import Turtle hiding (stdout)
import qualified Turtle as T
import Turtle ( noOverlappingFunc, NonOverlappingType )
it's just the minor inconvenience of writing
T.stdout
instead.
IMHO it's not a good idea to hide stuff from the Prelude to much - aside from the problems you saw there is always the problem of peaple reading your code and their expectations

Warning: The import of `Module` is redundant except perhaps to import instances from `Module`

I've recently started coding in Sublime Text. This has brought to my attention some warnings I didn't notice when I used Leksah. So I got this one:
import qualified Data.Set as S
Gives:
Warning:
The qualified import of `Data.Set' is redundant
except perhaps to import instances from `Data.Set'
To import instances alone, use: import Data.Set()
On the other hand, either of these two imports from Data.Foldable don't give any warnings:
import Data.Foldable (foldrM, mapM_,foldr,foldl',concat)
-- or
import Data.Foldable
So I'm not really sure what the warning for Data.Set means. I would expect "redundant" means that it's not necessary. If I remove the import it doesn't compile because I'm using a lot of things for Data.Set.
Meanwhile sitting next to it is import qualified Data.Map as M which also gives no warnings.
So I'm completely confused about what that warning is saying.
It generally means either :
you import a module but you don’t use it at all,
you import a module that is already imported by another module you import.
It may be the effect of some refactoring where you don’t use the module anymore. Or maybe you’ve anticipated the future use of this module by importing it.
This message is generated when you compile your project using the -Wall option.
Try to delete the line which shows the error, it often works ;-)

Explain Haskell empty import list ()

I saw much lines like import HSP.ServerPartT() - list of imports is empty. Why is this done? What difference with just not importing this module?
It imports only typeclass instances from the module. With -Wall, GHC issues a warning for modules that are imported but from which no definitions are used:
foo.hs:1:1:
Warning: The import of `M' is redundant
except perhaps to import instances from `M'
To import instances alone, use: import M()
The empty import list silences this warning and serves as documentation of the purpose of the import.
That form imports nothing but the instances from that module. And that's the reason of that form, you want to have the instances in scope, but nothing else.

Resources