相关疑难解决方法(0)

使用Template Haskell生成函数

是否可以使用Template Haskell定义函数?例如

convertStringToValue :: String -> Int
convertStringToValue "three" = 3
convertStringToValue "four" = 4
Run Code Online (Sandbox Code Playgroud)

我也有Map [Char] Int.

fromList [("five",5),("six",6)]
Run Code Online (Sandbox Code Playgroud)

我该如何添加功能

convertStringToValue "six" = 6
convertStringToValue "five" = 5
Run Code Online (Sandbox Code Playgroud)

在编译时使用Template Haskell和Map?使用Template Haskell来达到这个目的似乎很愚蠢,但我还是想知道.

haskell template-haskell

10
推荐指数
1
解决办法
574
查看次数

标签 统计

haskell ×1

template-haskell ×1