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 with a hand-written parser, the error goes away. This is hardly feasible in the actual project, of course :-) so I'm hoping someone can shed some light on what I'm doing wrong here. Thanks! Richard (I apologize for the attachment, by the way, but since filesystem layout is potentially important here, and since it's only slightly larger than 1K, I figured it was the best way. If there's a better way to do this in the future (which doesn't assume I can throw it on the web somewhere), then I'd love to hear about it.)

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
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 with a hand-written parser, the error goes away. This is hardly feasible in the actual project, of course :-) so I'm hoping someone can shed some light on what I'm doing wrong here.
Thanks!
Richard
(I apologize for the attachment, by the way, but since filesystem layout is potentially important here, and since it's only slightly larger than 1K, I figured it was the best way. If there's a better way to do this in the future (which doesn't assume I can throw it on the web somewhere), then I'd love to hear about it.)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

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
participants (2)
-
Erik Hesselink
-
Richard Cobbe