gpt4 book ai didi

haskell - 将 min 命令映射到 haskell 中的多级列表

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

我想找到一组列表中的最小值

map min [[1, 3], [2, 7],[9, 6]]

我想要输出

[[1],[2],[6]]

它给出了错误:

* No instance for (Show ([Integer] -> [Integer]))
arising from a use of `print'
(maybe you haven't applied a function to enough arguments?)
* In a stmt of an interactive GHCi command: print it

最佳答案

min :: Ord a => a -> a -> a对两个项目进行处理以返回两者中的最小值。您可能正在寻找minimum :: (Foldable f, Ord a) => f a -> a相反:

Prelude> map <b>minimum</b> [[1, 3], [2, 7],[9, 6]]
[1,2,6]

这里的项目没有包装在单独的子列表中,但这只会导致(不必要的)额外的间接层。

关于haskell - 将 min 命令映射到 haskell 中的多级列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57795685/

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