Just do It: Simple Monadic Equational Reasoning Jeremy Gibbons and Ralf Hinze, 2011 José Serra Thematic Seminar June 2012.

Slides:



Advertisements
Similar presentations
Find the following Algebra Tiles… Trace each of these Algebra Tiles on your notes. 1 unit x units Area/Name: 1 UNIT TILE 1 unit Area/Name: X TILE Area/Name:
Advertisements

Kathleen Fisher cs242 Reading: “A history of Haskell: Being lazy with class”,A history of Haskell: Being lazy with class Section 6.4 and Section 7 “Monads.
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Functional Programming Notes for CSCE 190 Based on Sebesta,
Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id
CS510AP Quick Check Monads. QuickCheck Quick check is a Haskell library for doing random testing. You can read more about quickcheck at –
4.3 Systems of Equations - Elimination Objective: The student will be able to: Solve systems of equations using elimination with addition and subtraction.
Elimination Using Addition and Subtraction. Solving Systems of Equations So far, we have solved systems using graphing and substitution. Solve the system.
Haskell Chapter 1, Part I. Highly Recommended  Learn you a Haskell for Great Good. Miran Lipovaca.
Haskell Chapter 8. Input and Output  What are I/O actions?  How do I/O actions enable us to do I/O?  When are I/O actions actually performed?
Algebra I: Introduction to Algebra YoungMath and Expert Subjects.com Present.
1 COMP313A Functional Programming (1). 2 Main Differences with Imperative Languages Say more about what is computed as opposed to how Pure functional.
 What is Algebraic Expressions and how do I solve them?
4.8 Writing Equations from Patterns A very useful problem-solving strategy is look for a pattern. When you make a conclusion based on a pattern of examples,
Solving a system of equations by adding or subtracting.
Going Functional Primož Gabrijelčič. Functional programming.
© M. Winter COSC 4P41 – Functional Programming Programming with actions Why is I/O an issue? I/O is a kind of side-effect. Example: Suppose there.
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L13-1 October 26, 2006http:// Monadic Programming October.
Solving Systems of Equations by Elimination (Addition) Section 3.2, Part II.
Solving Literal Equations and Formulas Objectives: I can solve literal equations (formulas) for a specified variable. I can apply these skills to solve.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Interactive Programs: I/O and Monads Dr. Hyunyoung Lee.
First Order Haskell Neil Mitchell York University λ.
Dr. Philip Cannata 1 Programming Languages Chapter 14 – Functional Programming – Lisp.
Algebra 1 / Es, Es, Is Mathematics and Millennials – 6th.
Solving Systems of Equations So far, we have solved systems using graphing and substitution. These notes show how to solve the system algebraically using.
Haskell Introduction CSCE 314 Spring CSCE 314 – Programming Studio Historical Background 1930s: Alonzo Church develops the lambda calculus, a simple.
Objective solve systems of equations using elimination.
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
Elimination Week 17 blog post. Add or subtract In elimination, we have to add or subtract two linear equations to isolate one of the variables. So, the.
Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id
Objective 7.3 To solve systems of equations using elimination with addition and subtraction.
Functional Programming
COSC 5V90 Functional Programming and Interactive Theorem Proving
Objective I can solve systems of equations using elimination with addition and subtraction.
Slope Intercept Form Algebra
STANDARD EQUATION OF A LINE: Ax + By = C
YoungMath and Expert Subjects.com Present
The student will be able to:
CS4450: Principles of Programming Languages
Query Execution Presented by Khadke, Suvarna CS 257
Conic Sections: Ellipses
Equations With Variables on Both Sides
3-5 Solving Equations and Formulas
3-5 Solving Equations and Formulas
Simultaneous Equations
3-5 Solving Equations and Formulas
The student will be able to:
The student will be able to:
The student will be able to:
Solving Systems of Equations
Query Execution Presented by Jiten Oswal CS 257 Chapter 15
CS 457/557: Functional Languages Folds
Point-Slope Form and Writing Linear Equations
How do you determine if a function is linear or non linear
The student will be able to:
The student will be able to:
Solving Systems of Equations
Programming Languages
The student will be able to:
Chapter 15 Functional Programming 6/1/2019.
Simultaneous Equations
The student will be able to:
Step 1: Put the equations in Standard Form. Standard Form: Ax + By = C
Advanced Functional Programming
Presentation transcript:

Just do It: Simple Monadic Equational Reasoning Jeremy Gibbons and Ralf Hinze, 2011 José Serra Thematic Seminar June 2012

Index Functional programming Monads Non Determinism Exceptions Stateful Computations Probabilistic Computations Conclusions

Functional programming Imperative languages – States and mutable data – Side effects – No referential transparency Functional Programming – Based on the application of mathematical functions – No side effects – Referential transparency

Monads Extends functionalities of functional programming: – I/O – Non-determinism – Variable assignment – Exceptions – Parsing – ….

Monads Two basic operations – Return return :: a→m a – Bind (>>=) ::m a→(a→m b)→m b Another one – Sequencing (>>) :: m a→m b→m b

Monads Required to satisfy 3 axioms return x >>=k = k x mx>>=return = mx (mx>>=k) >>=k’ = mx>>=(λx→k x>>=k’)

Monads Do operator do {e} = e do {e ; es} = e >> do {es} do {x←e ; es} = e >>=λx→do {es}

Extending Monads Non-determinism – Returns a possible answer fail ::m a fail >>m = fail – Permutation of a list – Get an element of a list – ….

Extending Monads Non-determinism select :: MonadNondet m ⇒ [a]→m (a, [a]) select [ ] =fail select (x : xs) = return (x, xs) (++) do {(y,ys)←select xs ; return (y, x : ys)}

Extending Monads Exceptions catch ::m a→m a→m a catch fail h = h catch m fail = m catch m (catch h h) = catch (catch m h) h E.g. catch (return (product xs)) (return 0)

Extending Monads Stateful computations – Add state -> functions depend not only on the parameters but on the state A S δ B S’ class Monad m ⇒ MonadState s m | m→s where get ::m s put :: s→m ()

Extending Monads Probabilistic computations class Monad m ⇒ MonadProb m where choice :: Prob→m a→m a→m a mx 0 my = my mx 1 my = mx (mx p my) >>=k = (mx>>=k) p (my>>=k) – E.g. uniform :: MonadProb m ⇒ [a]→m a uniform [x] =return x uniform (x : xs) = return x 1/length (x:xs) uniform xs

Conclusions Extended the basic definition of Monads based on na algebraic specification capturing its operations and equationsto acount to: – Non Determinism – Exceptions – Stateful Computations – Probabilistic Computations

Thank you. Questions? Monads?