Functional Programming Principles: Difference between revisions
Jump to navigation
Jump to search
Adamcolton (talk | contribs) |
Adamcolton (talk | contribs) |
||
| Line 17: | Line 17: | ||
call-by-name vs call-by-value. | call-by-name vs call-by-value. | ||
CBV evaluates all values first, CBN does substitution first. | CBV evaluates all values first, CBN does substitution first. | ||
From the next lesson, a good example | |||
def and(x:Boolean, y: =>Boolean): if (x) y else false | |||
Now if we call and(false, loop) where loop is an infinite loop, it will not evaluate the second argument. If we were to write it as | |||
def and(x:Boolean, y:Boolean): if (x) y else false | |||
then it would try to evaluate the second arg and would loop forever. | |||
==== Evaluation Strategies and Termination ==== | ==== Evaluation Strategies and Termination ==== | ||
Revision as of 15:21, 15 September 2014
Video Lectors
Getting Started
Tutorial: Working on Assignments
Using Eclipse and SBT
Working from scala repl
InelliJ IDEA
Week 1: Functions & Evaluations
Programming Paradigms
Programming languages are tightly coupled with the Von Neumann architecture. Functional programming is a way to decouple this dependency. It's also good for scalable computing.
Elements of Programming
SBT: scala build tool
call-by-name vs call-by-value. CBV evaluates all values first, CBN does substitution first.
From the next lesson, a good example
def and(x:Boolean, y: =>Boolean): if (x) y else false
Now if we call and(false, loop) where loop is an infinite loop, it will not evaluate the second argument. If we were to write it as
def and(x:Boolean, y:Boolean): if (x) y else false
then it would try to evaluate the second arg and would loop forever.
Evaluation Strategies and Termination
CBV termination → CBN termination but CBN termination !→ CBV termination
Scala uses CBV but you can force CBN with =>
Conditionals and Value Definitions
if (a) b else c
but it's more like ternary.