LoginSignup
15
8

More than 5 years have passed since last update.

Haskell(Stack)でGitHubにあるライブラリを使う方法

Posted at

Haskell(Stack)でGitHubにあるライブラリを使う方法

About

 こちらのプロジェクトmorishin氏のhsmecab(tanakh氏のhsmecabのstack対応用Fork版)を使用する必要がありましたが、
Hackageに登録されているhsmecabはtanakh氏のもので…Stackからは使えなかったので
その際にGitHubリポジトリにあるstack対応版をどのように使用したか…というもののまとめです。

  • わかること

    • HaskellのstackプロジェクトでGitHub上にあるstackライブラリプロジェクトを扱う方法
  • 多分わからないこと

    • stackを使用しない、cabal関連のHowTo

以下、「GitHubリポジトリ」は「stack用Haskellライブラリ」があるリポジトリを指します。


方法

 方法は簡単で

$ stack new {project-name} {template-name}

を実行するとプロジェクトルート直下にできるであろうファイルstack.yamlを弄り、{project-name}.cabalにbuild-dependsを追加するだけです。

  • 手順
    1. stack.yamlに使いたいGitHubリポジトリの情報を追加する
    2. {project-name}.caballのbuild-dependsに、手順1で追加したリポジトリのモジュール名を追加する

1. stack.yamlに使いたいGitHubリポジトリの情報を追加する

 今回の場合、追加したいのはhttps://github.com/morishin/hsmecabですので、packageslocationを追加します。

stack.yaml
# Local packages, usually specified by relative directory name
packages:
- '.'
- location:
    git: https://github.com/morishin/hsmecab.git
    commit: 2da6677fbd42bb77d3b6e61c02edfeebe248e184

2. {project-name}.caballのbuild-dependsにモジュール名を追加する

 https://github.com/morishin/hsmecab.gitによって提供されるモジュールの名前はmecabなので、
{project-name}.cabalのbuild-dependsに、mecabを追加します。

project-name.cabal
  build-depends:       base >= 4.7 && < 5
                     , (省略)
                     , mecab
                     , (省略)

 これで手順は完了です。

まとめ

 こちらのプロジェクトの、
2016-06-14時点の最終的なstack.yaml及び{project-name}.cabal(hs-gorira.cabal)を載せます。

stack.yaml
# This file was automatically generated by stack init
# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/

# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-5.14

# Local packages, usually specified by relative directory name
packages:
- '.'
- location:
    git: https://github.com/morishin/hsmecab.git
    commit: 2da6677fbd42bb77d3b6e61c02edfeebe248e184
# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
extra-deps: []

# Override default flag values for local packages and extra-deps
flags: {}

# Extra package databases containing global packages
extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true

# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: >= 1.0.0

# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64

# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]

# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
hs-gorira.cabal
name:                hs-gorira
version:             0.1.0.0
synopsis:            Simple project template from stack
description:         Please see README.md
homepage:            https://github.com/githubuser/hs-gorira#readme
license:             BSD3
license-file:        LICENSE
author:              aiya000
maintainer:          aiya000.develop at gmail.com
copyright:           2016 aiya000
category:            Web
build-type:          Simple
cabal-version:       >=1.10

executable hs-gorira
  hs-source-dirs:      src
  main-is:             Main.hs
  other-modules:       Config
                     , Control.GoriraMeCab
                     , Control.GoriraTwitter
                     , Data.GoriraMeCab
                     , Data.GoriraTwitter
  default-language:    Haskell2010
  build-depends:       base >= 4.7 && < 5
                     , HTTP
                     , aeson
                     , authenticate-oauth
                     , bytestring
                     , conduit
                     , conduit-extra
                     , connection
                     , http-client
                     , http-conduit
                     , lens-aeson
                     , mecab
                     , random-shuffle
                     , resourcet
                     , text
                     , transformers
15
8
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
8