繁体   English   中英

什么是构建Haskell项目的最新标准工作流程?

[英]What is the up-to-date standard workflow for building Haskell projects?

由于事情变化如此之快,我发布了这个问题,所以希望能够澄清社区同意的启动Haskell项目的方法。 想象一下,我有两个独立的项目:

  • 项目#1 :Square,正方形数字的库。 没有deps。

     -- Square.hs module Square where square :: Num a => a -> a square x = x * x 
  • 项目#2 :斜边,库和可执行文件,找到直角三角形的最长边。 取决于#1:

     -- Hypotenuse.hs module Hypotenuse where import Square hypotenuse :: Floating a => a -> a -> a hypotenuse xy = sqrt $ square x + square y 

     -- Main.hs import System.Environment import Hypotenuse main = do [x,y] <- fmap (map read) getArgs print $ hypotenuse xy 

从安装了GHC 7.10.2,Stack和Cabal的计算机开始,以及包含~/OrganizeMe/Square.hs~/OrganizeMe/Hypotenuse.hs~/OrganizeMe/Main.hs的单个目录~/OrganizeMe ,如上所述 - 经验丰富的Haskeller将用于构建这些项目的一整套unix命令是什么? 那包括:

  1. 组织这些项目的目录树;

  2. 配置Stack / Cabal / etc (和git ,可选);

  3. 在本地建造/安装;

  4. 发布到Hackage / Stackage

这不是一个完整的答案,它不是从您的OrganizeMe目录开始(代码中有一些错误),它不包括发布到Hackage / Stackage。 我从一个目录stackenv开始,包含两个包,但你当然可以这样做完全不同。

mkdir stackenv && cd stackenv/
mkdir square && cd square
vim Square.hs # The file you describe without the x in the type of square
cabal init # Go through the questions and choose "library"
stack init
cd ../ && mkdir hypotenuse && cd hypotenuse/
vim Hypotenuse.hs # The file you describe
vim Main.hs # The file you describe but importing Hypotenuse
cabal init # Go through the questions... "executable" this time
stack init
vim hypotenuse.cabal # add "square" or chosen package name to build-depends
vim stack.yaml # add "- '../square/'" below packages
stack install
hypotenuse 3 4 # works because ~/.local/bin is in my PATH

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM