Sieve of Eratosthenes: Difference between revisions
Content deleted Content added
imported>Polarit →{{header|Elm with immutable arrays}}: fixed header |
imported>Polarit m →Elm with immutable arrays: commening |
||
Line 6,657: | Line 6,657: | ||
{- |
{- |
||
The Eratosthenes sieve task in Rosetta Code does not accept the use of modulo function (allthough Elm functions modBy and remainderBy work always correctly as they require type Int excluding type Float). Thus the solution needs an indexed work array as Elm has no indexes for lists. |
|||
the use of modulo function (allthough Elm functions modBy and remainderBy work always correctly as they require type Int excluding type Float). |
|||
In this method we need no division remainder calculations, as we just set the markings of non-primes into the array. We need the indexes that we know, where the marking of the non-primes shall be set. |
|||
Thus the solution needs an indexed work array |
|||
as Elm has no indexes for lists. |
|||
In this method we need no division remainder calculations, |
|||
as we just set the markings of non-primes into the array. |
|||
We need the indexes that we know, where the marking of the non-primes |
|||
shall be set. |
|||
Because everything is immutable in Elm, every change of array values will create a new array save the original array unchanged. That makes the program running slower or consuming more space of memory than with non-functional imperative languages. All conventional loops (for, while, until) are excluded in Elm because immutability requirement. |
Because everything is immutable in Elm, every change of array values will create a new array save the original array unchanged. That makes the program running slower or consuming more space of memory than with non-functional imperative languages. All conventional loops (for, while, until) are excluded in Elm because immutability requirement. |
||