gpt4 book ai didi

haskell - 点对美元符号

转载 作者:行者123 更新时间:2023-12-02 15:27:13 24 4
gpt4 key购买 nike

print $ concat ["abc", "bde"]

打印

abcbde

然而,

print . concat ["abc", "bde"]

第二种情况抛出的错误是,

Couldn't match expected type ‘a -> b0’ with actual type ‘[Char]’
Relevant bindings include
it :: a -> IO () (bound at <interactive>:3:1)
Possible cause: ‘concat’ is applied to too many arguments

. (函数组合运算符)被使用是因为我认为它将获取 concat 函数的输出并将其传递给前面的函数 print?代码有什么问题?

最佳答案

只是优先级,真的;这会很好用:

(print . concat) ["abc", "bde"]

. 组合两个函数来创建一个新函数,而 $ 只是一种避免在这种情况下使用括号的方法。

关于haskell - 点对美元符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764819/

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