User Tools

Site Tools


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 [2021/03/23 18:52] – [Understanding Haskell] f2b216background [2025/10/08 00:44] (current) – external edit 127.0.0.1
Line 5: Line 5:
  
  
-====== Difficulties? You are not allone. ======+====== Difficulties to understand Haskell? You are not alone. ======
  
-Learning Haskell is still quite hard for me, and I need my own code knowing that the code really works, and 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 differnce 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 in the are not appropriate.+  * Often, the code examples are not appropriate.
     * ..or I am to stupid?     * ..or I am to stupid?
-    * Some of the available examples are outdated. +    * A lot of the available examples are outdated, and incompatible with current packages, libraries and compiler versions
-    * Somtimes just incomplete. +    * Often just incomplete. 
-    * Sometimes incompatible with the current packages. +    * Often they contain confusing useless, warning generating statements.
-    * Sometimes they contain confusing usless, warning generating statements.+
       * Example here: [[confusing:lyahpop|Confusing pop statement in LYAH]]       * Example here: [[confusing:lyahpop|Confusing pop statement in LYAH]]
   * Some of the available documentation is incomplete or inaccurate.   * Some of the available documentation is incomplete or inaccurate.
     * See the comments in [[https://stackoverflow.com/questions/65892923/where-accurately-to-set-dependencies-for-modules-to-import-using-the-haskell-t/65893019#65893019|here]]     * See the comments in [[https://stackoverflow.com/questions/65892923/where-accurately-to-set-dependencies-for-modules-to-import-using-the-haskell-t/65893019#65893019|here]]
   * Some information are only available on stackoverflow or reddit.   * Some information are only available on stackoverflow or reddit.
-  * If you place questions on stackoverflow, and don't know how to formulate the question from the very beginning then  you are also risking your reputation, like [[https://stackoverflow.com/questions/65892923/where-accurately-to-set-dependencies-for-modules-to-import-using-the-haskell-t/65893019#65893019|here]], again +  * If you place questions on stackoverflow, and don't know how to formulate the question from the very beginning then you are also risking your reputation, like [[https://stackoverflow.com/questions/65892923/where-accurately-to-set-dependencies-for-modules-to-import-using-the-haskell-t/65893019#65893019|here]].
  
 ====== About ====== ====== About ======
Line 29: Line 27:
 ===== Understanding ===== ===== Understanding =====
  
-was may be a techie since I was a curious child. At an age of approximately 8 years, I assambled an electric DC Motor, and believe still to remember that I was shocked and amazed that it worked. I was so keen to understand... +consider myself a techie since I was a curious child. At an age of approximately 8 years, I assambled an electric DC Motor, and believe still to remember that I was shocked and amazed that it worked. I was so keen to understand...
- +
-This craving to understand is a very big driver and also related to other topics: +
- +
-<sup> +
-  * Technology +
-    * Why is the world like this? +
-    * Why is the world at all? +
-    * How do computers work? +
-    * I have to know how a computer works. +
-    * I build my computer? +
-    * I need to program. +
-    * Assembler +
-    * Modula-2 +
-    * C +
-    * C++ +
-    * PHP +
-    * Java script +
-    * Java +
-    * Haskell +
-    * Scala +
-    * ... +
-  * Spirit +
-    * How does the brain work? +
-    * Does psychology work? +
-    * Can someone change himself or herself? +
-    * Is there a god? +
-    * How do neuronal networks work? +
-    * I have to program a neronal network. +
-    * What is spirituality, at all? +
-    * What is Zen? +
-    * I have to practice Zen. +
-    * I practice Meditation, since November 2008. +
-    * What is enlightenment? +
-    * Why is the driven mind so reluctant to try this? +
-    * ... +
-  * Beeing one society +
-    * How can people live together and accepting eachother as they are? +
-    * ... +
-</sup>+
  
 +This craving to understand is a very big driver - for me.
 ===== Understanding Haskell ===== ===== Understanding Haskell =====
  
-Let's put this question on hold: How can people live together and accepting eachother as they are?+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.
  
-In the meantime, let's understand how Haskell works?+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 97: 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 124: Line 84:
  
   * Haskell is fast.   * Haskell is fast.
-    * The execution of the algorithm above takes approximately 1 minute.+    * The execution of the algorithm above takes approximately 1 minute on a modern computer (Year 2021).
   * Haskell supports parallel execution.   * Haskell supports parallel execution.
   * Is very good testable and validatable to rock solid code.   * Is very good testable and validatable to rock solid code.
   * Haskell programs can solve problems that I would not dare to solve without - at least without a functional programming language like Haskell.   * Haskell programs can solve problems that I would not dare to solve without - at least without a functional programming language like Haskell.
 +
 +
 +----
  
 )<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.1616521965.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