So You Want to be a Functional Programmer (Part 5)

Referential Transparency

y = x + 10
x = 3
y = 3 + 10
quote str =
"'" ++ str ++ "'"
findError key =
"Unable to find " ++ (quote key)
findError key =
"Unable to find " ++ ("'" ++ str ++ "'")

Execution Order

1. Get out the bread
2. Put 2 slices into the toaster
3. Select darkness
4. Push down the lever
5. Wait for toast to pop up
6. Remove toast
7. Get out the butter
8. Get a butter knife
9. Butter toast
Thread 1
--------
1. Get out the bread
2. Put 2 slices into the toaster
3. Select darkness
4. Push down the lever
5. Wait for toast to pop up
6. Remove toast
Thread 2
--------
1. Get out the butter
2. Get a butter knife
3. Wait for Thread 1 to complete
4. Butter toast
buildMessage message value =
let
upperMessage =
String.toUpper message
quotedValue =
"'" ++ value ++ "'"
in
upperMessage ++ ": " ++ quotedValue

Type Annotations

public static String quote(String str) {
return "'" + str + "'";
}
private final Map<Integer, String> getPerson(Map<String, String> people, Integer personId) {
// ...
}
var getPerson = function(people, personId) {
// ...
};
add : Int -> Int -> Int
add x y =
x + y
add : Int -> (Int -> Int)
doSomething : String -> (Int -> (String -> String))
doSomething prefix value suffix =
prefix ++ (toString value) ++ suffix
doSomething : String -> Int -> String -> String
takes2Params : Int -> Int -> String
takes2Params num1 num2 =
-- do something
takes1Param : (Int -> Int) -> String
takes1Param f =
-- do something
map : (a -> b) -> List a -> List b
map f list =
// ...
(Int -> String) -> List Int -> List String

My Brain!!!!

--

--

Software Engineer and Architect, Teacher, Writer, Filmmaker, Photographer, Artist…

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Charles Scalfani

Charles Scalfani

24K Followers

Software Engineer and Architect, Teacher, Writer, Filmmaker, Photographer, Artist…