English 中文(简体)
Most “English-Like” Solutions to Project Euler # 1
原标题:Most "English-Like" solution to Project Euler # 1
  • 时间:2012-01-12 23:01:23
  •  标签:
  • haskell

Beginner Haskell 在这里学习。 我解决了Euler项目问题1, 数额比1 000多3或5人,但我期待着“更像英语”的功能代表。

我设立了一个称为多个单位的职能。

multiples::(Integral a) => a -> [a]
multiples a = map (*a) [1..]

我高兴,但我希望说,

multiples of::(Integral a) => a -> [a]
multiples of a = map (*a) [1..]

更像英文,但在“对”投入方面,我有一小差错。

我想我的职能声明读作这样的内容:

sum of multiples of::(Type)=>Type->Type

任何希望?

最佳回答

这种说法不言而喻,但你只能界定“词”,无视你“英文”职能中的论点:

by = ()
multiply a _ b = a*b

multiply 10 by 12
--120

但是,在您的榜样中,作为的<>编码>,你从中转出一个关键词(载于)。

By the way, here is another way of defining multiples:

multiples_of = scanl1 (+) . repeat

take 10 $ multiples_of 12
--[12,24,36,48,60,72,84,96,108,120]
问题回答

暂无回答




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

热门标签