Richard Cobbe | 2 Feb 22:32 2014

problem with happy and type identity

I'm working on a small project that involves an Alex scanner and a Happy
parser, and I'm getting an error from the type-checker that I do not
understand.  Can anyone help shed some light on what's going on?

I'm running Haskell Platform 2013.2.0.0, on MacOS 10.8.5 with XCode 4.6.3.

I've reduced the problem to a very small example, which I've attached as a
tar file.  It's a cabal package, and it contains a library with some test
cases.

If I run "cabal configure && cabal build" then the library builds with no
problems whatsoever.

But if I run

    cabal clean && cabal configure --enable-tests && cabal build

then I get the following error message:

    RunTests.hs:16:27:
        Couldn't match expected type `sample-0.4:Ast.Entry'
                    with actual type `Entry'
        In the return type of a call of `Entry'
        In the second argument of `(~?=)', namely `Entry "mumble"'
        In the expression: parse "entry" ~?= Entry "mumble"

And this doesn't make any sense to me, because the two types are supposed
to be the same.

If I take Happy and Alex out of the picture by replacing the Parser module
(Continue reading)

Erik Hesselink | 5 Feb 20:34 2014
Picon

Re: problem with happy and type identity

To be able to share code between your library and your tests, you should either

* Have a separate directory for the library sources and the test
sources. For example, put Ast.hs and Parser.y in 'src' and put
'Hs-source-dirs: src' in the library section. Put RunTests.hs in
'tests', and put 'Hs-source-dirs: tests' in the test-suite section.
This is the preferred way.
* Alternatively, don't specify 'sample' as a build-depends in the
test-suite. Note that this will mean that Ast and Parser will get
compiled twice.

Right now, cabal somehow mixes types from the files compiled as part
of the test suite with types imported from the library.

Regards,

Erik

On Sun, Feb 2, 2014 at 10:32 PM, Richard Cobbe <cobbe <at> ccs.neu.edu> wrote:
> I'm working on a small project that involves an Alex scanner and a Happy
> parser, and I'm getting an error from the type-checker that I do not
> understand.  Can anyone help shed some light on what's going on?
>
> I'm running Haskell Platform 2013.2.0.0, on MacOS 10.8.5 with XCode 4.6.3.
>
> I've reduced the problem to a very small example, which I've attached as a
> tar file.  It's a cabal package, and it contains a library with some test
> cases.
>
> If I run "cabal configure && cabal build" then the library builds with no
(Continue reading)

Richard Cobbe | 6 Feb 12:46 2014

Re: problem with happy and type identity

On Wed, Feb 05, 2014 at 08:34:40PM +0100, Erik Hesselink wrote:
> To be able to share code between your library and your tests, you should either
>
> * Have a separate directory for the library sources and the test
> sources. For example, put Ast.hs and Parser.y in 'src' and put
> 'Hs-source-dirs: src' in the library section. Put RunTests.hs in
> 'tests', and put 'Hs-source-dirs: tests' in the test-suite section.
> This is the preferred way.
> * Alternatively, don't specify 'sample' as a build-depends in the
> test-suite. Note that this will mean that Ast and Parser will get
> compiled twice.
>
> Right now, cabal somehow mixes types from the files compiled as part
> of the test suite with types imported from the library.

I see -- thanks!  I'll give that a shot as soon as I get a chance.

Richard

Gmane