• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

willdonnelly/dyre: A Dynamic Reconfiguration Library for Haskell Programs

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

willdonnelly/dyre

开源软件地址(OpenSource Url):

https://github.com/willdonnelly/dyre

开源编程语言(OpenSource Language):

Haskell 92.0%

开源软件介绍(OpenSource Introduction):

Dyre - A Dynamic Reconfiguration Library for Haskell

Dyre implements a basic interface for dynamically recompiling Haskell programs with new configurations. The inspiration for all this is, of course, Xmonad's reconfiguration functionality. It is similar in usage to the HConf library which was written for the Yi editor.

Basic Usage

The main interface to the Dyre library consists of three items: a datatype for configuration data, a set of default values, and a function which makes that data into an entry-point function.

A complete, working example can be seen here:

-- DyreExample.hs --
module DyreExample ( dyreExample ) where

import qualified Config.Dyre as Dyre

confError cfgMessage error = "Error:" ++ error ++ "\n" ++ cfgMessage

realMain message = do
    putStrLn "Entered Main Function"
    putStrLn message

dyreExample = Dyre.wrapMain $ newParams "dyreExample" realMain confError

This code defines a simple library which will display a message on stdout. It uses Dyre to provide configuration of what exactly the message is. The default configuration could look something like this:

-- Main.hs --
import DyreExample
main = dyreExample "This is the default configuration"

While a user's custom configuration would be more like this:

-- dyreExample.hs --
import DyreExample
main = dyreExample "This is a custom configuration"

This example can be run without installing. Simply run Main.hs[^1] with the argument '--dyre-debug', to tell it to search for a configuration file in the current directory. If the custom configuration exists, it will be compiled and executed, or the default message will be displayed if there is no custom configuration.

The Dyre.wrapMain function is how Dyre is meant to be invoked. It is passed a set of parameters which configure how it operates. Most parameters have some good defaults, but can be overriden on the record produced by newParams.

The Dyre.projectName element is used to search for a custom configuration, the Dyre.showError element is called with compile errors to store the information in the program configuration, and Dyre.realMain is the function which is ultimately the main program entry point.

For the other parameters Dyre uses, consult the Config.Dyre.Params module documentation.

[^1] You can compile it with ghc --make, or simply use runhaskell Main.hs.

Restarting and Persistent State

Restarting is handled by the Config.Dyre.Relaunch module. To simply restart, discarding all state information, use the relaunchMaster function.

If the state needs to be preserved, there are two pairs of functions available. When your program starts, you will want to use either the restoreTextState or the restoreBinaryState function. Both of these take a default state which is returned when there is no persisted state to use.

Then to restart and persist the state, use the function relaunchWithTextState or relaunchWithBinaryState corresponding to your chosen restore function. The state will be persisted and your program restarted for you.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap