About Me Sushant Bhatia, From India/Malawi, Work at Citation Technologies Inc, an Environmental Health & Safety company with Compliance
|
|
- Byron Grant
- 6 years ago
- Views:
Transcription
1 About Me Sushant Bhatia, From India/Malawi, Work at Citation Technologies Inc, an Environmental Health & Safety company with Compliance Why I chose to do this talk No one else was doing functional programming. I wanted to learn F#. Just started a few weeks ago. 1
2 Functional programming is essential to know Being added to C# and.net (generics, lambdas) Useful for developing at a higher level. Add to your tool belt Fun 2
3 Raffle at the end 3
4 Open VS 2011 VB Programmers? You just got Iterators, Call hierarchy & Global with.net 4.5 New Project & talk about 3 different project types Create F# Application (Property change from Client Profile to full blown profile) Add a New Item Signature File describes namespace, modules, types & members in corresponding implementation file Add a new.fs file Show UP / DOWN of file order. Compilation order = type inference Remove added.fs file Demo Hello World let msg = Hello World Build Run -> Nothing happens ENTER) Talk about F# Interactive (REPL Read Evaluate Print Loop) (ALT + 4
5 Type msg;; in Interactive Add print %s msg Run app (F5) Clear Demo Hello World 2 open System Console.WriteLine Hello World (F5) clear Talk about let and how F# values are immutable F# is case sensitive & whitespace matters Comments -> //, ///, (* *) Demo Greatest Common Denominator let rec gcd x y = if y = 0 then x else gcd y (x % y) Hover over gcd defintion to show inference occurs printfn "%i" (gcd 100 6) clear Demo Other things in F# int, float, BigInt (I) 2 + 2;; shows val it : int = 4 (this is an unnamed expression) let my x = if x > 5 then printfn "Cool!" else let db = "Something" printfn "%i %s" x db () clear 4
6 5
7 Unit is a concrete representation of void Ignore function swallows a functions return value Tuples provide a convenient way to return multiple values from a function Tuples fst, snd to get values from a tuple. Can also bind as such let mytuple = (1, 2, 3) let x, y, z = mytuple let divrem a b = let x = a / b let y = a % b (x, y) let s = divrem 10 2 Lists Cons (:: ) adds to head of list, append (@) joins two lists List ranges created [1.. 10], [ ] List comprehension use yield statement within [ and ] Option represents a value that may or may not exist let resolve x = match x with 6
8 Option.None -> "Zero" Option.Some(30) -> "What what what" _ -> "Meh" // try 6 and 633 let istherea5 = List.tryFind (fun x -> x%633 = 0) [ ] > resolve 6
9 For multi file projects, code must be organized into modules or namespaces Create a second fs file. Program.fs namespace Widgets module Program = let Sqr x = x * x module NotMath = let Name = "Sushant Bhatia" type Suit = Club Diamond Heart Spade Octagon File1.fs 7
10 module File1 let result x = Widgets.Program.Sqr x > printfn "%A" printfn "%s" Widgets.Program.NotMath.Name result 5; let mycardtype = Widgets.Suit.Club let getmatch cardtype = match cardtype with Widgets.Club -> "Its a club" Widgets.Diamond -> "its a diamond" Widgets.Heart -> "Its a heart" Widgets.Spade -> "Its a spade" _ -> "Its a what? Cheater!" (getmatch mycardtype) > printfn "%s" Namespaces cannot directly contain values and functions. Values and functions must be included in modules, and modules are included in namespaces. Namespaces can contain types, modules. 7
11 DEMO Forward composition operator joins functions together let sqr (x : int) = x * x let tostring (x : int) = x.tostring() let strlen (x : string) = x.length let lenofsqr = sqr >> tostring >> strlen sqr 100 lenofsqr 100 There is also a Pipe Backward (< ) and backward composition (<<) operator 8
12 Rules are checked in the order they are declared. NoMatch -> MatchFailureException Compiler will issue warning when matches are missing SEE DEMO FROM Module & Namespace 9
13 SEE DEMO FROM Module & Namespace DEMO BINARY TREES type BinaryTree = Node of int * BinaryTree * BinaryTree Empty let rec printinorder tree = match tree with Node (data, left, right) -> printinorder left printfn "Node %d" data printinorder right Empty -> () (* 2 / \ 1 4 / \
14 *) let example = Node(2, Node(1, Empty, Empty), Node(4, Node(3, Empty, Empty), Node(5, Empty, Empty) ) ) printinorder example 10
15 11
16 Program is a description of a specific computation Ignore how & focus on what Program is a black box for obtaining output from input Program is like a function 12
17 Originated with Lambda calculus = formal system developed in 1930s investigate function definition, application & recursion 13
18 Still quite complex so lets break it down 14
19 15
20 Treat functions as first class objects. 16
21 17
22 An expression is said to be referentially transparent if it can be replaced with its value without changing the behavior of a program. Memoization is optimization by having function calls avoid repeating the calculations of results for previously processed inputs. DEMO: Memoization open System let sqr i : int = i * i let memoize f = let cache = ref Map.empty fun x -> match (!cache).tryfind(x) with Some res -> res None -> let res = f x cache := (!cache).add(x,res) res let memoizedappend = 18
23 memoize (fun input -> printfn "Working out the value for '%A'" input String.concat ", " [ for i in 0.. input -> sprintf "%d: %i" i (sqr i) ]) Console.WriteLine(memoizedAppend(10)) Console.WriteLine("\r\n----\r\n") Console.WriteLine(memoizedAppend(10)) Console.WriteLine("\r\n----\r\n") Console.WriteLine(memoizedAppend(5)) Console.WriteLine("\r\n----\r\n") Console.WriteLine(memoizedAppend(10)) 18
24 Using recursion can be expensive for large numbers of iterations due to declaring the stack over and over. Process is terminated due to StackOverflowException. For this purpose, know when to use Tail Recursion Tail calls drop the current stack frame before making the recursive call. Thus function will execute faster, indefinitely and no stackoverflowexception. The CLR has an IL instruction specifically to help with tail recursion: the tail. IL prefix. The tail. instruction tells the CLR it can discard the caller s method state prior to making the associated call. DEMO: Fibonacci let rec fib n = if n < 2I then 1I else fib (n-2i) + fib(n-1i) let fibtail = Seq.unfold (fun (x, y) -> Some(x, (y, x+y)) ) (0I,1I) fibtail > Seq.nth
25 Currying transforms a function that has more than 1 parameter into a series of embedded functions each with 1 parameter. Can only curry parameters from left to right DEMO: sizeofdir open System.IO let sizeofdir folder pattern = let getfiles folder = Directory.GetFiles(folder, pattern, SearchOption.AllDirectories) let totalsize = folder > getfiles > Array.map (fun file -> new FileInfo(file)) > Array.map (fun info -> info.length) > Array.sum totalsize let DellFolder = sizeofdir "C:\\DELL" DellFolder "*.txt" 20
26 DEMO: Netflix open System.Data.Services.Client open Microsoft.FSharp.Data.TypeProviders // Use the OData type provider to access the Netflix catalog. [<Generate>] type Catalog = ODataService<" let netflix = Catalog.GetDataContext() // Query Netflix for all titles containing the word "Avatar" let titles = query { for t in netflix.titles do where (t.name.contains "naruto") } titles > Seq.iter (fun i -> printfn "%A - %s %i" i.id i.name i.awards.count) 21
27 Console.WriteLine(memoizedAppend(10)) Console.WriteLine("\r\n----\r\n") Console.WriteLine(memoizedAppend(10)) Console.WriteLine("\r\n----\r\n") Console.WriteLine(memoizedAppend(5)) Console.WriteLine("\r\n----\r\n") Console.WriteLine(memoizedAppend(10)) DEMO: Units of Measure [<Measure>] type kg [<Measure>] type s [<Measure>] type m [<Measure>] type N = (kg * m)/(s^2) let gravityonearth = 9.81<m/(s^2)> let dropheight = <m> let impactspeed = sqrt(2.0 * gravityonearth * dropheight) let force :float<n> = 80.0<kg> * gravityonearth DEMO ASYNC open System open System.Net open System.Text.RegularExpressions let websites = [" " " let regtitle = new Regex(@"\<title\>([^\<]+)\</title\>") let WriteLinePageTitle result = printfn "%A" (regtitle.match result).groups.[0].value let AsyncIntroSingle website = async { let client = new WebClient() let! result = client.asyncdownloadstring(uri(website)) 21
28 do WriteLinePageTitle result } > Async.StartImmediate websites > List.iter (fun x -> AsyncIntroSingle x) 21
29 //If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. //Find the sum of all the multiples of 3 or 5 below let lst = [ ] > List.filter (fun x -> x%3 = 0 x%5 = 0) > List.sum //Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: // 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,... //By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. let fibtail = Seq.unfold (fun (x, y) -> Some(x, (y, x+y)) ) (0I,1I) let problem2 = fibtail > Seq.takeWhile (fun x -> x < I) > Seq.sumBy (fun x -> if x%2i = 0I then x else 0I) 22
30 Read Practice Solve real world problems with it 23
31 24
Introduction to OCaml
Introduction to OCaml Jed Liu Department of Computer Science Cornell University CS 6110 Lecture 26 January 2009 Based on CS 3110 course notes and an SML tutorial by Mike George Jed Liu Introduction to
More informationFunctional Programming. Pure Functional Programming
Functional Programming With examples in F# Pure Functional Programming Functional programming involves evaluating expressions rather than executing commands. Computation is largely performed by applying
More informationProgramming Paradigms
PP 2017/18 Unit 12 Functions and Data Types in Haskell 1/45 Programming Paradigms Unit 12 Functions and Data Types in Haskell J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE
More informationCSCC24 Functional Programming Scheme Part 2
CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages
More informationCMSC 330, Fall 2013, Practice Problems 3
CMSC 330, Fall 2013, Practice Problems 3 1. OCaml and Functional Programming a. Define functional programming b. Define imperative programming c. Define higher-order functions d. Describe the relationship
More informationIndex. Cambridge University Press Functional Programming Using F# Michael R. Hansen and Hans Rischel. Index.
(),23 (*,3 ->,3,32 *,11 *),3.[...], 27, 186 //,3 ///,3 ::, 71, 80 :=, 182 ;, 179 ;;,1 @, 79, 80 @"...",26 >,38,35
More informationCOP4020 Programming Languages. Functional Programming Prof. Robert van Engelen
COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts
More informationImperative languages
Imperative languages Von Neumann model: store with addressable locations machine code: effect achieved by changing contents of store locations instructions executed in sequence, flow of control altered
More informationLECTURE 16. Functional Programming
LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative
More informationFunctional Programming. Big Picture. Design of Programming Languages
Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics
More informationCSCI-GA Scripting Languages
CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation
More informationCMSC 330, Fall 2013, Practice Problem 3 Solutions
CMSC 330, Fall 2013, Practice Problem 3 Solutions 1. OCaml and Functional Programming a. Define functional programming Programs are expression evaluations b. Define imperative programming Programs change
More informationFunctional Programming
Functional Programming Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense September 5, 2017 Practical Information The course is split in two I am responsible
More informationCS 11 Ocaml track: lecture 2
Today: CS 11 Ocaml track: lecture 2 comments algebraic data types more pattern matching records polymorphic types ocaml libraries exception handling Previously... ocaml interactive interpreter compiling
More informationHands-On Lab. Introduction to F# Lab version: Last updated: 12/10/2010. Page 1
Hands-On Lab Introduction to Lab version: 1.0.0 Last updated: 12/10/2010 Page 1 CONTENTS OVERVIEW... 3 EXERCISE 1: TYPES IN... 4 Task 1 Observing Type Inference in... 4 Task 2 Working with Tuples... 6
More informationFunctional Programming and Haskell
Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More informationCSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Winter 2013
CSE341: Programming Languages Lecture 9 Function-Closure Idioms Dan Grossman Winter 2013 More idioms We know the rule for lexical scope and function closures Now what is it good for A partial but wide-ranging
More informationOCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type.
OCaml The PL for the discerning hacker. ML Flow Expressions (Syntax) Compile-time Static 1. Enter expression 2. ML infers a type Exec-time Dynamic Types 3. ML crunches expression down to a value 4. Value
More informationProgramovací jazyky F# a OCaml. Chapter 6. Sequence expressions and computation expressions (aka monads)
Programovací jazyky F# a OCaml Chapter 6. Sequence expressions and computation expressions (aka monads) Sequence expressions 1. (generating sequences) Sequence expressions» Lazily generated sequences of
More informationDatatype declarations
Datatype declarations datatype suit = HEARTS DIAMONDS CLUBS SPADES datatype a list = nil (* copy me NOT! *) op :: of a * a list datatype a heap = EHEAP HEAP of a * a heap * a heap type suit val HEARTS
More informationJVM ByteCode Interpreter
JVM ByteCode Interpreter written in Haskell (In under 1000 Lines of Code) By Louis Jenkins Presentation Schedule ( 15 Minutes) Discuss and Run the Virtual Machine first
More informationCSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Fall 2011
CSE341: Programming Languages Lecture 9 Function-Closure Idioms Dan Grossman Fall 2011 More idioms We know the rule for lexical scope and function closures Now what is it good for A partial but wide-ranging
More informationFunctional Programming for Imperative Programmers
Functional Programming for Imperative Programmers R. Sekar This document introduces functional programming for those that are used to imperative languages, but are trying to come to terms with recursion
More informationWhom Is This Book For?... xxiv How Is This Book Organized?... xxiv Additional Resources... xxvi
Foreword by Bryan Hunter xv Preface xix Acknowledgments xxi Introduction xxiii Whom Is This Book For?... xxiv How Is This Book Organized?... xxiv Additional Resources... xxvi 1 Meet F# 1 F# in Visual Studio...
More informationCSC324 Functional Programming Efficiency Issues, Parameter Lists
CSC324 Functional Programming Efficiency Issues, Parameter Lists Afsaneh Fazly 1 January 28, 2013 1 Thanks to A.Tafliovich, P.Ragde, S.McIlraith, E.Joanis, S.Stevenson, G.Penn, D.Horton 1 Example: efficiency
More informationCS 11 Haskell track: lecture 1
CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of
More informationSymbolic Computation and Common Lisp
Symbolic Computation and Common Lisp Dr. Neil T. Dantam CSCI-56, Colorado School of Mines Fall 28 Dantam (Mines CSCI-56) Lisp Fall 28 / 92 Why? Symbolic Computing: Much of this course deals with processing
More informationTwo Approaches to Algorithms An Example (1) Iteration (2) Recursion
2. Recursion Algorithm Two Approaches to Algorithms (1) Iteration It exploits while-loop, for-loop, repeat-until etc. Classical, conventional, and general approach (2) Recursion Self-function call It exploits
More informationCMSC 330: Organization of Programming Languages. Functional Programming with Lists
CMSC 330: Organization of Programming Languages Functional Programming with Lists CMSC330 Spring 2018 1 Lists in OCaml The basic data structure in OCaml Lists can be of arbitrary length Implemented as
More informationSome Advanced ML Features
Some Advanced ML Features Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming University of Washington: Dan Grossman ML is small Small number of powerful constructs
More informationChapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Copyright 2009 Addison-Wesley. All rights reserved. 1-2 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages
More informationOverloading, Type Classes, and Algebraic Datatypes
Overloading, Type Classes, and Algebraic Datatypes Delivered by Michael Pellauer Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 28, 2006 September 28, 2006 http://www.csg.csail.mit.edu/6.827
More informationCPS 506 Comparative Programming Languages. Programming Language Paradigm
CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming
More informationProgramming in Standard ML: Continued
Programming in Standard ML: Continued Specification and Verification with Higher-Order Logic Arnd Poetzsch-Heffter (Slides by Jens Brandt) Software Technology Group Fachbereich Informatik Technische Universität
More informationTopic 7: Algebraic Data Types
Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,
More informationChapter 1. Fundamentals of Higher Order Programming
Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme
More informationLists. Michael P. Fourman. February 2, 2010
Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce
More informationIntroduction to Functional Programming in Racket. CS 550 Programming Languages Jeremy Johnson
Introduction to Functional Programming in Racket CS 550 Programming Languages Jeremy Johnson 1 Objective To introduce functional programming in racket Programs are functions and their semantics involve
More informationProcessadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II)
Processadors de Llenguatge II Functional Paradigm Pratt A.7 Robert Harper s SML tutorial (Sec II) Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra Paradigm Shift Imperative Paradigm State Machine
More informationTomas Petricek. F# Language Overview
Tomas Petricek F# Language Overview Master student of computer science at Charles University Prague Bachelor thesis on AJAX development with meta programming under Don Syme Microsoft C# MVP Numerous articles
More informationRecap: Functions as first-class values
Recap: Functions as first-class values Arguments, return values, bindings What are the benefits? Parameterized, similar functions (e.g. Testers) Creating, (Returning) Functions Iterator, Accumul, Reuse
More informationProgramming Systems in Artificial Intelligence Functional Programming
Click to add Text Programming Systems in Artificial Intelligence Functional Programming Siegfried Nijssen 8/03/16 Discover thediscover world at the Leiden world University at Leiden University Overview
More informationTuples. CMSC 330: Organization of Programming Languages. Examples With Tuples. Another Example
CMSC 330: Organization of Programming Languages OCaml 2 Higher Order Functions Tuples Constructed using (e1,..., en) Deconstructed using pattern matching Patterns involve parens and commas, e.g., (p1,p2,
More informationCS Lectures 2-3. Introduction to OCaml. Polyvios Pratikakis
CS 490.40 Lectures 2-3 Introduction to OCaml Polyvios Pratikakis Based on slides by Jeff Foster History ML: Meta Language 1973, University of Edinburg Used to program search tactics in LCF theorem prover
More informationThe Typed Racket Guide
The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce
More informationMini-ML. CS 502 Lecture 2 8/28/08
Mini-ML CS 502 Lecture 2 8/28/08 ML This course focuses on compilation techniques for functional languages Programs expressed in Standard ML Mini-ML (the source language) is an expressive core subset of
More informationCMSC330. Objects, Functional Programming, and lambda calculus
CMSC330 Objects, Functional Programming, and lambda calculus 1 OOP vs. FP Object-oriented programming (OOP) Computation as interactions between objects Objects encapsulate mutable data (state) Accessed
More informationTyped Racket: Racket with Static Types
Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type
More informationF# - LISTS. In this method, you just specify a semicolon-delimited sequence of values in square brackets. For example
http://www.tutorialspoint.com/fsharp/fsharp_lists.htm F# - LISTS Copyright tutorialspoint.com In F#, a list is an ordered, immutable series of elements of the same type. It is to some extent equivalent
More informationCOSE212: Programming Languages. Lecture 4 Recursive and Higher-Order Programming
COSE212: Programming Languages Lecture 4 Recursive and Higher-Order Programming Hakjoo Oh 2016 Fall Hakjoo Oh COSE212 2016 Fall, Lecture 4 September 27, 2016 1 / 21 Recursive and Higher-Order Programming
More informationFunctional Programming. Overview. Topics. Definition n-th Fibonacci Number. Graph
Topics Functional Programming Christian Sternagel Harald Zankl Evgeny Zuenko Department of Computer Science University of Innsbruck WS 2017/2018 abstract data types, algebraic data types, binary search
More informationFunctional programming Primer I
Functional programming Primer I COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Characteristics of functional programming Primary notions: functions and expressions (not
More informationUnit #2: Recursion, Induction, and Loop Invariants
Unit #2: Recursion, Induction, and Loop Invariants CPSC 221: Algorithms and Data Structures Will Evans 2012W1 Unit Outline Thinking Recursively Recursion Examples Analyzing Recursion: Induction and Recurrences
More informationCSC/MAT-220: Lab 6. Due: 11/26/2018
CSC/MAT-220: Lab 6 Due: 11/26/2018 In Lab 2 we discussed value and type bindings. Recall, value bindings bind a value to a variable and are intended to be static for the life of a program. Type bindings
More informationA Brief Introduction to Standard ML
A Brief Introduction to Standard ML Specification and Verification with Higher-Order Logic Arnd Poetzsch-Heffter (Slides by Jens Brandt) Software Technology Group Fachbereich Informatik Technische Universität
More informationCSc 372 Comparative Programming Languages
CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Christian Collberg collberg+372@gmail.com Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg
More informationClass 6: Efficiency in Scheme
Class 6: Efficiency in Scheme SI 413 - Programming Languages and Implementation Dr. Daniel S. Roche United States Naval Academy Fall 2011 Roche (USNA) SI413 - Class 6 Fall 2011 1 / 10 Objects in Scheme
More informationCSCI 2041: First Class Functions
CSCI 2041: First Class Functions Chris Kauffman Last Updated: Thu Oct 18 22:42:48 CDT 2018 1 Logistics Assignment 3 multimanager Reading OCaml System Manual: Ch 26: List and Array Modules, higher-order
More informationClosures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming
Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Summary 1. Predictive Parsing 2. Large Step Operational Semantics (Natural) 3. Small Step Operational Semantics
More informationOzyegin University CS 321 Programming Languages Sample Problems 05
Page 1 of 7 Ozyegin University CS 321 Programming Languages Sample Problems 05 1. (PLC Ex. 7.2.(i)) Write a C program containing a function void arrsum(int n, int arr[], int *sump) that computes and returns
More informationLecture 5: Lazy Evaluation and Infinite Data Structures
Lecture 5: Lazy Evaluation and Infinite Data Structures Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense October 3, 2017 How does Haskell evaluate a
More informationAnswers to review questions from Chapter 2
Answers to review questions from Chapter 2 1. Explain in your own words the difference between a method and a program. A method computes a value or performs some operation on behalf of the code for a program.
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 21 March 2 nd, 2016 GUI: notifiers Transition to Java What is the type of xs? let r = {contents = 3} let xs = [(fun () -> r.contents
More informationCSc 372. Comparative Programming Languages. 8 : Haskell Function Examples. Department of Computer Science University of Arizona
1/43 CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg Functions over Lists
More informationForward recursion. CS 321 Programming Languages. Functions calls and the stack. Functions calls and the stack
Forward recursion CS 321 Programming Languages Intro to OCaml Recursion (tail vs forward) Baris Aktemur Özyeğin University Last update made on Thursday 12 th October, 2017 at 11:25. Much of the contents
More informationList Functions, and Higher-Order Functions
List Functions, and Higher-Order Functions Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ List Functions, and Higher-Order
More informationFunctional Programming
Functional Programming Overview! Functional vs. imperative programming! Fundamental concepts! Evaluation strategies! Pattern matching! Higher order functions! Lazy lists References! Richard Bird, Introduction
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationINTRODUCTION TO HASKELL
INTRODUCTION TO HASKELL PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/81 HASKELL: A PURELY FUNCTIONAL PROGRAMMING LANGUAGE Functions are first-class values: Can be
More informationCunning Plan. One-Slide Summary. Functional Programming. Functional Programming. Introduction to COOL #1. Classroom Object-Oriented Language
Functional Programming Introduction to COOL #1 Cunning Plan Functional Programming Types Pattern Matching Higher-Order Functions Classroom Object-Oriented Language Methods Attributes Inheritance Method
More informationF# - QUICK GUIDE F# - OVERVIEW
F# - QUICK GUIDE http://www.tutorialspoint.com/fsharp/fsharp_quick_guide.htm Copyright tutorialspoint.com F# - OVERVIEW F# is a functional programming language. To understand F# constructs, you need to
More informationPrinciples of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003
Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 CS 314, LS, LTM: Functional Programming 1 Scheme A program is an expression to be evaluated (in
More informationCMSC 330: Organization of Programming Languages. Functional Programming with Lists
CMSC 330: Organization of Programming Languages Functional Programming with Lists 1 Lists in OCaml The basic data structure in OCaml Lists can be of arbitrary length Implemented as a linked data structure
More informationRECURSION. Problem Solving with Computers-II 6
RECURSION Problem Solving with Computers-II 6 10 12 40 32 43 47 45 41 Let recursion draw you in. Many problems in Computer Science have a recursive structure Identify the recursive structure in these
More information02157 Functional Programming Lecture 2: Functions, Basic Types and Tuples
Lecture 2: Functions, Basic Types and Tuples nsen 1 DTU Informatics, Technical University of Denmark Lecture 2: Functions, Basic Types and Tuples MRH 13/09/2012 Outline A further look at functions, including
More informationHaske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell
Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dk The most popular purely functional, lazy programming language Functional programming language : a program
More informationFunctional Programming
Functional Programming COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Original version by Prof. Simon Parsons Functional vs. Imperative Imperative programming
More informationHaskell through HUGS THE BASICS
Haskell through HUGS THE BASICS FP for DB Basic HUGS 1 Algorithmic Imperative Languages variables assignment if condition then action1 else action2 loop block while condition do action repeat action until
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques () Lecture 13 February 12, 2018 Mutable State & Abstract Stack Machine Chapters 14 &15 Homework 4 Announcements due on February 20. Out this morning Midterm results
More informationCOSE212: Programming Languages. Lecture 3 Functional Programming in OCaml
COSE212: Programming Languages Lecture 3 Functional Programming in OCaml Hakjoo Oh 2017 Fall Hakjoo Oh COSE212 2017 Fall, Lecture 3 September 18, 2017 1 / 44 Why learn ML? Learning ML is a good way of
More informationData Structures And Algorithms
Data Structures And Algorithms Recursion Eng. Anis Nazer First Semester 2016-2017 Recursion Recursion: to define something in terms of itself Example: factorial n!={ 1 n=0 n (n 1)! n>0 Recursion Example:
More informationChapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: Lisp Introduction
More informationCommon LISP Tutorial 1 (Basic)
Common LISP Tutorial 1 (Basic) CLISP Download https://sourceforge.net/projects/clisp/ IPPL Course Materials (UST sir only) Download https://silp.iiita.ac.in/wordpress/?page_id=494 Introduction Lisp (1958)
More informationFunctional Programming. Introduction To Cool
Functional Programming Introduction To Cool #1 Cunning Plan ML Functional Programming Fold Sorting Cool Overview Syntax Objects Methods Types #2 This is my final day... as your... companion... through
More informationReactive programming, WinForms,.NET. Björn Dagerman
Reactive programming, WinForms,.NET Björn Dagerman Motivation - Troublesome for many students previous years - Most student solutions we see are imperative - Useful techniques when working with GUI s,
More informationAn introduction introduction to functional functional programming programming using usin Haskell
An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dkau Haskell The most popular p purely functional, lazy programming g language Functional programming language : a program
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationOrganization of Programming Languages CS3200/5200N. Lecture 11
Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages
More informationCS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 7 Lambda Calculus Dan Grossman Spring 2011 Where we are Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now:
More informationProgramovací jazyky F# a OCaml. Chapter 3. Composing primitive types into data
Programovací jazyky F# a OCaml Chapter 3. Composing primitive types into data Data types» We can think of data type as a set: int = -2, -1, 0, 1, 2, More complicated with other types, but possible» Functions
More informationUnit #3: Recursion, Induction, and Loop Invariants
Unit #3: Recursion, Induction, and Loop Invariants CPSC 221: Basic Algorithms and Data Structures Jan Manuch 2017S1: May June 2017 Unit Outline Thinking Recursively Recursion Examples Analyzing Recursion:
More informationNews. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012
News CSE 130: Spring 2012 Programming Languages On webpage: Suggested HW #1 PA #1 (due next Fri 4/13) Lecture 2: A Crash Course in ML Please post questions to Piazza Ranjit Jhala UC San Diego Today: A
More informationLecture 10: Recursion vs Iteration
cs2010: algorithms and data structures Lecture 10: Recursion vs Iteration Vasileios Koutavas School of Computer Science and Statistics Trinity College Dublin how methods execute Call stack: is a stack
More informationWhereweare. CS-XXX: Graduate Programming Languages. Lecture 7 Lambda Calculus. Adding data structures. Data + Code. What about functions
Whereweare CS-XXX: Graduate Programming Languages Lecture 7 Lambda Calculus Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now: Didn t IMP leave
More informationCPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia
CPL 2016, week 10 Clojure functional core Oleg Batrashev Institute of Computer Science, Tartu, Estonia April 11, 2016 Overview Today Clojure language core Next weeks Immutable data structures Clojure simple
More informationCompSci 220. Programming Methodology 12: Functional Data Structures
CompSci 220 Programming Methodology 12: Functional Data Structures A Polymorphic Higher- Order Function def findfirst[a](as: Array[A], p: A => Boolean): Int = { def loop(n: Int): Int = if (n >= as.length)
More informationStreams. CS21b: Structure and Interpretation of Computer Programs Spring Term, 2004
Streams CS21b: Structure and Interpretation of Computer Programs Spring Term, 2004 We ve already seen how evaluation order can change behavior when we program with state. Now we want to investigate how
More informationClosures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming
Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming t ::= x x. t t t Call-by-value big-step Operational Semantics terms variable v ::= values abstraction x.
More informationProgrammazione Avanzata
Programmazione Avanzata Programmazione Avanzata Corso di Laurea in Informatica (L31) Scuola di Scienze e Tecnologie Programmazione Avanzata 1 / 51 Programming paradigms Programmazione Avanzata Corso di
More information