Functional programming - standard symbols, diagrams, etc.

I have a problem that I think is best solved with a functional programming style.

Based on a very imperative background, I'm used to programming a design that includes diagrams / class descriptions, connection diagrams, state diagrams, etc. However, these diagrams are implied or used to describe the state of the system and the various side effects that act in the system.

Is there any standardized set of diagrams or mathematical symbols used in the development of functional programs, or those programs that are best designed in a short functional pseudo-code (given that the functions will be much shorter than imperative copies).

Thanks Mike

+6
design functional-programming diagram uml
source share
4 answers

There is a secret trick for functional programming.

  • It is largely stateless, so traditional imperative charts are not relevant.

  • Most of the usual, mathematical designations for garden varieties are also stateless.

Functional design is more like algebra than anything else. You are going to define functions and show that the composition of these functions gives the desired result.

Diagrams are not so necessary because functional programming is somewhat simpler than procedural programming. This is more like regular mathematical notation. Use mathematical methods to show that your various functions do the right thing.

+7
source share

Functional programmers write equations more and then write diagrams. The game is called equational reasoning, and basically it includes

  • Substituting Equals for Equals

  • Application of algebraic laws

  • Induction random proof

The idea is that you write really simple code that is “clearly correct”, then you use equational reasoning to turn it into something cleaner and / or will work better. The master of this art is an Oxford professor named Richard Byrd.

For example, if I want to simplify a schema expression

(append (list x) l) 

I will receive equal equals for equals, like crazy. Using the definition of list , I get

 (append (cons x '()) l) 

Giving the body of the add, I

 (if (null? (cons x '())) l (cons (car (cons x '())) (append (cdr (cons x '())) l))) 

Now I have these algebraic laws:

 (null? (cons ab)) == #f (car (cons ab)) == a (cdr (cons ab)) == b 

and substituting equalities for equals, I get

 (if #f l (cons x (append '() l)) 

With a different law (if #f e1 e2) == e2 I get

 (cons x (append '() l)) 

And if I use the append definition again, I get

 (cons xl) 

which I proved equal

 (append (list x) l) 
+4
source share
+2
source share

I don’t know much about functional programming, but here are two things that I used in

  • λ (lambda) is often used to denote function
  • fog is used to refer to the Composition function.
-one
source share

All Articles