CSci 450/503: Programming Languages

Primary Programming Paradigms

H. Conrad Cunningham

24 August 2017

Acknowledgements: These slides accompany section 1.3, “Primary Programming Paradigms” from Chapter 1 “Fundamental Concepts” of “Introduction to Functional Programming Using Haskell”.

Advisory: The HTML version of this document may require use of a browser that supports the display of MathML. A good choice as of August 2017 is a recent version of Firefox from Mozilla.

Primary Programming Paradigms

Programming Paradigm

Timothy A. Budd. Multiparadigm Programming in Leda, Addison-Wesley, 1995, page 3:

"a way of conceptualizing what it means to perform computation, of
structuring and organizing how tasks are to be carried out on a
computer."

Primary Paradigms

Imperative Paradigm (1)

Imperative Paradigm (2)

    int count =  0;
    int maxc  = 10;
    while (count <= maxc) {
        System.out.println(count) ;
        count = count + 1
    }

Imperative Paradigm (3)

    int count =  0;
    int maxc  = 10;
    while (count <= maxc) {
        System.out.println(count) ;
        count = count + 1
    }

Imperative Paradigm (4)

    int count =  0;
    int maxc  = 10;
    while (count <= maxc) {
        System.out.println(count) ;
        count = count + 1
    }

Imperative Paradigm (5)

Declarative Paradigm (1)

Declarative Paradigm (2)

Functional Paradigm (1)

Functional Paradigm (2)

    counter :: Int -> Int -> String 
    counter count maxc 
        | count <= maxc = show count ++ "\n" ++ counter (count+1) maxc 
        | otherwise     = ""

Functional Paradigm (3)

    counter :: Int -> Int -> String 
    counter count maxc 
        | count <= maxc = show count ++ "\n" ++ counter (count+1) maxc 
        | otherwise     = ""

Functional Paradigm (4)

Functional Paradigm (5)

Relational (or Logic) Paradigm (1)

Relational (or Logic) Paradigm (2)

    counter(X,Y,S) :- count(X,Y,R), atomics_to_string(R,'\n',S).

    count(X,X,[X]). 
    count(X,Y,[])     :- X  > Y. 
    count(X,Y,[X|Rs]) :- X < Y, NX is X+1, count(NX,Y,Rs).

Relational (or Logic) Paradigm (3)

    counter(X,Y,S) :- count(X,Y,R), atomics_to_string(R,'\n',S).

    count(X,X,[X]). 
    count(X,Y,[])     :- X  > Y. 
    count(X,Y,[X|Rs]) :- X < Y, NX is X+1, count(NX,Y,Rs).

Relational (or Logic) Paradigm (4)