Haskell Failed to load interface for module - haskell

Hello i am trying to use a module inside another module but it seems it just won't work.I tried updating the cabal file,stack,i reinstalled the platform,ghc and everything and it just won't let it import modules.I tried adding in the cabal file both other-modules and home-modules section ..to no effect.What could be the problem?
Modules:
module Test where
test::IO()
test=do
elem<-getLine
print elem
module Main where
import Test
main :: IO ()
main = do
putStrLn "hello world"
Cabal-build renders this error:
$ cabal build
Resolving dependencies...
Configuring console-0.1.0.0...
Warning: To use the 'default-language' field the package needs to specify at
least 'cabal-version: >= 1.10'.
Preprocessing executable 'console' for console-0.1.0.0..
Building executable 'console' for console-0.1.0.0..
<no location info>: warning: [-Wmissing-home-modules]
These modules are needed for compilation but not listed in your .cabal file's other-modules: Test
<no location info>: warning: [-Wmissing-home-modules]
These modules are needed for compilation but not listed in your .cabal file's other-modules: Test
When i build with Stack i get this error:
C:\<path>\Main.hs:4:1: error:
Failed to load interface for `Test'
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
H>>= :module + *Main
Cabal file:
name: console
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/githubuser/console#readme
license: BSD3
license-file: LICENSE
author: Bercovici Adrian Simon
maintainer: example#example.com
copyright: 2018 Bercovici Adrian Simon
category: Web
build-type: Simple
cabal-version: >=1.2
extra-source-files: README.md
Executable console
hs-source-dirs: src
main-is: Main.hs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
other-modules: Test

The other-modules: directive must go inside the Executable console stanza.

Related

Unable to add classy-prelude dependency

I am trying to add classy-prelude dependency to my stack project as follows:
name: FooService
version: 0.1.0.0
github: "githubuser/FooService"
license: BSD3
author: "Author name here"
maintainer: "example#example.com"
copyright: "2019 Author name here"
extra-source-files:
- README.md
- ChangeLog.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/FooService#readme>
dependencies:
- base >= 4.7 && < 5
- classy-prelude
default-extesion:
- NoImplicitPrelude
- OverloadedStrings
library:
source-dirs: src
executables:
FooService-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- FooService
tests:
FooService-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- FooService
when call the interactive environment I've got the error message:
Using main module: 1. Package `FooService' component FooService:exe:FooService-exe with main-is file: /home/developer/haskell/FooService/app/Main.hs Cabal file info not found for classy-prelude-1.5.0#sha256:ed1a607f688745bc263be0b2ed2492729a62fd4c9821b68c2bfacbd7a9d9293d,1928, updating Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/ Downloading timestamp No package index update available, but didn't update cache last time, running now Calculating hashes to check for hackage-security rebases or filesystem changes Updating preexisting cache, should be quick Populating cache from file size 640326144, hash bb56d41c70c9e6cdd625a6c3c7de5f56823e92cc6fe880f8056259ab31d3e0d5 Populating package index cache ... Failed populating package index cache
Error: BadChecksum 0
Warning: Build failed, but trying to launch GHCi anyway The following GHC options are incompatible with GHCi and have not been passed to it:
-threaded Configuring GHCi with the following packages: FooService GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help <command line>: cannot satisfy -package classy-prelude-1.5.0
What is missing?

How to fix a "could not find module" error in Cabal, when it seems correctly specified?

I'm currently not using stack at all on this project (just Cabal), and all was going well when everything was in Main.hs. I decided to split up code, moving my dhall dep and related code from my executable deps to my library deps, and now seem to have this strange error when running cabal new-build:
Building executable 'FarmDataServer.exe' for FarmDataServer-0.1.0.0..
<no location info>: warning: [-Wmissing-home-modules]
These modules are needed for compilation but not listed in your .cabal file's other-modules: FDS
FDS.Config.Core
FDS.Config.DhallConf
[2 of 4] Compiling FDS.Config.DhallConf ( src/FDS/Config/DhallConf.hs, /home/brandon/workspace/CIDA/FarmDataServer/dist-newstyle/buil
d/x86_64-linux/ghc-8.4.4/FarmDataServer-0.1.0.0/x/FarmDataServer.exe/build/FarmDataServer.exe/FarmDataServer.exe-tmp/FDS/Config/Dhall
Conf.o )
src/FDS/Config/DhallConf.hs:7:1: error:
Could not find module `Dhall'
Use -v to see a list of the files searched for.
|
7 | import Dhall
| ^^^^^^^^^^^^^^^^^^^^^^
Certainly I'm also a bit confused by the Wmissing-home-modules message since I seem to have added those in my cabal file.
Relevant bits of my .cabal file:
cabal-version: 2.4
name: FarmDataServer
version: 0.1.0.0
library
exposed-modules:
FDS
other-modules:
FDS.Config.Core
, FDS.Config.DhallConf
build-depends: base ^>=4.11.1.0
, conduit ^>=1.3.1
, csv-conduit ^>=0.7.0.0
, dhall ^>=1.20.0
, text ^>=1.2.3.1
hs-source-dirs: src
executable FarmDataServer.exe
main-is: Main.hs
build-depends: base ^>=4.11.1.0
, conduit ^>=1.3.1
, csv-conduit ^>=0.7.0.0
, scotty ^>=0.11.3
, text ^>=1.2.3.1
, FarmDataServer ^>=0.1.0.0
My src folder:
$ pwd
/home/brandon/workspace/CIDA/FarmDataServer/src
$ du -a
4 ./FDS/Config/DhallConf.hs
4 ./FDS/Config/Core.hs
12 ./FDS/Config
16 ./FDS
4 ./FDS.hs
4 ./Main.hs
28 .
For the missing modules, sink your program executable into a directory such that the module hierarchy for yoru library isn't visible:
mkdir program ; mv src/Main.hs program/
and in cabal for the executable
hs-source-dirs: program
For your missing module Dhall, add the dhall build dependency to your executable stanza in the cabal file.

Haskell cabal confused about file and module name

In my haskell project, I have the following directory structure (some entries are missing but not relevant to this problem)
- quanthas
- quanthas.cabal
- src/
- QuantHas/
- Settings.hs
My Settings.hs file contains this module header
module QuantHas.Settings(module QuantHas.Settings) where
My cabal file looks like this
Name: QuantHas
Version: 0.0
Description:
QuantHas project is an attempt to port QuantLib to Haskell keeping the functional flavor of Haskell.
License: BSD3
License-file: LICENSE
Build-Type: Simple
Cabal-Version: >=1.10
Library
Build-Depends: base >= 3 && < 5, array >= 0.2
Exposed-modules: QuantHas.Time.Frequency
QuantHas.Time.TimeUnit
QuantHas.Time.Period
QuantHas.Time.Date
QuantHas.Time.DayCounter
QuantHas.Time.BusinessDayConvention
QuantHas.Time.Calendar
QuantHas.Time.Calendars.UnitedKingdom
QuantHas.Time.Schedule
QuantHas.Settings
QuantHas.Require
default-language: Haskell2010
hs-source-dirs: src
-- ghc-options: -Wall
test-suite QuantHas-tests
type: exitcode-stdio-1.0
hs-source-dirs: testsuite
main-is: Tests.hs
default-language: Haskell2010
When I execute
cabal install --enable-tests
I get this message
src/Quanthas/Settings.hs:17:8: error:
File name does not match module name:
Saw: ‘QuantHas.Settings’
Expected: ‘Quanthas.Settings’
This seems wrong. However, what if we do what cabal expects. So the Settings.hs module header now is
module Quanthas.Settings(module Quanthas.Settings) where
Cabal now says
src/QuantHas/Settings.hs:17:8: error:
File name does not match module name:
Saw: ‘Quanthas.Settings’
Expected: ‘QuantHas.Settings’
And it's at this ppint that I give up and turn to SO. Can anyone help me understand what is going on?
Versions info:
Platform: Macbook Pro running MacOS 10.12.3
Haskell: 8.0.1
Cabal: 1.24.0.0
Thanks!
The issue is that there is a typo in one of the import statements in a different module. Since you're on a case-insensitive filesystem (OS X), GHC is able to find the module contents, but upon checking the module header finds it mismatches with the import statement and errors out.

cabal build for my project fails linking llvm-general package

I have a cabal project, when I issue cabal build I get this :
Building phjava-0.1.0.0...
Preprocessing executable 'phjava' for phjava-0.1.0.0...
[2 of 3] Compiling CodeGen ( src/CodeGen.hs, dist/build/phjava/phjava-tmp/CodeGen.o )
<no location info>: error:
<command line>: can't load .so/.DLL for: /usr/lib/libcurses.so (-lncursesw: cannot open shared object file: No such file or directory)
This is the output with --verbose=3 : verbose output
This is my cabal file :
name: phjava
version: 0.1.0.0
synopsis:
-- description:
-- license:
-- license-file:
homepage:
author: abnud1
maintainer: ahmad13932013#hotmail.com
category: Language
-- copyright:
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
executable phjava
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >= 4.7 && < 5 , parsec < 4, containers < 1 , regex-pcre < 1 , parsec-permutation < 1 , transformers < 1 , logfloat < 0.14, llvm-general-pure < 4, llvm-general, mtl < 3
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall
I have ghc 8.0.1, cabal 1.24, llvm-3.8.1 . I installed llvm-general by cloning the llvm-3.8 branch and running cabal install with -fshared-llvm.
I assure you I have ncurses installed, also libcurses.so file is a symlink to /usr/lib/libncurses.so, I also have /usr/lib/libncursesw.so (which is also a symlink to /usr/lib/libncursesw.so.6).
Last my OS is Arch Linux 64 bit and I also have ncurses5-compat-libs installed from AUR(and uninstalling it didn't help).

Dynamic code loading w/ Haskell

I've been playing around with the plugins package. I want a host application to dynamically compile and load Haskell source files in a sandboxed environment. Compilation works just fine. Loading fails as soon as the plugin references modules available in the sandbox only. Here is what I've got for the plugin:
module Plugin (resource) where
import ServerAPI
import System.Plugins -- this module is only available in the sandbox
resource = Interface { action = timesTwo }
timesTwo :: Integer -> IO Integer
timesTwo n = return $ n * 2
Loading the plugin from the host application looks like this:
pkgConfDir = "/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
loadedOk <- pdynload "Plugin.o" ["."] [pkgConfDir] "ServerAPI.Interface" "resource"
This is what I've got in the sandbox:
> cabal sandbox hc-pkg list
…
/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
plugins-1.5.4.0
…
This is what I get when running the host application:
Failed to load interface for ‘System.Plugins.Env’
no package matching ‘plugins-1.5.4.0’ was found
As mentioned above, when I get rid of the import System.Plugins statement in the plugin the code does load. What am I missing?
Edit:
The cabal file:
name: plugins
version: 0.1.0.0
-- synopsis:
-- description:
-- license:
license-file: LICENSE
author: W. Davis
maintainer: w.davis#spam.me.not
-- copyright:
-- category:
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
executable plugins
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.7 && <4.8, plugins >=1.5 && <1.6
-- hs-source-dirs:
default-language: Haskell2010

Resources