English 中文(简体)
新型。 说 明
原标题:newbie on sort.words
  • 时间:2012-01-13 22:23:29
  •  标签:
  • haskell

This expression:

sort words "fire water earth fire"

---

Couldn t match expected type `[a] 
against inferred type `GHC.Base.String -> [GHC.Base.String] 

Could someone explain to me what is going on here and how to elegantly express sort.words?

最佳回答

希望:

sort (words "fire water earth fire")

when you do

sort words "fire water earth fire"

它实际上这样做

(sort words) "fire water earth fire"

www.un.org/sc/ 范围——和;[标准]/编号——作为任何清单。

也可以这样做:

sort $ words "fire water earth fire"

这相当于第一版,可能会看上去。

问题回答

功能应用与左侧相联,因此,斜体为<条码>(直言)“火水土火灾<>。 不用说,对职能进行分类<代码> 工作做得很好! 因此,错误信息告诉你,sort期望有“>[a](即,名单)”的论据,但您将其适用于“<代码>的某种类型。 String -> [String], 即words

你们要么希望sort (words "fire water Earth fire”),要么使用更为常见的迪恩,sort$“fire water Earth fire”。 <<>代码>($)的操作者只是功能应用,但具有极低的、正确的关联性优先,因此经常以类似表述的形式使用,以避免书写母体。





相关问题
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?

热门标签