background
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| background [2021/03/23 17:47] – [Understanding Haskell] f2b216 | background [2025/10/08 00:44] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| - | ====== Difficulties? | + | ====== Difficulties |
| - | Learning Haskell | + | Learning Haskell |
| 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 | + | * The difference between the imperative paradigm and the functional paradigm is like the difference |
| * Often, the code examples 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 | + | * Often just incomplete. |
| - | * Sometimes incompatible with the current packages. | + | * Often they contain confusing |
| - | * Sometimes | + | |
| * Example here: [[confusing: | * Example here: [[confusing: | ||
| * Some of the available documentation is incomplete or inaccurate. | * Some of the available documentation is incomplete or inaccurate. | ||
| * See the comments in [[https:// | * See the comments in [[https:// | ||
| * Some information are only available on stackoverflow or reddit. | * Some information are only available on stackoverflow or reddit. | ||
| - | * If you place questions on stackoverflow, | + | * If you place questions on stackoverflow, |
| - | + | ====== About ====== | |
| - | ====== About Jörg Brüggamnn | + | |
| ===== Understanding ===== | ===== Understanding ===== | ||
| - | I 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 was amased | + | I consider myself |
| - | + | ||
| - | This understanding is very deep and also related | + | |
| - | + | ||
| - | < | + | |
| - | * 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, | + | |
| - | * 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? | + | |
| - | * ... | + | |
| - | </ | + | |
| + | 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 | + | 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 | + | The following shows how 10 primes are evaluated and displayed starting with the one millionth prime number. |
| - | * Example: | + | * Example |
| * <code Haskell> | * <code Haskell> | ||
| module Main where | module Main where | ||
| + | |||
| + | import qualified Data.List as L | ||
| main :: IO () | main :: IO () | ||
| - | main = do print $ take 100 (primes :: [Integer]) | + | main = do print ((genericTakeFrom 1000000 10 primes) :: [Integer]) |
| - | primes | + | genericTakeFrom |
| + | genericTakeFrom nFrom nCount l = L.genericTake nCount ((L.genericDrop nFrom) l) | ||
| + | |||
| + | primes :: Integral a => [a] | ||
| primes = 2 : [n | n <- [3, 5..], all ((> 0).rem n) [3, 5..floor.sqrt$((fromIntegral n) :: Double)]] | primes = 2 : [n | n <- [3, 5..], all ((> 0).rem n) [3, 5..floor.sqrt$((fromIntegral n) :: Double)]] | ||
| </ | </ | ||
| Line 89: | Line 54: | ||
| * Output: | * Output: | ||
| * < | * < | ||
| - | [2,3,5,7,11,13,17,19,23,29, | + | [15485867,15485917,15485927,15485933,15485941,15485959,15485989,15485993,15486013,15486041] |
| - | + | </ | |
| - | The code above works without any warnings with ghc 8.10.4 and option -Wall. | + | |
| - | 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 | ||
| - Prelude | - Prelude | ||
| - Monads | - Monads | ||
| - '' | - '' | ||
| - [[https:// | - [[https:// | ||
| + | - Types | ||
| - Type signatures | - Type signatures | ||
| - Type defaulting | - Type defaulting | ||
| Line 105: | Line 71: | ||
| - Lists | - Lists | ||
| - List comprehension | - List comprehension | ||
| + | - Recursion | ||
| - Function composition | - Function composition | ||
| + | - Lazy evaluation | ||
| And there is also | And there is also | ||
| - | * design | + | * design, |
| - | * optimisation | + | * optimisation, |
| - | * test | + | * test, and |
| - | * proove | + | * proove |
| - | * to estabish | + | |
| + | ===== Why is it still worth to use Haskell? ===== | ||
| + | |||
| + | * Haskell is fast. | ||
| + | * The execution of the algorithm above takes approximately 1 minute on a modern computer (Year 2021). | ||
| + | * Haskell supports parallel execution. | ||
| + | * Is very good testable and validatable | ||
| + | * Haskell programs can solve problems that I would not dare to solve without - at least without a functional programming language like Haskell. | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | )< | ||
| + | |||
| + | 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..] | ||
| + | </ | ||
| - | ) <sup>1</ | + | )< |
background.1616518040.txt.gz · Last modified: (external edit)
