Content deleted Content added
mNo edit summary |
Nowhere man (talk | contribs) m More idiomatic code and explanation for Haskell |
||
Line 234:
===Haskell===
In [[Haskell (programming language)|Haskell]], with its [[lazy evaluation]] model,
<syntaxhighlight lang="haskell">
countFrom :: Integer -> [Integer]
from10to20 :: [Integer]
primes
primes = 2 : 3 : nextPrime 5
where
| otherwise = nextprime (n+2)▼
nextPrime n
where b = all ((/= 0).(rem n)) $ takeWhile ((<= n).(^2)) $ tail primes▼
| notDivisible n = n : nextPrime (n + 2)
notDivisible n =
</syntaxhighlight>
where <code>(:)</code> is a non-strict list constructor, ''cons'', and <code>$</code> is just a ''"called-with"'' operator, used for parenthesization. This uses the standard adaptor function,
Line 252 ⟶ 257:
| otherwise = []
</syntaxhighlight>
which
<syntaxhighlight lang="haskell">
</syntaxhighlight>
|