![]() And that is only my opinion - there are people out there who really go out of their way and use it for way more (backend, …). ![]() I really did not want to make the impression that Elm is a toy - it’s a tool and it’s rather specific (creating Web-Apps for a lack of a better word). That’s why I personally would keep it simple and see how to get this working for small numbers - especially if this is only for learning purposes. To be honest I don’t have much experience in optimizing Elm in that way (there is the compiler in between and the output contains all the runtime so it’s not easy to see what is produced).Ĭoncerning the StackOverflow: usually you can get rid of this by pushing stuff on the heap instead of the stack (continuations often work) so with a bit of work we should be able to fix this.īut then you have a big messy piece of code where the original concern probably is almost not recognizable. There are packages like list-extra that includes some of those but I though it’s better to keep it with what comes after elm init. I don’t mind continuing this here it’s just that I don’t really use Elm for this kind of algorithms (I’d go with Haskell here) so I constantly are missing functions I’d go to. Yes you should be able to rewrite most of this into List.fold style - maybe it’s a good exercise for you? If you want I can have a go at it but it’ll probably have to wait till tomorrow. ![]() How about using combination of sieve function, map2 and filter or foldl or recursion and sieve? Sieve 2 il |> sieve 3 |> sieve 5 |> sieve 7 |> sieve 11 Sieve prime integers = List.filter (\i → remainderBy prime i > 0) integers The primes used in sieve are dropped from beginning of the resulting list. This shall find all primes of the range 1 … 121. I wrote a little piece just for begin using elm repl… There is one exception, Haskell, see Sieve of Eratosthenes but I don’t read haskell. Perhaps it’s piece of cake to write a code for Eratoshenes sieve in FP and it’s assumed everybody can do it for him(her)self. Maybe the primes are not an interesting topic in a language used mainly in frontend codes. I tried to find a code for searching prime numbers but there is hardly anything written in elm, not much in any other functional programmng language either.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |