Could not load my own modules in ghci haskell - haskell

i am trying to load a module called Point.hs into a file called Circle.hs by this way:
module Figures.Circle
( Circle(..)
, getArea
, getPerimeter
) where
import qualified Figures.Point as P
here is my Point.hs file:
module Figures.Point
( Point(..)
) where
this is my directory´s tree:
Figures/
Point.hs
Circle.hs
and this is what ghci´s error says:
Circle.hs:7:1: error:
Could not find module `Figures.Point'
Locations searched:
Figures\Point.hs
Figures\Point.lhs
Figures\Point.hsig
Figures\Point.lhsig
|
7 | import qualified Figures.Point as P
I follow this guide.

I get the same error if I call ghci from within the Figures directory, that can be avoided by calling ghci from the parent directory, so ghci Figures\Circle.hs.

Related

Fay can't find fay-base

I want to use Fay with Yesod, but can't get Fay typechecking to work.
Will appreciate any advice.
$ stack build
[ 9 of 11] Compiling Handler.Home ( src/Handler/Home.hs, .stack-work/dist/x86_64-linux-dkda49f7ca9b244180d3cfb1987cbc9743/Cabal-2.4.0.1/build/Handler/Home.o )
/home/user/code/myproject/src/Handler/Home.hs:121:13: error:
_ Exception when trying to run compile-time code:
ghc-pkg describe error:
Timestamp 2019-05-07 18:46:44 UTC for /opt/ghc/8.6.5/lib/ghc-8.6.5/package.conf.d/package.cache
ghc-pkg: cannot find package fay-base <- ########### Why?
GHC package manager version 8.6.5
using cache: /opt/ghc/8.6.5/lib/ghc-8.6.5/package.conf.d/package.cache
db stack: ["/opt/ghc/8.6.5/lib/ghc-8.6.5/package.conf.d"]
flag db stack: ["/opt/ghc/8.6.5/lib/ghc-8.6.5/package.conf.d"]
CallStack (from HasCallStack):
error, called at src/Fay/Compiler/Packages.hs:70:24 in fay-0.24.0.3-CdLcUWVJEOpLCiYHkNVTai:Fay.Compiler.Packages
Code: fayFile' (ConE 'StaticR) "HelloWorld"
_ In the untyped splice: $(fayFile' (ConE 'StaticR) "HelloWorld")
|
121 | $( fayFile' (ConE 'StaticR) "HelloWorld" )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Fay packages are not yet in stackage, so I added them to stack.yaml as extra-deps:
extra-deps: - fay-0.24.0.3
- fay-base-0.21.1.1
- fay-dom-0.5.0.1
- fay-text-0.3.2.2
- yesod-fay-0.10.0
and to package.yaml as dependencies:
dependencies:
... more dependencies ...
- fay == 0.24.0.3
- fay-base == 0.21.1.1
- fay-dom == 0.5.0.1
- fay-text == 0.3.2.2
- yesod-fay == 0.10.0
Fay packages are in the local package database:
$ stack exec -- ghc-pkg list
/opt/ghc/8.6.5/lib/ghc-8.6.5/package.conf.d
Cabal-2.4.0.1
array-0.5.3.0
base-4.12.0.0
...
/home/user/.stack/snapshots/x86_64-linux-dkda49f7ca9b244180d3cfb1987cbc9743/lts-13.30/8.6.5/pkgdb
Cabal-2.4.1.0
Diff-0.3.4
HUnit-1.6.0.0
...
yesod-1.6.0
yesod-core-1.6.14
yesod-form-1.6.5
yesod-newsfeed-1.6.1.0
yesod-persistent-1.6.0.2
yesod-static-1.6.0.1
/home/user/code/myproject/.stack-work/install/x86_64-linux-dkda49f7ca9b244180d3cfb1987cbc9743/lts-13.30/8.6.5/pkgdb
fay-0.24.0.3
fay-base-0.21.1.1
fay-dom-0.5.0.1
fay-text-0.3.2.2
yesod-fay-0.10.0
However trying to set HASKELL_PACKAGE_SANDBOX to the local database as Fay Troubleshooting suggests doesn't work, because sandboxes containing the string .stack are ignored in yesod-fay.
If I remove that check from yesod-fay and force the --package-db to point to the local database, it still doesn't work, complains that fay-base can't find the fay package.
$ stack build
/home/user/code/myproject/src/Handler/Home.hs:121:13: error:
• Exception when trying to run compile-time code:
Unable to compile Fay module "HelloWorld":
ghc: <command line>: cannot satisfy -package fay-base-0.21.1.1:
fay-base-0.21.1.1-91eIy2f24Wa5OHg9LMre7 is unusable due to missing dependencies:
fay-0.24.0.3-CdLcUWVJEOpLCiYHkNVTai
(use -v for more information)
CallStack (from HasCallStack):
error, called at ./Yesod/Fay.hs:483:3 in yesod-fay-0.10.9999-CzTT9fyZ6636pi0gIof7Ge:Yesod.Fay
Code: fayFile' (ConE 'StaticR) "HelloWorld"
• In the untyped splice: $(fayFile' (ConE 'StaticR) "HelloWorld")
|
121 | $( fayFile' (ConE 'StaticR) "HelloWorld" )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Update: not using satck or cabal and using packages that are installed system-wide, this error doesn't occur. I guess the problem is in my local stack package database (the one in .stack-work)
I concluded that fay doesn't work with stack.

Can't import .lhs script in Haskell

I have two files, S5.hs and S6.lhs, in the same folder, and I want to import the S6.lhs script in S5.hs, but when i type import S6, i get:
Could not find module `S6'
Use -v to see a list of the files searched for.
|
1 | import S6
| ^^^^^^^^^^
Failed, no modules loaded.
When I lauch it from the folder, I get following message(the first line of the S6 file is import Data.Array):
File name does not match module name:
Saw: `Main'
Expected: `S6'
|
1 | import Data.List
| ^
Why is this happening?
Looks like you need to specify at the top of the S6.lhs file that you want this file to be treated as the S6 module, as opposed to the default module name of Main. You would do that with module S6 where or module S6 (export, list) where.

