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