CSE 130 Lecture Notes - Lecture 6: Function Application, Double-Precision Floating-Point Format, Purely Functional Programming

23 views3 pages
26 Jan 2018
School
Course
Professor
Haskell - a typed, lazy, purely functional language
Statically-Typed - determined statically at compile-time
-everything has a type
-everything MUST make sense at compile time!
-unlike JS where undefined functions will NOT complain until you evaluate f(x)
Is JS typed? Yes, but at runtime (dynamically)
Why is this cool?
-Removes overhead! (8 million checks)
- Helps find bugs AHEAD of time (as opposed to @ runtime
- Important for security & safety
- Easier to optimize and write faster code
Functional - functions are first-class
-support for high-order, first-class
-Haskell programs are NOT statements; they are definitions (functions/values)
-meaning of programs centered around:
- evaluating expressions
- NOT executing instructions
Pure - NO side effects
Is JS pure? No - mutation (i++) is a side-effect!
Side-effect free:
- In a scope where x1,..,xn (vars) are defined, ALL occurrences of expression e (where
FV(e) = {x1,...,xn}) have the SAME value
Why is this cool?
- Algebraic laws: equational reasoning & optimizations
- Easier to think about - don’t need to worry if x changed after calling f
- Parallelism - evaluate expressions in parallel
Lazy - called by name
-don’t evaluate expressions unless result is absolutely necessary
Haskell is call by need
- You only evaluate an expression ONCE and cache the result
- Can you cache results in JS? NO (f might mutate! - no way of knowing)
Why is this cool?
- MUCH faster: only evaluate once
- Can define YOUR OWN control structures using functions
- If-then-else WAY easier
- Define infinite data structures (use omega)
Committee Language - unusually popular (most committee languages NEVER take off)
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Notes+

Unlimited access to class notes and textbook notes.

YearlyBest Value
75% OFF
$8 USD/m
Monthly
$30 USD/m
You will be charged $96 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.