Axioms of functional programming

I study functional programming with Clojure and want to deepen my theoretical understanding of the functional paradigm (and not just the Clojure syntax).

I am looking for axioms or formulas , like every functional method, such as recursion, mapping, reduction, minus, first a-contact, relates to each other, composed of which, and which is the ultimate axiom for everything.

For example, I realized that mapcan only be realized with the use of functions recur, first, restand cons, and, of course, itself a function of the display is transmitted map.

After that, I also realized that it mapcould also be implemented with reduce, and again, the reduction could be implemented with recur, firstand rest. It filtercan also be implemented using reduce.

It seems to me that I am beginning to envelop functional programming, but it is still difficult to understand which of them are the most final building blocks, i.e. minimal set of abstractions or keywords to create an arbitrary function. With the map example, the second method uses one smaller abstraction to achieve the same goal. So, what are some limiting axioms of a functional paradigm to help me see the big picture?

+4
source share
3 answers

From lambda (called fnin clojure), you can get something else. For example, suppose a classic exercise to get cons, firstand restwith fn:

(defn cons [x y]
  (fn [f]
    (f x y)))

(defn first [coll]
  (coll (fn [x y] x)))

(defn rest [coll]
  (coll (fn [x y] y)))

So, if you need a set of axioms for functional programming, then only one: lambda is the ultimate axiom. For more information on how to derive other functions, see the following articles:


, ; , .

, clojure first/rest, , . , cons/first/rest, , , ,

(= x (first (cons x y)))
(= y (rest (cons x y)))

, clojure / , , .

, , :

(defn cons [x y]
  (fn [f]
    (f x y)))

(defn first [coll]
  (coll (fn [x y] x)))

(defn rest [coll]
  (coll (fn [x y] y)))
user> (def integers (cons 0 (cons 1 (cons 2 (cons 3 nil)))))
#'user/integers
user> integers
#object[user$cons$fn__2108 0x3fb178bd "user$cons$fn__2108@3fb178bd"]
user> (first integers)
0
user> (first (rest (rest integers)))
2
+5

, cons tructed , , first rest. , .

, // .., haskell, . , .

, map (a -> b) -> [a] -> [b] : , a b, a, b.

, , fold ( left right), reduce . ,

, , . ( ) recur, map filter take .. recur, reduce ..

+1

, , , , . 3 :

  • P [A] >= 0 A
  • P [ "any event" ] = 1
  • P [A B] = P [A] + P [B], A B

, .

" " . , , 100 "" , 100 . .

, , , , "" . "" , "/".

, : . , . FP , :

, "" "", "" "". , , , , .

, , . , "" , , , .., , "" , , , , .. .

. (), (). - .

2 ( ) .

+1

Source: https://habr.com/ru/post/1676453/


All Articles