(no title)
0xFF69B4 | 4 years ago
# milk_cows :: Person -> Tired Person
def milk_cows(person):
...
person["tired"] = True
return person
# feed_pigs :: Person -> Tired Person
def feed_pigs(person):
...
person["tired"] = True
return person
# birthday :: Person -> Person
def birthday(person):
person["age"] += 1
return person
# willy :: Person
willy = {"age": 32, "tired": False}
# fmap and >>=
print(milk_cows(birthday(feed_pigs(willy))))
In Haskell there would be a 'Tired a' type with a Monad instance to express the tiredness property and a Functor instance to apply functions to it with no impact on or knowledge of tiredness, e.g. aging.
No comments yet.