background

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
background [2022/04/21 21:58] – [Difficulties to understand Haskell? You are not alone.] f2b216background [2025/10/08 00:44] (current) – external edit 127.0.0.1
Line 14: Line 14:
   * Often, the code examples are not appropriate.   * Often, the code examples are not appropriate.
     * ..or I am to stupid?     * ..or I am to stupid?
-    * A lot of the available examples are outdated.+    * A lot of the available examples are outdated, and incompatible with current packages, libraries and compiler versions.
     * Often just incomplete.     * Often just incomplete.
-    * Often incompatible with the current packages. 
     * Often they contain confusing useless, warning generating statements.     * Often they contain confusing useless, warning generating statements.
       * Example here: [[confusing:lyahpop|Confusing pop statement in LYAH]]       * Example here: [[confusing:lyahpop|Confusing pop statement in LYAH]]
Line 33: Line 32:
 ===== Understanding Haskell ===== ===== Understanding Haskell =====
  
-Let's understand how Haskell works?+Just to imagine how rich Haskell is in terms of abstraction - and to understand how must can be and sometimes has to be understood - enyoy the example below. 
 + 
 +The following shows how 10 primes are evaluated and displayed starting with the one millionth prime number.
  
   * Example )<sup>1</sup> )<sup>2</sup>:   * Example )<sup>1</sup> )<sup>2</sup>:
Line 56: Line 57:
 </code> </code>
  
-To understand this code (lines of code) completely I have to understand the following:+To understand this code (lines of code) completely I have to understand the following:
   - Packets   - Packets
   - Import   - Import
Line 92: Line 93:
  
 )<sup>1</sup> The code may __**not**__ work with extrem large numbers. I do not know at which conditions the floor function would fail. My calculator says sqrt((1E16x1E16)-1) is 9.999.999.999.999.999,9999999999999999, but sqrt((1E17x1E17)-1) is (1E17)! )<sup>1</sup> The code may __**not**__ work with extrem large numbers. I do not know at which conditions the floor function would fail. My calculator says sqrt((1E16x1E16)-1) is 9.999.999.999.999.999,9999999999999999, but sqrt((1E17x1E17)-1) is (1E17)!
 +
 +The following code (sieve of Erastothenes) will also work but by far not as fast for large numbers (approximately 100 times slower for the first 20 thousand prime numbers):
 +<code Haskell>
 +primes = let sieve (n0:lrn) = n0 : sieve [ n | n <- lrn, n `mod` n0 /= 0 ] in sieve [2..]
 +</code>
  
 )<sup>2</sup> The code compiles without any warnings with ghc 8.10.4 and option -Wall. )<sup>2</sup> The code compiles without any warnings with ghc 8.10.4 and option -Wall.
background.1650571138.txt.gz · Last modified: (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki