[Int]; func = read "有什么问题 [3,5,7 ]""-6ren"> [Int]; func = read "有什么问题 [3,5,7 ]""-在一个非常简单的模块中test我有以下功能 func :: String -> [Int] func = read "[3,5,7]" 由于我有明确的类型注释,我希望得到 [3,5,7]当我加载模块 -6ren">
gpt4 book ai didi

function - "func::String -> [Int]; func = read "有什么问题 [3,5,7 ]""

转载 作者:行者123 更新时间:2023-12-02 02:19:18 26 4
gpt4 key购买 nike

在一个非常简单的模块中test我有以下功能

func :: String -> [Int]
func = read "[3,5,7]"

由于我有明确的类型注释,我希望得到 [3,5,7]当我加载模块 test并调用 func在 ghci 中。然而,我得到了
    • 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]按预期返回。为什么在我加载模块时会引发错误?

最佳答案

您正在尝试将字符串作为 String -> [Int] 类型的函数读取。 ,而不是列表 [Int] .但是,read无法将字符串转换为函数。

试试这个:

myList :: [Int]
myList = read "[3,5,7]"

关于function - "func::String -> [Int]; func = read "有什么问题 [3,5,7 ]"",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54865352/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com