Haskell Cabal: Mysterious Missing or Recursive Dependencies

Haskell Cabal: Mysterious missing or recursive dependencies

OK, solved it myself:

There is a bug and template-haskell-2.5.0.0 was installed in the system directory of cabal, as well as in my user directory.

When I forcedly unregistered template-haskell in my user directory, everything was fine.

Persistent modules not found

  1. Check that you're not using sandboxes, cabal-dev, hsenv, anything else that can influence ghc in looking for dependencies. Make sure you're using ghc/ghci, and not any wrappers, and that ghc/ghci are not aliased to anything in your shell.

  2. Try to specify the package-db explicitly:

    ghci -package-db /home/apsk/.ghc/x86_64-linux-7.6.3/package.conf.d
  3. If you launch ghci with -v, it'll print the (caches of) databases it looks at, like this:

    % ghci -v 
    GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
    Glasgow Haskell Compiler, Version 7.6.3, stage 2 booted by GHC version 7.4.2
    Using binary package database: /opt/ghc763/lib/ghc-7.6.3/package.conf.d/package.cache
    Using binary package database: /home/feuerbach/.ghc/i386-linux-7.6.3/package.conf.d/package.cache

    Make sure that the database which has persistent is listed there.

How do I run the tests that are part of an installed/installing Cabal package?

The --run-tests flag does not appear to be working in the current version of cabal. The --enable-tests flag no longer runs tests as a new feature of cabal. Until the issue is resolved you can manually verify that a package passes it's test suite by doing the following:

  1. Use cabal to download the package source
  2. Use cabal to build the package in a sandbox
  3. Use cabal to run the tests in the sandbox

Use this series of cabal commands to run the test for the-package:

cabal get the-package
cd the-package*
cabal sandbox init
cabal install --dependencies-only
cabal configure --enable-tests
cabal build
cabal test
cd ../
rm -r the-package*

Or use this equivalent one-liner:

cabal get the-package && cd the-package* && cabal sandbox init && cabal install --dependencies-only && cabal configure --enable-tests && cabal build && cabal test && cd ../ && rm -r the-package*

Type synonyms not in scope when using Template Haskell

This is caused by declaration groups when using Template Haskell. Here is an excerpt from the GHC Manual:

Top-level declaration splices break up a source file into delcaration
groups. A declaration group is the group of declarations created by a
top-level declaration splice, plus those following it, down to but not
including the next top-level declaration splice. The first declaration
group in a module includes all top-level definitions down to but not
including the first top-level declaration splice.

Each declaration group is mutually recursive only within the group.
Declaration groups can refer to definitions within previous groups,
but not later ones.

In my original code, two declaration groups are created:

-- This is the start of the first declaration group.

type Foo = Bar

data Baz = Baz
$(deriveJSON defaultOptions ''Baz)

-- This is the start of the second declaration group.

data Bar = Bar

The first declaration group cannot see Bar, which is causing this error.

typeclass for repetitive actions until fixed point

What you are asking for, is actually a plain fix:

cd :: (Monad m) => Int -> Int -> m Int
cd = fix (\f c i -> if i == 0 then return c else f (c+i) (i-1))

This will repeat the computation, until i becomes 0. (I added c to have a meaningful computation; but you could assume s=(Int,Int) with one of them being a rolling sum and the other the counter)

> cd 0 4 :: [Int]
[10]

This is the same as:

relax = fix (\f s -> if isFix s then return s else f (step s))

I believe, this is the definition of iterateUntilM.

How to produce a .js file from a haskell source file with haste?

Is it possible that you have an old version of Haste lying around, or have intermediate files (.jsmod, for instance) from a different version of the compiler in your source directory? This sounds like the (quite unhelpful) error message Haste produces when it runs into a corrupted intermediate file.

Check that the version of the binary you're calling is what you expect (hastec --version). Then, try getting rid of all intermediate files in the directory as well as any files in %USERPROFILE%\AppData\Roaming\haste, reinstalling split, and recompiling with the -fforce-recomp flag. You should also add a main function, so that Haste has an entry point to your program from which to start linking. If all you want to do is to make some Haskell function available to external JavaScript, you can use the export foreign function interface:

{-# LANGUAGE OverloadedStrings #-}
module Main where
import Haste.Foreign
import Hexagon

main = export "picture" Hexagon.picture

You will probably also want to compile your program with the --onexec flag, to make sure that main runs and exports picture immediately when loaded, and not on page load which is the default:

> hastec -o hexagon.js --pretty-print --onexec hexagon.hs

After doing this, any code included after hexagon.js will be able to call e.g. Haste.picture(5); in order to produce a picture of size 5.

(Re: MSI installer requiring a reboot, this is required since it adds the Haste binaries to your %PATH%, which does not take effect immediately. I assume that a re-login would be enough to make it take effect, however.)



Related Topics



Leave a reply



Submit