Proper way to treat global flags in Haskell

后端 未结 4 790
天涯浪人
天涯浪人 2021-02-07 12:19

I often need to make a core function that\'s used in many places somehow configurable - i.e., it may use either algorithm A or algorithm B depending on a command-line switch; o

4条回答
  •  不思量自难忘°
    2021-02-07 12:57

    Our new HFlags library is exactly for this.

    If you would like to see an example usage like your example, look into this:

    https://github.com/errge/hflags/blob/master/examples/ImportExample.hs

    https://github.com/errge/hflags/blob/master/examples/X/B.hs

    https://github.com/errge/hflags/blob/master/examples/X/Y_Y/A.hs

    No kind of parameter passing is needed between the modules, and you can define new flags with an easy syntax. It uses unsafePerformIO internally, but we think that it does that in a safe way, and you won't have to concern yourself with that.

    There is a blog post about this stuff at: http://blog.risko.hu/2012/04/ann-hflags-0.html

提交回复
热议问题