构建 Haskell 项目的最新标准工作流程是什么?
What is the up-to-date standard workflow for building Haskell projects?
由于事情变化如此之快,我发布了这个问题,希望社区同意的启动 Haskell 项目的方式能够得到澄清。假设我有两个独立的项目:
项目 #1:Square,计算数字平方的库。没有部门。
-- Square.hs
module Square where
square :: Num a => a -> a
square x = x * x
项目 #2:Hypotenuse,查找直角三角形最长边的库和可执行文件。取决于#1:
-- Hypotenuse.hs
module Hypotenuse where
import Square
hypotenuse :: Floating a => a -> a -> a
hypotenuse x y = sqrt $ square x + square y
,
-- Main.hs
import System.Environment
import Hypotenuse
main = do
[x,y] <- fmap (map read) getArgs
print $ hypotenuse x y
从一台安装了 GHC 7.10.2、Stack 和 Cabal 以及一个目录 ~/OrganizeMe
的计算机开始,其中包含 ~/OrganizeMe/Square.hs
、~/OrganizeMe/Hypotenuse.hs
和 ~/OrganizeMe/Main.hs
,如上所示 - 有经验的 Haskeller 会使用哪些完整的 unix 命令来构建这些项目? 包括:
整理那些项目的目录树;
配置 Stack
/Cabal
/etc
(和 git
,可选);
building/installing 他们在本地;
发布到 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
希望对您有所帮助。
由于事情变化如此之快,我发布了这个问题,希望社区同意的启动 Haskell 项目的方式能够得到澄清。假设我有两个独立的项目:
项目 #1:Square,计算数字平方的库。没有部门。
-- Square.hs module Square where square :: Num a => a -> a square x = x * x
项目 #2:Hypotenuse,查找直角三角形最长边的库和可执行文件。取决于#1:
-- Hypotenuse.hs module Hypotenuse where import Square hypotenuse :: Floating a => a -> a -> a hypotenuse x y = sqrt $ square x + square y
,
-- Main.hs import System.Environment import Hypotenuse main = do [x,y] <- fmap (map read) getArgs print $ hypotenuse x y
从一台安装了 GHC 7.10.2、Stack 和 Cabal 以及一个目录 ~/OrganizeMe
的计算机开始,其中包含 ~/OrganizeMe/Square.hs
、~/OrganizeMe/Hypotenuse.hs
和 ~/OrganizeMe/Main.hs
,如上所示 - 有经验的 Haskeller 会使用哪些完整的 unix 命令来构建这些项目? 包括:
整理那些项目的目录树;
配置
Stack
/Cabal
/etc
(和git
,可选);building/installing 他们在本地;
发布到
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
希望对您有所帮助。