CS代写 COMP1811 Paradigms of Programming

COMP1811 Paradigms of Programming
Some notes about Side Effects and FP
Mutability, State, Sequencing, I/O

Copyright By PowCoder代写 加微信 powcoder

• These notes may sound a bit weird.
• You don’t need to understand them to use (program) well.
“Young man, in mathematics you don’t understand things. You just get used to them” (John von Neumann)
• However…
“Any fool can know. The point is to understand” ( )

• Plato and Aristotle: two visions of reality.
• The functional approach.
– Benefits for Software Eng.
• Injection of mutable entities: Side effects.
– Consequences for Software Eng.
• APPENDIX: Can be the realm of ideas be restored? – Monad Concept.

• Plato’s doctrine:
– Immutable entities.
– The Realm of Ideas.
– Static, eternal, forever.
• Aristotle’s thought:
– Mutable entities.
– Substance vs. accident
– Dynamic, evolving, temporary.
Plato and Aristotle
Two visions of “reality”

• Immutableworld – values/symbols
• (non variables) – Referential
transparency
• (same input, same output)
– Order of parameters evaluation irrelevant
Functional approach

• Referential Transparency – Software update.
• Inefficient modules to be easily replaced by efficient ones. – Easier reasoning
• Softwarealwaysreactsthesameway.
• Irrelevant order.
– Computation can be speed-up by parallel computing.
Functional approach
Benefits for Software Eng.

• Mutable world:
– Symbols become variables.
– Changing contents:
• File system.
• Data Bases.
– End user input at will:
• Screen, keyboard, mouse • Networking
Apparently, mutable world funnier but…
Injection of mutable entities
Side effects

Referential Transparency broken!
Cannot replace so easy software modules
Order matters
Sequencing prevents parallel
Harder to certify soundness
Software do not behave as always (crash, reboot system…)
Injection of mutable entities
Consequences for Software

• Scheme, as dialect of Lisp (1960’s) accepts mutable symbols, hence side-effects.
• The programmer must be very aware of them.
• That is the topic of next lecture. – set!
– input/output, ports… – for-each…
Scheme language

Is there a way to combine the indulgences of impurity with the blessings of purity? ( )
• Category theory (1940’s Lane) – Abstract: The mathematics of mathematics.
• Monads :
– A recurrent pattern in computation
– Formalized and rigorously stated in Category Theory
– A functional language supporting the concept of monad
Can the realm of ideas be restored?
The monad concept

Bibliography
Further reading
• Monads for functional programming ( )
• Cakes, custard + Category Theory ( )

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com