Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Why learn Haskell? Haskell 101. Chapter 1.
Brain Dump
Sep 4, 2024
103 views
Before we learn any syntax or anything. Let's first explore the most important question to learn anything.
That is to learn why learn Haskell?
Let's explore what makes Haskell worth learning and what makes it unique.
1. Pure Functional Programming:
This is the most important point.
Haskell is purely functional programming, which means it treats computation as the evaluation of mathematical functions. Pure functional programming means that functions are pure, having two main properties:
Let's see what it means:
In imperative languages, functions can often have side effects, which can lead to unexpected behaviour. In Haskell, functions are predictable.
Example:
later we will understand keywords and syntax i.e :: . For now just try to get the gist.
For easy explanation we will compare Haskell to Typescript:
What is Currying?
The names comes from Haskell Curry, a mathematician and logician.
Currying is a technique in functional programming where a function that takes multiple arguments is transformed into a sequence of functions, each taking single arguments.
Currying is a way of structuring functions that makes them more flexible.
Let's use a real world analogy:
Imagine you have a coffee machine that makes different types of coffee drinks.
Here a curried version is more specialized than the non curried one.
Key points to take away:
In Haskell, this currying is automatic. Every function is curried by default:
Currying breaks down a function that takes multiple arguments into a series of function, each taking a single argument which make your code more flexible and easier to reuse.
2. Concurrency & Easier Parallel Programming.
3. Strong static typing.
4. Mathematical foundations:
Haskell was designed with strong mathematical principles in mind. Learning haskell can help develop a more mathematical way of thinking about programming problems.
5. Lazy Evaluation:
Allows us to define potentially infinite computation & data structures, but only compute the parts you actually use. This can lead to more efficient programs & allow for elegant solutions to certain problems.
Breaking down the codes:
For examples provided earlier in this notes, we will discuss it here for clearly understanding.
Type signature:
It's read as has type of or is of type. This symbol is a fundamental part of Haskell's syntax for explicitly declaring the types of expression, functions or variables.
Let's break it down with some examples:
declares that x has type of Int & then assigns the value 5
For functions
declares that add is a function that takes two Int parameters and returns Int
Since we also learnt what is currying this same statement could be written as
Last Int and the b is always the retun type
Dissecting it:
#Haskell #functionalProgramming #CSCE550