我想找到一组列表中的最小值
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/