简体   繁体   中英

How can I manage multiple configurations of a single Haskell program?

What is an alternative to autotools in Haskell world? I want to be able to choose between different configurations of the same source code.

For example, there are at least two implementations of MD5 in Haskell: Data.Digest.OpenSSL.MD5 and Data.Digest.Pure.MD5 . I'd like to write code in such a way that it can figure out which library is already installed, and didn't require to install the other.

In CI can use Autotools/Scons/CMake + cpp . In Python I can catch ImportError . Which tools should I use in Haskell?

In Haskell you use Cabal configurations. At your project top-level directory, you put a file with the extension .cabal , eg, <yourprojectname>.cabal . The contents are roughly:

Name:                myfancypackage
Version:             0.0
Description:         myfancypackage
License:             BSD3
License-file:        LICENSE
Author:              John Doe
Maintainer:          john@example.com
Build-Type:          Simple
Cabal-Version:       >=1.4

Flag pure-haskell-md5
  Description: Choose the purely Haskell MD5 implementation
  Default: False

Executable haq
  Main-is:           Haq.hs
  Build-Depends:     base-4.*
  if flag(pure-haskell-md5)
    Build-Depends:   pureMD5-0.2.*
  else
    Build-Depends:   hopenssl-1.1.*

The Cabal documentation has more details, in particular the section on Configurations .

As nominolo says, Cabal is the tool to use. In particular, the 'configurations" syntax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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