我正在传递一个部分应用的功能。完整的签名是:
import Data.Map as Map
-- Update the correct bin of the histogram based on the min value, bin width,
-- the histogram stored as a map, and the actual value we are interested in.
updateHist :: Double -> Double -> Map.Map Bin Double -> Double ->
Map.Map Bin Double
该函数更新存储直方图数据的地图。前两个参数给出了我们感兴趣的数据的下界,下一个是直方图的 bin 宽度。我在程序启动时填写这些值,并在整个模块中传递部分应用的函数。这意味着我有大量的函数,其签名如下:
-- Extra the data out of the string and update the histogram (in the Map) with it.
doSomething :: String -> (Map.Map Bin Double -> Double -> Map.Map Bin Double) ->
Map.Map Bin Double
这一切都很好,但写“(Map.Map Bin Double -> Double -> Map.Map Bin Double)”相当冗长。我想将它们全部替换为“UpdateHistFunc”作为一种类型,但由于某种原因我一直失败。
我试过:
newtype UpdateHistFunc = Map.Map Bin Double -> Double -> Map.Map Bin Double
这失败并出现错误:
HistogramForColumn.hs:84:44: 解析错误输入`->'
我究竟做错了什么?