Send the link below via email or IMCopy
Present to your audienceStart remote presentation
- Invited audience members will follow you as you navigate and present
- People invited to a presentation do not need a Prezi account
- This link expires 10 minutes after you close the presentation
- A maximum of 30 users can follow your presentation
- Learn more about this feature in our knowledge base article
Do you really want to delete this prezi?
Neither you, nor the coeditors you shared it with will be able to recover it again.
Make your likes visible on Facebook?
Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.
Transcript of Haskell
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
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
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
Data: Numbers and Booleans
Numbers defined recursively:
1 = λxy.x(y)
2 = λxy.x(x(y))
3 = λxy.x(x(x(y)))
True = λxy.x
False = λxy.y
"a" holds first element
"b" holds the rest
Working With Data
No free variables
4. λyx.yyyx = 3
3. (λst.t) = F
: 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
“polymorphically statically typed, lazy, purely functional language.”
Expressions are not executed until they are needed
What it is
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
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:
works with all data types for which + is defined (Ints, Doubles, etc.)
Does same thing, regardless of input type
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
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"
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.