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

标签 haskell functional-programming

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

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/

相关文章:

javascript - 功能性 javascript 和网络浏览器 javascript 版本

javascript - Lodash 中 curry 和 curryRight 的区别

multithreading - forkOn 和 -qm RTS 标志之间有什么关系?

haskell - 类别中初始对象和终止对象之间的差异

haskell - 为什么 Char 有一个 Bounded 的实例?

haskell - 如何避免重复类似的表达?

通过重复输入/迭代来定义列表

lambda - 使用 Java 8 Stream API 展平 map 并关联值

Scheme中的图编程

recursion - 与 SUCC 的功能