Functional Programming IN NON-FUNCTIONAL LANGUAGES.

Slides:



Advertisements
Similar presentations
Introduction to Compilation of Functional Languages Wanhe Zhang Computing and Software Department McMaster University 16 th, March, 2004.
Advertisements

Introduction to OCaml Slides prepared by Matt Gruskin Some material borrowed from the CIS 500 lecture notes.
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Programming Languages and Paradigms
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
Evis Trandafili Polytechnic University of Tirana Albania Functional Programming Languages 1.
MATHEMATICAL FOUNDATIONS SUPPLEMENTAL MATERIAL – NOT ON EXAM.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Programming Language Paradigms: summary. Object-oriented programming Objects are the fundamental building blocks of a program. Interaction is structured.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
Programming Language Theory Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
Chapter 4: Language Semantics The need for language semantics: a. for the programmer - to know how to use language constructs b. for the implementor -
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Multilisp: Concurrent Functional Programming Ed Walters and Tim Richards University.
Interlude: Functional Programming CSE 331 Section 2 James Daly.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Functional Programing Referencing material from Programming Language Pragmatics – Third Edition – by Michael L. Scott Andy Balaam (Youtube.com/user/ajbalaam)
Haskell Chapter 1, Part I. Highly Recommended  Learn you a Haskell for Great Good. Miran Lipovaca.
Principles of Programming Languages Lecture 1 Slides by Yaron Gonen, based on slides by Daniel Deutch and lecture notes by Prof. Mira Balaban.
Principles of Programming Languages Lecture 1 Slides by Daniel Deutch, based on lecture notes by Prof. Mira Balaban.
1 Programming Language History and Evolution In Text: Chapter 2.
Dan Johnson.  Functional language that started development in  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after.
Robert Vitolo CS474.  Branched off of ML (metalanguage)  Developed at Microsoft, available as part of the Visual Studio 2010 software package, integrated.
Going Functional Primož Gabrijelčič. Functional programming.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
Principles of Programming Languages Lecture 1 Slides by Yaron Gonen, based on slides by Daniel Deutch and lecture notes by Prof. Mira Balaban.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
CS162 Week 1 Kyle Dewey. Overview Basic Introduction CS Accounts Scala survival guide.
CS50 Week 9 Sam Green ’
Monads. foo1 Method to print a string, then return its length: scala> def foo1(bar: String) = { | println(bar) | bar.size | } foo1: (bar: String)Int scala>
Methods Methods are how we implement actions – actions that objects can do, or actions that can be done to objects. In Alice, we have methods such as move,
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Java8 Released: March 18, Lambda Expressions.
Python Basics  Functions  Loops  Recursion. Built-in functions >>> type (32) >>> int(‘32’) 32  From math >>>import math >>> degrees = 45 >>> radians.
CMSC 330: Organization of Programming Languages Operational Semantics.
Swing Threading Nested Classes COMP 401 Fall 2014 Lecture 23 11/25/2014.
Haskell Introduction CSCE 314 Spring CSCE 314 – Programming Studio Historical Background 1930s: Alonzo Church develops the lambda calculus, a simple.
An Introduction to F# Sushant aboutdev.com
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Principles of Programming Languages Lecture 1 Slides by Yaron Gonen, based on slides by Daniel Deutch and lecture notes by Prof. Mira Balaban.
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
1 Introduction to Functional Programming in Racket CS 270 Math Foundations of CS Jeremy Johnson.
Introduction to Concepts in Functional Programming CS16: Introduction to Data Structures & Algorithms Thursday, April 9,
Lambda Functions & Closures A Sydney PHP Group Presentation 2 nd October 2008 By Timothy Chandler.
Introduction to Functional Programming Part 1 – The Basic Concepts Winter Young
Programming Paradigms, Software Architectural Patterns, and MVC CS 378 – Mobile Computing for iOS Dr. William C. Bulko.
Functional Programming
Programming Language History and Evolution
Functional Programming
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Functional Programming
Principles of programming languages 4: Parameter passing, Scope rules
Programming Language History and Evolution
Introduction to Functional Programming in Racket
Functional Programming with Java
Fundamentals of Functional Programming Languages
Main Points of Haskell Functional programming Laziness
Object Oriented Practices
Chap. 6 :: Control Flow Michael L. Scott.
1.2 Key Concepts and Walkthroughs
Procedural vs Functional Style
Chap. 6 :: Control Flow Michael L. Scott.
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 12/25/2018.
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
Introduction to Functional Programming in Racket
Threads and concurrency / Safety
Presentation transcript:

Functional Programming IN NON-FUNCTIONAL LANGUAGES

What is functional programming? In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state.[1] Functional programming has its roots in lambda calculus, a formal system developed in the 1930s to investigate computability, the Entscheidungsproblem, function definition, function application, and recursion. Many functional programming languages can be viewed as elaborations on the lambda calculus. – Wikipedia: Functional programming (

TL;DR – Give me the Cliffs Notes  First-class functions  Functions are not treated any different than any other named thing  Can be passed as argument and returned as a result  Pure functions  No side effects  Results are constant given the same input  Evaluation is always thread safe and order is never important  Recursion  looping is often done via recursion  Recursion is safe and optimized by the compiler  Type system  Types are inferred  Data always has a type  Pattern matching on complex types

But I can’t/don’t/won’t use a functional language  What should I use to get started?  Java -> Scala .NET -> F#  JavaScript Use the principles of functional programming in non-functional languages

The principles  Don’t make setters in your class definitions – instead, make your fields constant and defined in the constructor. Then you can expose them as public.  Avoid side effects. Treat your memory as immutable.  Always make pure functions - Your function is like a math function. It doesn’t care about the state of the environment. Given the same input, it always produces the same output. Everything it needs is passed in.  Many languages have implemented some functional principles although the syntax remains imperative  Java 8 will support lambda expressions – anonymous functions  JavaScript, PHP 5.3, VB 9, C# 3, C++ 11 have first-class functions, lambda expressions  JavaScript has a functional, expressive syntax  Asynchronous for-each loops

Questions?