User Tools

Site Tools


background

This is an old revision of the document!


Background

I am going to update this wiki as I am learning Haskell, and reading your comments.

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.

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++.
  • 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.
    • ..or I am to stupid?
    • A lot of the available examples are outdated.
    • Often just incomplete.
    • Often incompatible with the current packages.
    • Often they contain confusing useless, warning generating statements.
  • Some of the available documentation is incomplete or inaccurate.
    • See the comments in here
  • 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 here.

About

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 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 - for me.

Understanding Haskell

Let's understand how Haskell works?

  • Example )1 )2:
    • module Main where
       
      import qualified Data.List as L
       
      main :: IO ()
      main = do print ((genericTakeFrom 1000000 10 primes) :: [Integer])
       
      genericTakeFrom :: Integral a => a -> a -> [a] -> [a]
      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)]]
  • Output:
    • [15485867,15485917,15485927,15485933,15485941,15485959,15485989,15485993,15486013,15486041]

To understand this code (7 lines of code) completely I have to understand the following:

  1. Packets
  2. Import
  3. Prelude
  4. Monads
  5. do-notation
  6. Types
  7. Type signatures
  8. Type defaulting
  9. Type classes
  10. Type constraints
  11. Lists
  12. List comprehension
  13. Recursion
  14. Function composition
  15. Lazy evaluation

And there is also

  • design,
  • optimisation,
  • test, and
  • proove of validity

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 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.

)1 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)!

)2 The code compiles without any warnings with ghc 8.10.4 and option -Wall.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
You could leave a comment if you were logged in.
background.1631952083.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