background
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| background [2021/09/18 10:02] – [Understanding] f2b216 | background [2025/10/08 00:44] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| ====== Difficulties to understand Haskell? You are not alone. ====== | ====== Difficulties to understand Haskell? You are not alone. ====== | ||
| - | Learning Haskell was quite hard for me, and I needed to be confident that my own code really works under which conditions. This is may be the same for you. | + | Learning Haskell was quite hard for me, and I needed to be confident that my own code really works, and under which conditions. This is may be the same for you. |
| The reasons for the difficulties in learning Haskell, may be: | The reasons for the difficulties in learning Haskell, may be: | ||
| * Before I started with Haskell, I was only used to imperative languages (Assembler, C, Pascal, Modula-2, C++, PHP, and more). The most, I was used to C++. | * Before I started with Haskell, I was only used to imperative languages (Assembler, C, Pascal, Modula-2, C++, PHP, and more). The most, I was used to C++. | ||
| * The difference between the imperative paradigm and the functional paradigm is like the difference between hockey and chess. It is both sport, isn't it? ;-) | * The difference between the imperative paradigm and the functional paradigm is like the difference between hockey and chess. It is both sport, isn't it? ;-) | ||
| - | * Often, the code examples | + | * 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: | * Example here: [[confusing: | ||
| Line 33: | Line 32: | ||
| ===== Understanding Haskell ===== | ===== Understanding Haskell ===== | ||
| - | Let's understand | + | Just to imagine |
| + | |||
| + | The following shows how 10 primes are evaluated and displayed starting with the one millionth prime number. | ||
| * Example )< | * Example )< | ||
| Line 56: | Line 57: | ||
| </ | </ | ||
| - | To understand this code (7 lines of code) completely I have to understand the following: | + | To understand this code (8 lines of code) completely I have to understand the following: |
| - Packets | - Packets | ||
| - Import | - Import | ||
| Line 92: | Line 93: | ||
| )< | )< | ||
| + | |||
| + | 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..] | ||
| + | </ | ||
| )< | )< | ||
background.1631952132.txt.gz · Last modified: (external edit)
