How can I access python3.6+ from Haskell? - haskell

haskell-cpython works up to python3.4, but it is a too old version of python. The library also seems not to be maintained anymore.

It is possible to download a more recent version at this fork changing package.yaml
dependencies:
- cpython
and also stack.yaml
extra-deps:
- github: ekalosak/haskell-cpython
commit: 829da05dc5117b2f1d15fdcbd9796b1a65f53c3d

Related

how to use a my own Haskell library in a stack project?

I have a Haskell library I wrote that I compile with stack.
I now need to use it in another Haskell stack project.
In order to do that, I have added its current version to the extra_deps of my new project's stack.yaml and listed it among the build_depends of one its executables.
When I run stack build, however, it obviously tries to download the library from the internet. How do I specify that the library is local and where to find it?
Thanks in advance!
You can use github coordinates in the extra-deps section of your stack.yaml.
extra-deps:
- github: snoyberg/http-client
commit: a5f4f30f01366738f913968163d856366d7e0342
Then add the dependency in your package.yaml:
dependencies:
- http-client >= 0.1.0.0

Is there a way to point on servant-server 0.15 that is not yet on the last haskell LTS?

I would like to use the version 0.15 instead of the the one available on the last LTS (12.22), usually I'm adding this in stack.yaml :
extra-deps :
- git: git#github.com:haskell-servant/servant.git
commit: e3e5d2b23057c2c3409e5e210b613527baf3b77d
But they use multiple projects in the same repo so it does not work :-( :
The current entry points to
/Users/nhenin/dev/gsdFlow/.stack-work/downloaded/6krbU6UwORFF/ but no .cabal or package.yaml file could be found there.
Do you know how I could use it ?
All you need to do is specify sub directories in the repository containing the project:
extra-deps:
- git: git#github.com:haskell-servant/servant.git
commit: e3e5d2b23057c2c3409e5e210b613527baf3
subdirs:
- servant
if you needed servant-pipes from the repository as well, for instance, you'd also include it in the list:
...
subdirs:
- servant
- servant-pipes
You can use subdirs subfield to tell stack what project you want to add. See https://github.com/eta-lang/dhall-to-etlas/blob/master/stack.yaml f.e.

Trouble building yesod/amazonka dependencies in a Haskell Stack project

I'm trying to use the excellent AWS SDK amazonka in the backend portion of an API built using the equally excellent web framework yesod, but I am having great difficulty getting the dependencies for these two libraries to work together.
I started the scaffolded yesod project with
stack new my-project yesod-mongo
which populated my cabal file with the most recent version of yesod (1.6.0). Naively adding the dependencies amazonka-core and amazonka-ssm (for example) to my cabal file comes back with
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for my-project-0.0.0:
amazonka-core must match -any, but the stack configuration has no specified version
(latest matching version is 1.5.0)
amazonka-ssm must match -any, but the stack configuration has no specified version
(latest matching version is 1.5.0)
needed since my-project is a build target.
As suggested, I tried adding amazonka-core-1.5.0 and amazonka-ssm-1.5.0 to my stack.yaml file under extra-deps, but this doesn't work:
Warning: WARNING: /home/ubuntu/my-project/my-project.cabal was modified manually.
Ignoring package.yaml in favor of cabal file. If you want to use package.yaml
instead of the cabal file, then please delete the cabal file.
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for amazonka-core-1.5.0:
conduit-1.3.0.2 from stack configuration does not match >=1.1 && <1.3 (latest
matching version is 1.2.13.1)
needed due to my-project-0.0.0 -> amazonka-core-1.5.0
After a bit of digging, it seems that the snapshot that the yesod template was built off of is lts-11.6, but the most recent snapshot that the amazonka library is included in is lts-10.9. So, I tried building the project again from the yesod-mongo template, but this time specifying an older snapshot:
ubuntu:~$ stack new my-project yesod-mongo --resolver lts-10.9
Downloading template "yesod-mongo" to create project "my-project" in my-project/ ...
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- my-project/
Selected resolver: lts-10.9
Resolver 'lts-10.9' does not have all the packages to match your requirements.
classy-prelude version 1.3.1 found
- my-project requires ==1.4.*
classy-prelude-conduit version 1.3.1 found
- my-project requires ==1.4.*
classy-prelude-yesod version 1.3.1 found
- my-project requires ==1.4.*
http-conduit version 2.2.4 found
- my-project requires ==2.3.*
persistent version 2.7.1 found
- my-project requires ==2.8.*
persistent-mongoDB version 2.6.0 found
- my-project requires ==2.8.*
yesod version 1.4.5 found
- my-project requires ==1.6.*
yesod-auth version 1.4.21 found
- my-project requires ==1.6.*
yesod-core version 1.4.37.3 found
- my-project requires ==1.6.*
yesod-form version 1.4.16 found
- my-project requires ==1.6.*
yesod-static version 1.5.3.1 found
- my-project requires ==1.6.*
Using package flags:
- my-project: dev = False, library-only = False
Now I am at a loss and more than a little frustrated. It seems like perhaps the template is ignoring the snapshot specification. So, my question:
Is there a way to build the scaffolded site from a template that uses a specific snapshot to fill in the cabal and stack.yaml files? Is there anything else I can do to get this to work?
Happy to provide more information if it's helpful.
Edit: I also tried bumping down the versions of the packages in the above snippet, and while this solves the issue of building dependencies, now the scaffolded site doesn't compile (presumably because things have changed in a meaningful way from yesod-1.4.5 to yesod-1.6.0).
Unfortunately you can't use Commercial Haskell's stack templates with yesod and amazonka as of now. The reasons being:
There was a recent conduit rewrite in version 1.3
Some breaking changes were introduced in recent Yesod 1.6 which depends on conduit >= 1.3
Amazonka doesn't work with recent version of conduit
The only way for you to get it working is switching back to old version of stack templates (those templates which actually worked with stackage resolver 10.9) and then using that to create a new project. Fortunately, Stack supports custom stack templates:
$ stack new my-project https://raw.githubusercontent.com/github-user-id/stack-templates/master/my-template.hsfiles

stack.yaml not pulling in dependency from github

Here's the stack.yaml stanza
packages:
- location:
git: https://github.com/TwitterFriends/lsh.git
commit: 57d57f4209e56f526c0eca023907015935c26071
extra-dep: true
I add the package to cabal file
get error when I try to build
While constructing the BuildPlan the following exceptions were encountered:
-- While attempting to add dependency,
Could not find package lsh in known packages
What am I doing wrong?
Current project found here
https://github.com/TwitterFriends/twitter-friend-server
The problem is syntax. You added some extra spaces before extra-dep. Place this in stack.yaml. With this, your project builds on my machine.
- location:
git: https://github.com/TwitterFriends/lsh.git
commit: 57d57f4209e56f526c0eca023907015935c26071
extra-dep: true
UPDATE: (17 Dec 2017)
Since stack-1.6.1 syntax of adding github dependency is changed. You need to add your github dependency into extra-deps field. Something like this:
resolver: lts-9.17
packages: [.]
extra-deps:
- fmt-0.5.0.0
- git: https://github.com/TwitterFriends/lsh.git
commit: 57d57f4209e56f526c0eca023907015935c26071
UPDATE: (5 Dec 2019)
In stack-2.1.3 you can specify GitHub dependencies in extra-deps with even shorter syntax:
extra-deps:
- github: TwitterFriends/lsh
commit: 57d57f4209e56f526c0eca023907015935c26071
It looks like the problem you're facing is due to a syntax error in the lines in your stack.yaml file directly preceding those you posted in the question.
When I visited your repo and checked out the whole stack.yaml file, I saw this:
resolver: lts-8.13
# User packages to be built.
# Various formats can be used as shown in the example below.
#
packages:
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
- location:
git: https://github.com/TwitterFriends/lsh.git
commit: 57d57f4209e56f526c0eca023907015935c26071
extra-dep: true
This packages: line doesn't look right, especially given that later in the file you have:
packages:
- '.'
So my best guess would be that the stack.yaml file isn't getting parsed correctly, so it can't find the library b/c it doesn't know it should grab it from that location.

How to install a package using stack?

Using cabal, I could install hakyll with the command:
cabal install hakyll
How can I do the same thing using stack?
stack install hakyll
stack offers a curated set of packages that won't blow your machine up. If you want to check what packages are available, or exactly what version is supported, or on what version of GHC you can get it, check out https://www.stackage.org/.
For example, you can get hakyll 4.6.9.0 right now for both GHC 7.8.4 and GHC 7.10.1. Pretty neat. - source
EDIT: I forgot to mention, Yuan Wang's method works for getting the version of hakyll that is not curated into stackage. It's up to you what version you need.
add hakyll in stack.yaml generated by stack init or stack new
yaml file should look like:
flags: {}
packages:
- '.'
extra-deps:
- hakyll-4.7.1.0
resolver: lts-2.15
after that, run stack solver installs it
https://github.com/commercialhaskell/stack/wiki/stack.yaml
This documentation worked for me
On package.yaml add the library under dependencies, for example:
dependencies:
- base >= 4.7 && < 5
- hakyll # added here

Resources