Reduce code complexity

Increase program efficiency when dealing with large datasets (lazy evaluation)

Simplest Turing-Complete Programming Language EVER!

variables all single-letters a...z

defining functions: λ<arguments>.<output>

Using functions: λx.xy applies identity function to y

λx.xy → y

Expressions evaluated left-to-right

Variable Types:

Bound: part of function definitions, can be replaced by any letter

Free: function input

in λx.xy, x is bound and y is free (λx.xy = λt.ty)

**and how Lambdaλ Calculus will explode your brain**

**Haskell: Functional Programming**

λ Calculus

Declaring Functions

Haskell - Syntax

Haskell in the real world - QuickSort

Only 2 keywords: lambda and "."

See the alligator-and-egg paradigm at: http://worrydream.com/AlligatorEggs/

λx.x is the identity function

The Basics

Data: Numbers and Booleans

Numbers defined recursively:

1 = λxy.x(y)

2 = λxy.x(x(y))

3 = λxy.x(x(x(y)))

Booleans:

True = λxy.x

False = λxy.y

Church Numerals

Data Structures:

Array: λx.xab

"a" holds first element

"b" holds the rest

Recursive

Working With Data

Increment Function

λwyx.y(wyx)

1. λwyx.y(wyx)(λuv.uuv)

Example:

Multiplication Function

Exponential Function

λxyz.x(yz)

2

No free variables

2. λyx.y((λuv.uuv)yx)

3. λyx.y(yyx)

4. λyx.yyyx = 3

λxy.yx

AND

λxy.xy(λst.t)

OR

λxy.x(λst.s)y

Example:

1. (λxy.xy(λst.t))(λpq.q)(λst.s)

T

F

2. ((λpq.q)(λst.s)(λst.t))

3. (λst.t) = F

NOT

λx.x(λpq.q)(λab.a)

Syntactic Sugar

Function Header

Return statement

Java:

Haskell:

No variables!

No loops!

Using Functions

Function

Argument

Dollar Symbol

Error

: Print thinks its being given two arguments, but it can only handle one

=

Expressions within parenthesis evaluated before being passed to print (Output: "7.2")

All content after $ evaluated first

Converts prefix function to infix

funcName arg1 arg2 == arg1 `funcName` arg2

Grave Accent (`)

Programming Shortcuts that make life easier

Static Typing

Polymorphism

Haskell Features

“polymorphically statically typed, lazy, purely functional language.”

Lazy Evaluation

Expressions are not executed until they are needed

What it is

Advantages

Doesn't execute unnecessary code - increased efficiency

Allows creation of infinite data structures

Full data structure not stored in memory, elements stored when needed

Completes in a matter of picoseconds

...as opposed to dynamic typing

Variable (or function) data types determined at compile-time

Prevents runtime bugs

Catch bugs before releasing to public

Fewer patches needed

Compiler knows exactly how much storage to allocate for each piece of data

efficient

Java also features static typing: Int x = 5

It's a fairly common feature...

Haskell methods do not need to specify input types

let's modify our previous sumMeth function:

Parametric

works with all data types for which + is defined (Ints, Doubles, etc.)

Does same thing, regardless of input type

Ad-Hoc

Similar to Java's method overloading

Does different things, depending on input type

C - 24 lines

Haskell - 6 lines

Haskell - 3 lines

Super elegant coding!

Syntactic Sugar - List Comprehensions

Tradeoff:

Increased readability

Slightlyless efficient code

Haskell in the real world - Base Conversion

recursively applies lambda function to the elements of ds

'n' is updated to the running sum (starts at 0)

'k' is the next element of the list

See "out of the tar pit"

Conclusion:

Haskell: Conclusions

Pros

Con

Decreases program efficiency in some cases, but not by a significant amnt

Haskell is capable of creating much more professional, elegant, and comprehensible solutions to many Computer Science problems, albeit at a slight efficiency cost. However, in today's GHz-processor world, micro-optimization techniques are diminishing in importance. In addition, as this modern technology leads to the creation of increasingly complex software, having manageable, comprehensible code is becoming a much higher priority.