Compare commits
4 Commits
2828b36251
...
4d742b6b88
Author | SHA1 | Date | |
---|---|---|---|
4d742b6b88 | |||
a30e91976a | |||
2e97717395 | |||
ab3c6ed53a |
10
README.md
10
README.md
@ -1,10 +1,18 @@
|
|||||||
# learning-languages
|
|
||||||
|
# Learning new languages and documenting my journey
|
||||||
|
|
||||||
Repository which documents my journey in learning new languages.
|
Repository which documents my journey in learning new languages.
|
||||||
|
|
||||||
Currently learning:
|
Currently learning:
|
||||||
|
<style>
|
||||||
|
#rust {
|
||||||
|
filter: invert(1);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
<span id="rust">
|
||||||
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/rust/rust-original.svg" alt="Rust" width="50" height="50"/>
|
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/rust/rust-original.svg" alt="Rust" width="50" height="50"/>
|
||||||
|
</span>
|
||||||
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/haskell/haskell-original.svg" alt="Haskell" width="50" height="50"/>
|
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/haskell/haskell-original.svg" alt="Haskell" width="50" height="50"/>
|
||||||
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/swift/swift-original.svg" alt="Swift" width="50" height="50"/>
|
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/swift/swift-original.svg" alt="Swift" width="50" height="50"/>
|
||||||
<img src="https://dashboard.snapcraft.io/site_media/appmedia/2021/01/coq.png" alt="Coq" width="50" height="50"/>
|
<img src="https://dashboard.snapcraft.io/site_media/appmedia/2021/01/coq.png" alt="Coq" width="50" height="50"/>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<p align = "center">
|
<p align = "center">
|
||||||
<img src = "https://upload.wikimedia.org/wikipedia/commons/d/d8/Coq_logo.png" width = "100">
|
<img src = "https://calebstanford.com/img/2018/coq-vector-logo/coq-logo-large.png" width = "200">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# Learn Coq with me
|
# Introduction
|
||||||
<a href = "https://github.com/alhassy/CoqCheatSheet/blob/master/CheatSheet.pdf">
|
<a href = "https://github.com/alhassy/CoqCheatSheet/blob/master/CheatSheet.pdf">
|
||||||
<img src = "https://img.shields.io/badge/-CheatSheet-blue">
|
<img src = "https://img.shields.io/badge/-CheatSheet-blue">
|
||||||
</a>
|
</a>
|
||||||
@ -18,12 +18,12 @@ When I feel confident enough, I will film a 1-2h tutorial on Coq and attach it t
|
|||||||
<!-- - [Software Foundations](https://softwarefoundations.cis.upenn.edu/current/index.html) by Benjamin C. Pierce et al. -->
|
<!-- - [Software Foundations](https://softwarefoundations.cis.upenn.edu/current/index.html) by Benjamin C. Pierce et al. -->
|
||||||
|
|
||||||
## ToC
|
## ToC
|
||||||
- [Learn Coq with me](#learn-coq-with-me)
|
- [Introduction](#introduction)
|
||||||
- [ToC](#toc)
|
- [ToC](#toc)
|
||||||
- [Motivation](#motivation)
|
- [Motivation](#motivation)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Basic Coq](#basic-coq)
|
- [Basic Coq](#basic-coq)
|
||||||
- [Introduction](#introduction)
|
- [Introduction](#introduction-1)
|
||||||
- [Comment on semantics](#comment-on-semantics)
|
- [Comment on semantics](#comment-on-semantics)
|
||||||
- [Type theory](#type-theory)
|
- [Type theory](#type-theory)
|
||||||
- [Basic Concepts + Syntax](#basic-concepts--syntax)
|
- [Basic Concepts + Syntax](#basic-concepts--syntax)
|
||||||
|
40
haskell/README.md
Normal file
40
haskell/README.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<p align = "center">
|
||||||
|
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/haskell/haskell-original.svg" alt="Haskell" width="200"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
# Introduction
|
||||||
|
After miserably failing my Functional Programming exam and some soul searching, I realized that I never really learned Haskell nor did I ever really understand functional programming. So, I decided to learn Haskell properly. This repository will document my journey in learning Haskell.
|
||||||
|
|
||||||
|
With the help of some friends!
|
||||||
|
|
||||||
|
This is going to be structured in a different way than my other repositories. I will have a `sessions` folder where I will document my thought process and the things I learned while during my "lessons". Maybe do Haskell notebooks? I don't know yet.
|
||||||
|
|
||||||
|
This is the larger, more general README, which will house the main takeaways/revelations of the sessions.
|
||||||
|
|
||||||
|
## ToC
|
||||||
|
- [Introduction](#introduction)
|
||||||
|
- [ToC](#toc)
|
||||||
|
- [Books and resources](#books-and-resources)
|
||||||
|
- [13th of March - Introduction](#13th-of-march---introduction)
|
||||||
|
|
||||||
|
# Books and resources
|
||||||
|
- [Haskell Programming from first principles](http://haskellbook.com/)
|
||||||
|
- [Learn you a Haskell for great good](http://learnyouahaskell.com/)
|
||||||
|
|
||||||
|
|
||||||
|
## [13th of March - Introduction](sessions/13_03/notes.md)
|
||||||
|
|
||||||
|
Big question:
|
||||||
|
|
||||||
|
> Why is the singly-linked list the most common data structure in functional programming?
|
||||||
|
|
||||||
|
Because it is the simplest recursive data structure. It is a recursive data structure because it is defined in terms of itself. It is a singly-linked list because it has a head and a tail. The head is the first element of the list and the tail is the rest of the list.
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="assets/list.png" alt="lists" width="700"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
> But why not a tree?
|
||||||
|
|
||||||
|
The tree is simply too complex. Linked lists are easy.
|
||||||
|
|
BIN
haskell/assets/list.png
Normal file
BIN
haskell/assets/list.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 176 KiB |
BIN
haskell/sessions/13_03/folds.png
Normal file
BIN
haskell/sessions/13_03/folds.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 127 KiB |
132
haskell/sessions/13_03/notes.md
Normal file
132
haskell/sessions/13_03/notes.md
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
|
||||||
|
## Progress report - confidence scale
|
||||||
|
In the first meeting, we went through the structure of my exam on a very surface level.
|
||||||
|
I reached the conclusion that, although I have a vague idea of what the topics are, I don't have a deep understanding of them. All of my knowledge is very superficial.
|
||||||
|
|
||||||
|
Hence, this progress report will be a preamble of each session, where I will list the topics and the corresponding confidence I have in them.
|
||||||
|
|
||||||
|
The scale of my confidence in the topics:
|
||||||
|
1. 😎 - Very confident
|
||||||
|
2. 😊 - Confident
|
||||||
|
3. 😐 - Can solve, no intuition
|
||||||
|
4. 😕 - No idea
|
||||||
|
|
||||||
|
| Topic | Description | Confidence |
|
||||||
|
|-------|-------------|------------|
|
||||||
|
| Signatures | Checking whether the expression types are correct | 😊 |
|
||||||
|
| Programming | Writing code to solve an algorithmic problem | 😐 |
|
||||||
|
| Higher order functions | Demonstrate understanding of higher order functions, usually by chaining them | 😐 |
|
||||||
|
| List comprehensions | Demonstrate understanding of list comprehensions | 😐 |
|
||||||
|
| Recursion/infinite lists | Infinitely generating lists, usually by recursion and/or list comprehensions | 😕 |
|
||||||
|
| ADTs | Algebraic Data Types, usually defining a data type and writing functions that operate on it | 😕 |
|
||||||
|
| Proof on lists | Proving properties of functions that operate on lists | 😕 |
|
||||||
|
| Proof on trees/ADTs | Proving properties of functions that operate on trees or ADTs | 😕 |
|
||||||
|
|
||||||
|
## Basics
|
||||||
|
|
||||||
|
### Signatures
|
||||||
|
|
||||||
|
Example given - the `.` operator a.k.a. $f \circ g = f(g(x))$
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
(.) :: (b -> c) -> (a -> b) -> a -> c
|
||||||
|
f . g = \x -> f (g x)
|
||||||
|
```
|
||||||
|
Why? Because the type of `f` is `b -> c`, the type of `g` is `a -> b`, and the type of `x` is `a`. Hence, the type of the output is `c`.
|
||||||
|
|
||||||
|
|
||||||
|
### Stack and heap
|
||||||
|
**What's the stack?**
|
||||||
|
> The stack is a data structure that stores information about the active subroutines of a computer program. It is used to store the return address of the function, the local variables of the function, and the parameters passed to the function.
|
||||||
|
> This is like CPU registers, but for functions.
|
||||||
|
|
||||||
|
**What's the heap?**
|
||||||
|
> The heap is a region of memory that is not managed automatically for you. This is a large pool of memory from which you can request blocks of memory.
|
||||||
|
> This is like the RAM of the computer.
|
||||||
|
|
||||||
|
**What's the difference between the stack and the heap?**
|
||||||
|
> The stack is used for static memory allocation and the heap is used for dynamic memory allocation, both stored in the computer's RAM.
|
||||||
|
i.e. in C:
|
||||||
|
```c
|
||||||
|
int main() {
|
||||||
|
int x = 5; // Stack
|
||||||
|
int* y = malloc(sizeof(int)); // Heap
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**What's the difference between the stack and the heap in Haskell?**
|
||||||
|
> In Haskell, the stack is used for function calls and the heap is used for storing data.
|
||||||
|
> This is because Haskell is a lazy language, so it doesn't evaluate the function calls immediately. Instead, it stores them in the stack and evaluates them when needed.
|
||||||
|
> The heap is used for storing data because Haskell is a functional language, so it doesn't have mutable variables. Hence, it stores the data in the heap.
|
||||||
|
> This is why Haskell is a pure language.
|
||||||
|
|
||||||
|
|
||||||
|
### Recursion
|
||||||
|
|
||||||
|
Recursion in Haskell is very similar to recursion in other languages. The only difference is that Haskell is a lazy language, so it doesn't evaluate the recursion immediately. Instead, it stores the recursion in the stack and evaluates it when needed.
|
||||||
|
|
||||||
|
Tail recursion is a special case of recursion where the recursive call is the last thing in the function.
|
||||||
|
|
||||||
|
Example of non-tail recursion:
|
||||||
|
```haskell
|
||||||
|
fib :: Int -> Int
|
||||||
|
fib 0 = 0
|
||||||
|
fib 1 = 1
|
||||||
|
fib n = fib (n-1) + fib (n-2)
|
||||||
|
```
|
||||||
|
|
||||||
|
To make the `fib` function tail recursive, we can use an accumulator[^1]
|
||||||
|
```haskell
|
||||||
|
fib :: Int -> Int
|
||||||
|
fib n = go n 0 1
|
||||||
|
where
|
||||||
|
go 0 a b = a
|
||||||
|
go n a b = go (n-1) b (a+b)
|
||||||
|
```
|
||||||
|
|
||||||
|
### `map, foldr, foldl, filter, zip`
|
||||||
|
|
||||||
|
These are higher order functions in Haskell. They are used to operate on lists.
|
||||||
|
|
||||||
|
`map` applies a function to each element of a list.
|
||||||
|
```haskell
|
||||||
|
map :: (a -> b) -> [a] -> [b]
|
||||||
|
map f [] = []
|
||||||
|
map f (x:xs) = f x : map f xs
|
||||||
|
```
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="folds.png" alt="folds" width="700"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
`foldr` is a right fold. It is used to reduce a list to a single value.
|
||||||
|
```haskell
|
||||||
|
foldr :: (a -> b -> b) -> b -> [a] -> b
|
||||||
|
foldr f z [] = z
|
||||||
|
foldr f z (x:xs) = f x (foldr f z xs)
|
||||||
|
```
|
||||||
|
|
||||||
|
`foldl` is a left fold. It is used to reduce a list to a single value.
|
||||||
|
```haskell
|
||||||
|
foldl :: (b -> a -> b) -> b -> [a] -> b
|
||||||
|
foldl f z [] = z
|
||||||
|
foldl f z (x:xs) = foldl f (f z x) xs
|
||||||
|
```
|
||||||
|
|
||||||
|
`filter` is used to filter a list based on a predicate.
|
||||||
|
```haskell
|
||||||
|
filter :: (a -> Bool) -> [a] -> [a]
|
||||||
|
filter p [] = []
|
||||||
|
filter p (x:xs) = if p x then x : filter p xs else filter p xs
|
||||||
|
```
|
||||||
|
|
||||||
|
`zip` is used to combine two lists into a list of tuples.
|
||||||
|
```haskell
|
||||||
|
zip :: [a] -> [b] -> [(a, b)]
|
||||||
|
zip [] _ = []
|
||||||
|
zip _ [] = []
|
||||||
|
zip (x:xs) (y:ys) = (x, y) : zip xs ys
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
[^1]: This is a common pattern in functional programming. The idea is to pass an accumulator to the function and update it in each recursive call. This is to "circumvent" immutability by introducing a way to store the "state" of the function.
|
28
rust/README.md
Normal file
28
rust/README.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<style>
|
||||||
|
/* Invert rust logo */
|
||||||
|
#rust img {
|
||||||
|
filter: invert(1);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<p align = "center">
|
||||||
|
<span id=rust>
|
||||||
|
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/rust/rust-original.svg" alt="Rust" width="200"/>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
# Introduction
|
||||||
|
On my journe to memory safety and due to lots of ridicule from my friends about daily-driving Python, I am currently looking for a systems programming language that is memory safe and has a good ecosystem (i.e. is not hated by everyone). In other words, I am looking for a *practically useful* language that is not Python or C++.
|
||||||
|
|
||||||
|
Rust seems to be the perfect fit for this. This repository will document my journey in learning Rust.
|
||||||
|
|
||||||
|
The process of learning this language is going to be quite different from my other repositories. I will try to design an embedded project in Rust, instead of focusing on algorithmic problems (i.e. practical problems). This will help me understand the language better and also give me a taste of what it is like to work with Rust in a real-world scenario.
|
||||||
|
|
||||||
|
I'm going to try and ***actually document*** my process instead of my usual cheat-sheet style.
|
||||||
|
|
||||||
|
## ToC
|
||||||
|
- [Introduction](#introduction)
|
||||||
|
- [ToC](#toc)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2,6 +2,14 @@
|
|||||||
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/swift/swift-original.svg" alt="Swift" width="250"/>
|
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/swift/swift-original.svg" alt="Swift" width="250"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
# Introduction
|
||||||
|
I watched a Swift lecture by an apple guy at FOSDEM 2025. It was pretty cool. Inspired me to think about memory safety, and, needless to say, learn Swift.
|
||||||
|
|
||||||
|
|
||||||
|
## ToC
|
||||||
|
|
||||||
|
- [Introduction](#introduction)
|
||||||
|
- [ToC](#toc)
|
||||||
- [General Notes](#general-notes)
|
- [General Notes](#general-notes)
|
||||||
- [Swift project](#swift-project)
|
- [Swift project](#swift-project)
|
||||||
- [Package.swift](#packageswift)
|
- [Package.swift](#packageswift)
|
||||||
@ -27,12 +35,11 @@
|
|||||||
- [Project-specific Notes](#project-specific-notes)
|
- [Project-specific Notes](#project-specific-notes)
|
||||||
- [Most likely teammates for Software engineering](#most-likely-teammates-for-software-engineering)
|
- [Most likely teammates for Software engineering](#most-likely-teammates-for-software-engineering)
|
||||||
|
|
||||||
|
|
||||||
# General Notes
|
# General Notes
|
||||||
There are **NO** semicolons in Swift. The language is designed to be concise and readable. Very pythonic in that sense.
|
There are **NO** semicolons in Swift. The language is designed to be concise and readable. Very pythonic in that sense.
|
||||||
|
|
||||||
Swift is a statically-typed language. This means that the type of a variable is known at compile time. This is in contrast to dynamically-typed languages like Python, where the type of a variable is determined at runtime.
|
Swift is a statically-typed language. This means that the type of a variable is known at compile time. This is in contrast to dynamically-typed languages like Python, where the type of a variable is determined at runtime. It deals with memory by using Automatic Reference Counting (ARC). This means that the compiler automatically manages memory for us.
|
||||||
|
|
||||||
Swift deals with memory by using Automatic Reference Counting (ARC). This means that the compiler automatically manages memory for you. This is in contrast to languages like C and C++, where you have to manually manage memory.
|
|
||||||
|
|
||||||
Swift is a multi-paradigm language. This means that it supports multiple programming paradigms, such as object-oriented programming, functional programming, and procedural programming. We'll get into this later.
|
Swift is a multi-paradigm language. This means that it supports multiple programming paradigms, such as object-oriented programming, functional programming, and procedural programming. We'll get into this later.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user