Alex wrappers.hs no instance of Applicative - haskell

I am trying to compile a lex.x with ghc 7.10.2 and alex 3.1.4, but it is giving the below error.
I checked Lex.hs and indeed there is no applicative instance for 'Alex' there.
Note: This error started coming after I moved from wrapper 'monad' to 'monad-bytestring'
templates/wrappers.hs:287:10:
No instance for (Applicative Alex)
arising from the superclasses of an instance declaration
In the instance declaration for ‘Monad Alex’
I saw that in alex 3.1.4 this was fixed http://hackage.haskell.org/package/alex
Changes in 3.1.4:
Add Applicative/Functor instances for GHC 7.10
Below commit introduced the applicative instance, but it is not present in my generated Lex.hs. Can I manually use the below wrapper to be used for generating Lex.hs?
https://github.com/simonmar/alex/commit/b1472bfbb7b95bcd6c66558197e2603997d9ce0b

This is a workaround for this problem. Basically this involves building the alex from latest source code and modifying the local wrapper. Though this worked for me, but it can have some unknown issues also.
mkdir tmp; cd tmp;
git clone https://github.com/simonmar/alex.git
cd alex;
git checkout 3b7e8e4;
cabal build;
Then copy the 'AlexWrapper-monad-bytestring' generated in this directory to the one in your local alex installation.
For example
cp AlexWrapper-monad-bytestring ~/.stack/snapshots/x86_64-linux/lts-3.14/7.10.2/share/x86_64-linux-ghc-7.10.2/alex-3.1.4/AlexWrapper-monad-bytestring
The reason behind building from '3b7e8e4' is that the commit '447bbb8' breaks the compilation of wrapper due to introduction of an extra feature.

Related

Building the Spock tutorial example fails

I wanted to get going with Haskell a little bit and therefore took a look at the Spock framework. To start clean, I uninstalled everything Haskell related from my Arch Linux machine and installed ghcup, Cabal and Stack using the install scripts from their respective websites.
Now I want to follow Spock's Tutorial. Trying to install Spock globally with cabal install Spock as suggested gives me an error (abbreviated):
src/Web/Spock/Internal/Wire.hs:43:1: error:
Could not find module ‘Web.Routing.AbstractRouter’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
43 | import Web.Routing.AbstractRouter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cabal: Failed to build Spock-0.9.0.1. See the build log above for details.
I already found a question on reddit on the topic, but the solution does not apply because I'm not trying to use a specific version of the libraries as implied.
So I try to follow along and build only locally.
But when I reach the point where it says stack build --fast --pedantic, the build plan can not be constructed and Stack suggests to add another dependency, stm-containers. Doing so, I am presented with two additional suggestions for focus and primitive. When I add these, the plan fails again, this time without a simple solution:
In the dependencies for primitive-0.6.4.0:
base-4.13.0.0 from stack configuration does not match >=4.5 && <4.13 (latest matching version is 4.12.0.0)
needed due to Spock-example-0.1.0.0 -> primitive-0.6.4.0
I can do a little thing with Haskell, but with the build system(s), I am way out of my comfort zone. Help and hints appreciated. Oh, and all versions of course are the latest by the time of this post.
Due to incompatible versions of dependencies, Spock won't build with GHC 8.8 and above. A similar problem is described in Spock issue #149, though I'm not fully sure it is exactly the same incompatibility. The error you got from Stack hints at that, as base-4.13.0.0 is the version of base that is bundled with GHC 8.8. cabal-install failed in a more obscure way because, upon noting the incompatibility, it tries to solve the dependencies using older versions of Spock, eventually picking 0.9.0.1, attempting and, thanks to a missing version upper bound for the reroute dependency, failing to build it.
(Shortly after this answer was posted, the missing upper bound was retrofitted to the old Spock version, so attempting to reproduce the problem now will lead to an easier to understand failure.)
Casting the tutorial aside, the most straightforward way to use Spock given those complications is probably through cabal-install 3+. Begin by using ghcup to switch to GHC 8.6.5:
$ ghcup install 8.6.5
$ ghcup set 8.6.5
Then, create a blank project with cabal-install:
$ mkdir myproject
$ cd myproject
$ cabal init
Add Spock to the build-depends section of myproject.cabal:
build-depends: base >=4.12 && <4.13
, Spock == 0.13.*
Finally, you can run:
$ cabal build
Which will install Spock and its dependencies before building the project. (Note that you generally don't need to use cabal install to install libraries with cabal-install 3.)
It is presumably possible to make it work with Stack as well, by changing to the lts-14.27 resolver (the latest one that uses GHC 8.6.5), tracking down all dependency versions that need to be overriden (as you had began to do) and manually adding them to the extra-deps of stack.yaml.

Why is GHC not importing Semigroup ((<>))

I've been given code by my lecturer that doesn't build in GHCI. As far as I know, it has been building correctly for my classmates.
The code I'm refering to is
import Data.Semigroup (Semigroup ((<>)))
GHCI is throwing this error at me
Module ‘Data.Semigroup’ does not export ‘Semigroup((<>))’
Should this work? Is there perhaps something wrong with my version of GHC? All other import statements are working.
Final Edit
Is there perhaps something wrong with my version of GHC?
Absolutely yes, there is something wrong, is too old, to be precise:
GHC-6.12 / base-4.2 (from 2010, which is the time of the Semigroup package) -- thanks so much #leftaroundabout and #Thomas M. DuBuisson for the contribution!
And that package has not the (Semigroup ((<>))) function. Hence the error you see.
Edit 2
After comments, I tried to reproduce the OP environment to reproduce the error too, I installed in stack the ghc version 7.10.3, this is how looks the stack.yaml file:
resolver: lts-6.27
system-ghc: false
packages:
- .
And after ruining a base stack project with a Main.hs file containing:
module Main where
import Data.Semigroup
main :: IO ()
main = do
putStrLn "Hello"
putStrLn "World"
the error I got is
/home/damian/test-semigroup/app/Main.hs:3:8:
Could not find module ‘Data.Semigroup’
Use -v to see a list of the files searched for.
-- While building package test-semigroup-0.1.0.0 using:
/home/damian/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_1.22.5.0_ghc-7.10.3 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.5.0 build lib:test-semigroup exe:test-semigroup-exe --ghc-options ""
Process exited with code: ExitFailure 1
The same happend with older versions:
LTS 3.22 for ghc-7.10.2,
I couldt try with:
LTS 2.22 for ghc-7.8.4, published 4 years ago
Because they where to old to run with cabal
and
- LTS 0.7 for ghc-7.8.3, published 5 years ago
Because they I cannot install it in a 64bit OS...
So, to be absolutely sure I tried with all the newer LTS versions one by one, yes... one by one, It took some time but worth the shot:
LTS 13.29 for ghc-8.6.5, published today
LTS 13.19 for ghc-8.6.4, published 3 months ago
LTS 13.11 for ghc-8.6.3, published 4 months ago
LTS 12.26 for ghc-8.4.4, published 7 months ago
LTS 12.14 for ghc-8.4.3, published 9 months ago
LTS 11.22 for ghc-8.2.2, published 11 months ago
LTS 9.21 for ghc-8.0.2, published a year ago
LTS 7.24 for ghc-8.0.1, published 2 years ago
None of those ghc version could reproduce your log error, so I thought to try a typo maybe:
import Data.Semigroup (Semigroup ((<$>)))
or
import Data.Semigroup (Semigroup ((=>>)))
And those gave me your error:
/home/damian/test-semigroup/app/Main.hs:3:24: error:
Module ‘Data.Semigroup’ does not export ‘Semigroup(())’
That means, that the Data.Semigroup module exists in your ghc
Semigroup((<>)) is not part of that module
Meaning, you must have one of the oldest ghc versions...
So, I just can think that you can try:
Reinstall your ghc, and try it to run it again.
Please, consider using some tool such as stack
Check your code, look out for some typos or something odd
I stand that my first answer was close though:
Edit 1
It has been added in ghc version 8.0.1
A quick search in hoogle always helps:
Here first link is semigroup <>, (<>) :: Semigroup a => a -> a -> a
and it says:
This versions is able since May 2016, and it ghc version is 8.0.1.
To see all versions of ghc with its base versions:
https://wiki.haskell.org/Base_package
ThomasM.DuBuisson found what must have been the problem (discussion in comments): there are three different packages defining a Data.Semigroup module –
base. As of GHC-8, Haskell ships with the semigroup class and -module out of the box, so you don't need to take care for anything. See Damian Lattenero's answer for details.
semigroups. In GHC-7, there was no semigroups class in base but the semigroups package was semi-official part of the base libraries. In fact, this exact module was just copied over to base. The way to write really backwards-compatible code with semigroups is still to depend on the semigroups package: when compiling against new GHC versions, that package just uses the base module, only in old versions does it provide the module itself. See the .cabal configuration
if impl(ghc < 7.11.20151002)
-- starting with GHC 8 these modules are provided by `base`
hs-source-dirs: src-ghc7
exposed-modules:
Data.Semigroup
Data.List.NonEmpty
Semigroup is an obsolete package back from 2010. It too exports a Data.Semigroup module, but unlike the semigroups one this is not compatible with the official base module. It does have a Semigroups class, but its method is called .++. rather than <> (probably, to not clash with the operator from Data.Monoid – that is by now not an issue, because in very new versions <> is now in the prelude and already works on semigroups).
So, what happened for you is probably the following:
You tried to compile your code
GHC complained Could not find module ‘Data.Semigroup’. That's because you're running an old compiler.
At this point, what you should have done would be installing/depending on the semigroups package. Instead you installed the Semigroup package, which is unfortunately incompatible.
There are two solutions:
Use Cabal-install and allow for your old compiler. IMO this is ok, though you should be prepared to run into other dependency troubles in the future. If you do this, you need to add the semigroups package in the build-depends of your .cabal file.
Or use Stack to enforce a recent compiler. Select e.g. lts-12.14.

stack fails to build monad-mersenne-random-0.1 package

I'm trying to install moo stackage and it has the monad-mersenne-random dependency which is giving me the following error. The stack project is fresh created. I tried to add the dependency to the configuration files but it didn't help, and I got the same error.
# stack build monad-mersenne-random-0.1
gives me:
>>/tmp/stack8403/monad-mersenne-random-0.1/Control/Monad/Mersenne/Random.hs:50:10: error:
>> • No instance for (Applicative Rand)
>> arising from the superclasses of an instance declaration
>> • In the instance declaration for ‘Monad Rand’
>> |
>> 50 | instance Monad Rand where
>> | ^^^^^^^^^^
This library is somewhat too old. GHC version from 7.10 or above can't compile it
If you need to use Random library, you can find another alternative such as MonadRandom
IMO, GHC 8.4 is too new for production, many libraries haven't supported it yet. You should use GHC 8.2.2 or below

Craft3e: cabal install not in scope: Applicative

I am attempting to install the code for "Haskell: The Craft of Functional Programming", 3rd edition.
I'm using GHCi, version 7.6.3 on Centos version 7.
Then:
cabal unpack Craft3e
cd Craft3e-0.1.1.0/
cabal install
...
[29 of 67] Compiling CalcParseLib ( Calculator/CalcParseLib.hs, dist/build/CalcParseLib.o )
Calculator/CalcParseLib.hs:132:10:
Not in scope: type constructor or class `Applicative'
Failed to install Craft3e-0.1.1.0
cabal: Error: some packages failed to install:
Craft3e-0.1.1.0 failed during the building phase. The exception was:
ExitFailure 1
I have attempted this installation multiple times, but cannot
overcome this error.
Could I use something other than "cabal install"?
I have plenty to learn about Haskell before I get to this example,
but it would be great to know the installation is fine! :)
You have three options:
Install an older version of the Craft3e package, with e.g. cabal unpack Craft3e-0.1.0.10.
Find Calculator/CalcParseLib.hs in the source files you have downloaded with cabal unpack and add a...
import Control.Applicative
... line next to the other import lines at the beginning. I suspect you will have to do the same with other modules, if the same error shows up elsewhere after you do this change, and there might be other issues of a similar nature.
Install a newer version of GHC (7.6.3 is from 2013). Though the default CentOS repositories won't offer that, there are other options, such as an unofficial Fedora repository and a manual installation. See this page for instructions.
#3 is the definitive solution. If you just want to get started with the book right now, though, you can go for #1 and leave the reinstall for later.
For the sake of reference, here is a brief explanation of the problem (I will use some unfamiliar terms, but you will soon enough learn about them as you study Haskell). There is an important type class called Applicative which, for historical reasons, wasn't as well integrated with the rest of the core libraries as it should be. This situation was corrected in GHC 7.10, which both included Applicative in the Prelude (the module which is imported by default in Haskell programs) and made it necessary to add Applicative instances in a number of places where they were missing. The code in the Craft3e package was updated so that these Applicative instances were in place (cf. this entry in the book's blog), but the import Control.Applicative line, which would be necessary to make the updated code work in older GHCs that do not have Applicative in the Prelude, wasn't added, leading to the error that you are seeing.

How to install generic haskell

after install hugs and then install ghc6 then install generic-haskell has the following message, How to do?
# make package
Creating generic-haskell package ...
ghc-pkg: cannot find package generic-haskell
Reading package info from "generic-haskell.cabal.pkg" ... done.
generic-haskell-1.80: missing id field
generic-haskell-1.80: dependency "base-4.2.0.0" doesn't exist (use --force to override)
generic-haskell-1.80: dependency "haskell98-1.0.1.1" doesn't exist (use --force to override)
generic-haskell-1.80: dependency "containers-0.3.0.0" doesn't exist (use --force to override)
make: *** [package] Error 1
in ubuntu i compile ghc-6.2.2 got the following error
/usr/bin/ghc -M -optdep-f -optdep.depend -osuf o -H16m -O HaskTags.hs
on the commandline:
Warning: -optdep-f is deprecated: Use -dep-makefile instead
------------------------------------------------------------------------
==fptools== make boot - --no-print-directory -r;
in /home/martin/ghc-6.2.2/ghc/utils/ghc-pkg
------------------------------------------------------------------------
/usr/bin/ghc -M -optdep-f -optdep.depend -osuf o -H16m -O -cpp -DPKG_TOOL -DWANT_PRETTY Main.hs Package.hs ParsePkgConfLite.hs Version.hs
on the commandline:
Warning: -optdep-f is deprecated: Use -dep-makefile instead
make all
/usr/bin/ghc -H16m -O -cpp -DPKG_TOOL -DWANT_PRETTY -c Main.hs -o Main.o -ohi Main.hi
Main.hs:496:11:
Ambiguous type variable `e' in the constraint:
`Exception.Exception e'
arising from a use of `Exception.throw' at Main.hs:496:11-25
Possible cause: the monomorphism restriction applied to the following:
my_catch :: forall a. IO a -> (e -> IO a) -> IO a
(bound at Main.hs:499:0)
my_throw :: forall a. e -> a (bound at Main.hs:496:0)
Probable fix: give these definition(s) an explicit type signature
or use -XNoMonomorphismRestriction
Main.hs:498:13:
Ambiguous type variable `e1' in the constraint:
`Exception.Exception e1'
arising from a use of `Exception.catch' at Main.hs:498:13-27
Possible cause: the monomorphism restriction applied to the following:
eval_catch :: forall a. a -> (e1 -> IO a) -> IO a
(bound at Main.hs:498:0)
Probable fix: give these definition(s) an explicit type signature
or use -XNoMonomorphismRestriction
make[4]: *** [Main.o] Error 1
make[3]: *** [boot] Error 2
make[2]: *** [boot] Error 1
make[1]: *** [boot] Error 1
Any one have installed old version of GHC and generic haskell in ubuntu 10?
There are many pairs of version , i tried ghc-6.2.2 got above error, will i need to uninstall ubuntu 10 to install older version ubuntu to get it work? which version of ubuntu for which version of ghc work?
http://www.cs.uu.nl/research/projects/generic-haskell/compiler.html
I tried installing generic-haskell myself from the source, I managed, and am able to describe how I fixed it. My installation platform is the Haskell Platform 2011.2.0.1-x86_64, but the following instruction are somewhat more general.
I met three problems, including the first one you describe (no. 3 below). For other users, I also describe the first two ones, which you probably solved as well.
1) Other users have first to fix an error depending on Data.Map.lookup type having changed, for containers >= 0.2.0.0: it used to return Monad m => m b (in containers-1.0.0.0), now it returns just Maybe b.
I added calls to Data.Maybe.maybeToList to fix a few call-sites needing to use a list type; I bet you fixed the same error in some way. You can find this fix at:
http://hpaste.org/47624.
2) Another error I had, with GHC 7, is that the configure script does not realize that it is newer than GHC 6.8, so it needs to also depend on containers. configure output included this line:
checking whether base package is split (GHC 6.8 or newer)... no
To fix this, you need to replace
if test $ghc_ma -ge 6 -a $ghc_mi -ge 8; then
with
if test $ghc_ma -eq 6 -a $ghc_mi -ge 8 -o $ghc_ma -ge 7; then
3) To fix your problem, you need to edit build/generic-haskell.cabal.pkg (assuming you are not doing an in-place installation with make in-place). You need to add an id: line and fix the depends line to use package-ids of packages present on your systems instead of package names. You can find out the ids using the following commands (output on my system included):
$ ghc-pkg field base id
id: base-4.3.1.0-f5c465200a37a65ca26c5c6c600f6c76
$ ghc-pkg field haskell98 id
id: haskell98-1.1.0.1-150131ea75216886448a7146c9e0526b
$ ghc-pkg field containers id
id: containers-0.4.0.0-b4885363abca642443ccd842502a3b7e
The change to build/generic-haskell.cabal.pkg would then be:
-depends: base-4.3.1.0
- haskell98-1.1.0.1
- containers-0.4.0.0
+depends: base-4.3.1.0-f5c465200a37a65ca26c5c6c600f6c76
+ haskell98-1.1.0.1-150131ea75216886448a7146c9e0526b
+ containers-0.4.0.0-b4885363abca642443ccd842502a3b7e
Furthermore, you need to add an id line to the same file - any id will do, as long as you change it if/when you reinstall the library. Here I've used:
id: generic-haskell-1.80-lib-md5sum-2a7ae9d60440627618ad0b0139ef090b
I've also aligned all fields with spaces, as in the existing files. The syntax reference for this file can be found in:
http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/packages.html#installed-pkg-info
Apparently, the generic-haskell package depends on an old version of base.
The Haskell Platform specifies base-4.3.1.0, while generic-haskell needs an older version. Please contact the maintainers, or possibly, install an older version of GHC.

Resources