【发布时间】:2019-07-18 19:21:43
【问题描述】:
在一个非常简单的模块test 中我有以下功能
func :: String -> [Int]
func = read "[3,5,7]"
由于我有明确的类型注释,我希望在加载模块 test 并在 ghci 中调用 func 时得到 [3,5,7]。但是,我得到了
• No instance for (Read (String -> [Int]))
arising from a use of ‘read’
(maybe you haven't applied a function to enough arguments?)
• In the expression: read "[3,5,7]"
In an equation for ‘func’: func = read "[3,5,7]"
|
11 | func = read "[3,5,7]"
| ^^^^^^^^^^^^^^
但是当我执行read "[3,5,7]" :: [Int] 时,[3,5,7] 会按预期返回。为什么我在加载模块时出现错误?
【问题讨论】:
-
cd str = [ (fromEnum d) - 48 | d <- str, elem d '0'..'9']]将采用任何形式的单个数字字符串,cd "13579"或cd "[2,3,5,7]"或cd " 2 3 5"
标签: function haskell types compiler-errors type-signature