1
如何编写模板哈斯克尔功能使得:生成具有模板哈斯克尔函数定义
mkFunc "func"
产生
func = "func"
我已经试过这
mkFunc x = ValD (VarP x) (NormalB (LitE (StringL x))) []
但它不” t typecheck:
Couldn't match type ‘Name’ with ‘[Char]’
Expected type: String
Actual type: Name
In the first argument of ‘StringL’, namely ‘x’
In the first argument of ‘LitE’, namely ‘(StringL x)’
此外,在定义了mkFunc
之后,我怎样才能定义mkFuncs
这个函数定义了一个列表?
的感谢!更精确些:makeFuncs :: [String] - > Q [Dec] makeFuncs ss = return $ foldl1(++)$ mapM(\ x - > [ValD(VarP(mkName x))(NormalB(LitE(StringL x)))[]])ss btw,我们可以使用quasiquoters而不是直接操纵AST吗? – doofin