Haskell reexport linker errors

I want to have a function in a Foo.Internal module that is used by other things in there, but it should also be exposed by the Foo module. When I reexport the function from Foo to use elsewhere I get linker errors. I am using stack to build the code, so it might be an issue there, or with cabal, not sure.
Minimal working example:
module Foo.Internal where
secrets = "stuff"
module Foo(secrets) where
import Foo.Internal (secrets)
module Main where
import Foo
main = putStrLn secrets
When I compile this with stack build I get
package-0.1.0.0: build
Preprocessing library package-0.1.0.0...
[1 of 2] Compiling Foo.Internal ( src/Foo/Internal.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/Foo/Internal.o )
[2 of 2] Compiling Foo ( src/Foo.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/Foo.o )
In-place registering package-0.1.0.0...
Preprocessing executable 'package-exe' for package-0.1.0.0...
Linking .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/package-exe/package-exe ...
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/package-exe/package-exe-tmp/Main.o:(.text+0x26): undefined reference to `packazuEPdwTk5e5ZZOCOiVJMdOJ3P_FooziInternal_secrets_closure'
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/package-exe/package-exe-tmp/Main.o: In function `S2Re_srt':
(.data+0x40): undefined reference to `packazuEPdwTk5e5ZZOCOiVJMdOJ3P_FooziInternal_secrets_closure'
collect2: error: ld returned 1 exit status

Why isn't haddock generating documentation?

My Haskell file (pretty sure this is not the problem) is basically:
import System.IO
...
-- | Every Word is a String
type Word = String
...
-- | Some documentation for Haddock to see
main :: IO ()
main = do
...
My Setup.hs:
import Distribution.Simple
main = defaultMain
My grade.cabal:
name: grade
version: 0.1.0.0
...
build-type: Simple
cabal-version: >=1.8
executable grade
main-is: grade.hs
-- other-modules:
build-depends: base ==4.6.*, split ==0.2.*
hs-source-dirs: src
When I run cabal haddock --executables I get
...
Haddock coverage:
Warning: Not found in environment: Main.main
50% ( 1 / 2) in 'Main'
Warning: Main: could not find link destinations for:
Main.main
Documentation created: dist/doc/html/grade/grade/index.html
and the HTML contains main but no documentation for it. It does not even contain functions I defined other than main. Why is that?
You need to add a module declaration to generate documents for it.
module Main (main, Word) where

Haskell - Packaging cabal package with custom preprocessors

I've implemented a custom preprocessor which creates *.hs files form *.tpl files. It is specified in Setup.hs by using a Build-Type: Custom. Everything works fine, but I can't create tar.gz package from it (using cabal sdist).
Cabal complains, that it can not find the exposed modules which are generated by the preprocessor. The error message is
cabal: Error: Could not find module with any
suffix: ["gc","chs","hsc","x","y","ly","cpphs","hs","lhs"]
How can I make Cabal aware of the fact that the module is not missing, or maybe add tpl to the known file extensions, or something?
This is a known issue with cabal sdist. Use ./dist/setup/setup sdist instead.
Here's an example:
$ cat preprocessor-test.cabal
name: preprocessor-test
version: 0.1.0.0
build-type: Custom
cabal-version: >=1.10
extra-source-files: PreprocessorTest/*.prepro
library
exposed-modules: PreprocessorTest.PreprocessorTest
build-depends: base ==4.5.*
-- hs-source-dirs:
default-language: Haskell2010
$ cat Setup.hs
#!/usr/bin/env runhaskell
import Distribution.Simple
import Distribution.Simple.PreProcess
import Distribution.Simple.Utils
import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
import System.Cmd (rawSystem)
import System.FilePath ((</>))
main = let hooks = simpleUserHooks
dummy = ("prepro", dummyPreprocessor)
in defaultMainWithHooks hooks
{ hookedPreProcessors = dummy:knownSuffixHandlers }
dummyPreprocessor :: BuildInfo -> LocalBuildInfo -> PreProcessor
dummyPreprocessor build local = PreProcessor {
platformIndependent = True,
runPreProcessor =
mkSimplePreProcessor $ \inFile outFile verbosity -> do
notice verbosity (inFile ++ " is being preprocessed to " ++ outFile)
rawSystem "cp" [inFile, outFile]
return ()
}
$ cat PreprocessorTest/PreprocessorTest.prepro
module PreprocessorTest.PreprocessorTest
where
preprocessorTest :: Int
preprocessorTest = 1
$ cabal configure
Resolving dependencies...
[1 of 1] Compiling Main ( Setup.hs, dist/setup/Main.o )
Linking ./dist/setup/setup ...
Configuring preprocessor-test-0.1.0.0...
$ cabal build
Building preprocessor-test-0.1.0.0...
Preprocessing library preprocessor-test-0.1.0.0...
PreprocessorTest/PreprocessorTest.prepro is being preprocessed to
dist/build/PreprocessorTest/PreprocessorTest.hs
[1 of 1] Compiling PreprocessorTest.PreprocessorTest ( dist/build/PreprocessorTest/PreprocessorTest.hs, dist/build/PreprocessorTest/PreprocessorTest.o )
Registering preprocessor-test-0.1.0.0...
$ ./dist/setup/setup sdist
Distribution quality errors:
No 'synopsis' or 'description' field.
The 'license' field is missing or specified as AllRightsReserved.
Distribution quality warnings:
No 'category' field.
No 'maintainer' field.
Note: the public hackage server would reject this package.
Building source dist for preprocessor-test-0.1.0.0...
Preprocessing library preprocessor-test-0.1.0.0...
PreprocessorTest/PreprocessorTest.prepro is being preprocessed to
dist/src/sdist.-6767/preprocessor-test-0.1.0.0/dist/build/PreprocessorTest/PreprocessorTest.hs
Source tarball created: dist/preprocessor-test-0.1.0.0.tar.gz
$ tar tzf dist/preprocessor-test-0.1.0.0.tar.gz
preprocessor-test-0.1.0.0/
preprocessor-test-0.1.0.0/dist/
preprocessor-test-0.1.0.0/dist/build/
preprocessor-test-0.1.0.0/dist/build/PreprocessorTest/
preprocessor-test-0.1.0.0/dist/build/PreprocessorTest/PreprocessorTest.hs
preprocessor-test-0.1.0.0/Setup.hs
preprocessor-test-0.1.0.0/PreprocessorTest/
preprocessor-test-0.1.0.0/PreprocessorTest/PreprocessorTest.prepro
preprocessor-test-0.1.0.0/preprocessor-test.cabal

Resources