【发布时间】:2012-01-20 11:56:23
【问题描述】:
我有一些类似这样的 Haskell 样板:
data Configuration
{ confA :: Integer
, confB :: Boolean
, confC :: String }
x = (\arg opt -> opt{ confA=arg })
y = (\arg opt -> opt{ confB=arg })
z = (\arg opt -> opt{ confC=arg })
我想删除样板,产生如下内容:
setter :: (Config -> a) -> a -> Config -> Config
x = setter confA
y = setter confB
z = setter confC
但我不知道如何构造这样的setter 函数。这甚至可能在(非模板)haskell 中还是我在这里与语法糖对接?如果是这样,我将如何在模板 haskell 中做这样的事情?
【问题讨论】:
标签: haskell