Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 C I can use Autotools/Scons/CMake + cpp. In Python I can catch ImportError. Which tools should I use in Haskell?

like image 707
sastanin Avatar asked Apr 14 '09 12:04

sastanin


2 Answers

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

Name:                myfancypackage
Version:             0.0
Description:         myfancypackage
License:             BSD3
License-file:        LICENSE
Author:              John Doe
Maintainer:          [email protected]
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.

like image 79
nominolo Avatar answered Sep 28 '22 14:09

nominolo


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

like image 27
Don Stewart Avatar answered Sep 28 '22 16:09

Don Stewart