English 中文(简体)
Haskell Newbie: 地图功能中没有显示
原标题:Haskell Newbie: No instance for Show in map function

在GHCI,我类型如下:

map (+1) [1..10]

which returns [2,3,4,5,6,7,8,9,10,11]

迄今情况良好。

现为第一类:

min (map (+1) [1..10])

我收到以下错误信息:

No instance for (Show ([b0] -> [b0]))
  arising from a use of `print 
Possible fix: add an instance declaration for (Show ([b0] -> [b0]))
In a stmt of an interactive GHCi command: print it

这对我来说非常奇怪。 为什么我会认为我是谁试图印刷任何论点? 我如何确定这一点?

最佳回答

问题是<代码>min。 有两个论点(至少是两个论点),但你只提出具体论点;你希望<条码>最低,该文本在名单上运作。

Specifically, this error occurs because GHCi tries to print out the result of the expressions you evaluate, but in this case, you ve applied min to one argument, producing another function.1 GHCi dutifully tries to print this out, but it fails, because functions are not an instance of Show, the standard type-class for things that can be represented as strings for display.

1 In Haskell, all functions take one argument, and functions of multiple arguments are built up from functions returning other functions; for instance, a function adding two integers might have the type Integer -> Integer -> Integer, which is Integer -> (Integer -> Integer) — a function taking an Integer and returning another function which itself takes an Integer, and returns an Integer. Thankfully, you don t have to think about this in such explicit terms very often, or it d get very confusing!

问题回答

暂无回答




相关问题
Euler Problem in Haskell -- Can Someone Spot My Error

I m trying my hand at Euler Problem 4 in Haskell. It asks for that largest palindrome formed by multiplying two three-digit numbers. The problem was simple enough, and I thought my Haskell-fu was up ...

How does foldr work?

Can anybody explain how does foldr work? Take these examples: Prelude> foldr (-) 54 [10, 11] 53 Prelude> foldr (x y -> (x+y)/2) 54 [12, 4, 10, 6] 12.0 I am confused about these executions....

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Problem detecting cyclic numbers in Haskell

I am doing problem 61 at project Euler and came up with the following code (to test the case they give): p3 n = n*(n+1) `div` 2 p4 n = n*n p5 n = n*(3*n -1) `div` 2 p6 n = n*(2*n -1) p7 n = n*(5*n -3)...

Ways to get the middle of a list in Haskell?

I ve just started learning about Functional Programming, using Haskel. I m slowly getting through Erik Meijer s lectures on Channel 9 (I ve watched the first 4 so far) and in the 4th video Erik ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?

热门标签