Learning to Code // a better name is a WIP.

possibly: How to work from anywhere / pants optional!

I am assuming that by teaching someone else (you) that I will also be learning. Lernen durch Lehren is a fancy french term for this process.

What the heck is this?

This is a Jupyter Notebook. It is the evolution of IPython notebook project. It is used primarily for Data-science. You will be able to run your own code an correct all the typos you find.

We will be learning Haskell as your first language. Haskell is kind of the grand daddy of the ML (not machine-learning) family of programming languages. The IHaskell kernel allows us to use a subset of Haskell in the notebook.

The help menu items above gives you all the info you need to start using notebooks.

In [1]:
-- this is a code cell- see the In []: to the left.
-- text or comments must start with 'dash-dash' 
-- comments like these are ignored by the compiler.
-- to evaluate the code below "Hello..." select this cell by clicking 
-- inside this gray area.
-- now hold down the **ctrl** key and hit the **enter** key.

"Hello from IHaskell"   -- this line of code should run.    

--try it

"Hello from IHaskell"

OK- great here is your next task

  1. in the empty cell below
  2. enter 40 + 2 or any other simple math thing you would like
  3. then evaluate it with 'Ctrl+Enter'
  4. for some reason programmers like the number 42.

In [ ]:

This is little more interesting...

Lets define the Fibonacci sequence

i think we're ready!

In [ ]:
import Data.Char   --only need the print SWEET!

fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)

-- notice how the function name 'fib' is used in defining the function.

"The fibonacci of 20 is..."  

fib 20     -- this will run the function

IHaskellPrelude.map Data.Char.toUpper "sweeet!" 

-- select the cell by clicking it and then Ctrl+Enter to run it.
Find another example of Fibonacci numbers and run it below.

In [ ]:
-- my fib function:
Lets look at a *type*

In [ ]:
:type fib   -- evaluate this the same way here.   
            -- lets see what a type definition looks like.

The Haskell programming language in based on lambda calculus.

It is a typed lambda calculus.

Types are quite important.

Here is a little deep shit stuff.

Type inference (the compiler infers the types for you) is done by the compiler by following simple typing rules.

This one is for function application.

It states that if f is a function that maps arguments of type A to results of type B , and e is an expression of type A , then the application f.e has type B :

$\frac{f\ ::\ A\ \rightarrow\ B\ \quad e\ ::\ A}{f\ e\ ::\ B}$


Functional programming is writing expressions that include values and can be applied to arguments and reduced into a new value.

All functions take just one argument and return one result. That result can also be another function. This is called currying.

Functions are a mapping of inputs to outputs. And they will ALWAYS return the same output/ given the same inputs. /not the case for all programming languages.

Haskell is a typed lambda calculus.

Haskell is named after Haskell Curry

In [3]:
let myNum = 1 :: Integer
let myVal f = f + myNum

:t myVal
:t myNum

myVal :: Integer -> Integer
myNum :: Integer