CSE 341 : Programming Languages Section 5 Haskell: Round 3

Slides:



Advertisements
Similar presentations
Haskell Lets review some of the Haskell concepts you have been learning on your own. The answers are included, but try it yourself first.
Advertisements

”Life is too short for imperative programming” John Hughes.
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.
12 Haskell.  ftp://web.ntnu.edu.tw/WWW/func_prog/ghc zip ftp://web.ntnu.edu.tw/WWW/func_prog/ghc zip  Haskell is  Lazy evaluated  Case-sensitive.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
Laziness and Infinite Datastructures Koen Lindström Claessen.
A Lightning Tour of Haskell Lecture 1, Designing and Using Combinators John Hughes.
Advanced Programming Handout 12 Higher-Order Types (SOE Chapter 18)
CS 312 Spring 2002 Lecture 16 The Environment Model.
Cse536 Functional Programming 1 6/23/2015 Lecture #17, Dec. 1, 2004 Todays Topics – Higher Order types »Type constructors that take types as arguments.
0 PROGRAMMING IN HASKELL Chapter 9 - Interactive Programs.
MJ2 Ch 11.2 – Estimating Square Roots. Bellwork Police officers can use a formula and skid marks to determine the speed of a car. Use the formula below.
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?
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
Advanced Functional Programming 2009 Ulf Norell (lecture by Jean-Philippe Bernardy)
© 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.
0 Odds and Ends in Haskell: Folding, I/O, and Functors Adapted from material by Miran Lipovaca.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L13-1 October 26, 2006http:// Monadic Programming October.
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 λ.
Grab Bag of Interesting Stuff. Higher Order types Type constructors are higher order since they take types as input and return types as output. Some type.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
Haskell Chapter 9. More Input and More Output  Files and Streams  Transforming Input  Not covered  brackets  command-line arguments  bytestrings.
160 as a product of its prime factors is 2 5 x 5 Use this information to show that 160 has 12 factors.
Haskell Chapter 5, Part II. Topics  Review/More Higher Order Functions  Lambda functions  Folds.
H ASKELL Session 2 Ronald L. Ramos Proglan DLS-CSB 2 nd Term SY
1 Objective Caml (Ocaml) Aaron Bloomfield CS 415 Fall 2005.
24-Jun-16 Haskell Dealing with impurity. Purity Haskell is a “pure” functional programming language Functions have no side effects Input/output is a side.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Functional Programming Language: Haskell (cont’d) Lecture 20 – Functional Programming, Spring 2008.
5x(x 2 – 4) (y 2 + 4)(y 2 – 4) (9 + d 2 )(9 – d 2 )
Advanced Functional Programming 2010
Polymorphic Functions
Functional Programming
Haskell Chapter 8.
CS314 – Section 5 Recitation 10
Laziness and Infinite Datastructures
Introduction to the λ-Calculus and Functional Programming Languages
Programming Languages
dr Robert Kowalczyk WMiI UŁ
PROGRAMMING IN HASKELL
A lightening tour in 45 minutes
Haskell Chapter 4.
Higher-Order Programming: Iterative computation (CTM Section 3
Debugging Haskell by Observing Intermediate Data Structures
CSE341: Programming Languages Lecture 9 Function-Closure Idioms
Pure Kevin Edelmann.
PROGRAMMING IN HASKELL
Distributive Law Special Forms and Tables
PROGRAMMING IN HASKELL
Programming Languages
Haskell Dealing with impurity 30-Nov-18.
CSE 341 : Programming Languages Section 4 Haskel #2
CSE341: Programming Languages Lecture 9 Function-Closure Idioms
Input and Output.
Jeff West - Quiz Section 8
CSE 341 : Programming Languages Section 1 Hello Racket!
CSE 3302 Programming Languages
CSE 341 : Programming Languages Section 2 More Racket!
Haskell Dealing with impurity 8-Apr-19.
PROGRAMMING IN HASKELL
Grab Bag of Interesting Stuff
Programming Languages
Higher-Order Functions in Haskell
Haskell Dealing with impurity 29-May-19.
Laziness and Its Consequences
PROGRAMMING IN HASKELL
Haskell Dealing with impurity 28-Jun-19.
Functions Taken from notes by Dr. Neil Moore & Dr. Debby Keen
RANDOM NUMBERS SET # 1:
Presentation transcript:

CSE 341 : Programming Languages Section 5 Haskell: Round 3 Autumn 2015

Octopus Interpreter... Due Tomorrow! It’s really okay to use late days on this one! Any pressing questions? Office hours remaining: Justin Adsuara (justbads at cs) Section AC: Thurs 2:30pm-3:20pm SAV 130 Office Hours: Thurs 3:30-4:20, CSE 002

Reminder: Monads class Monad m where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b return :: a -> m a fail :: String -> m a Remember these! Monads do all sorts of things in Haskell. We’ve seen some IO, but there’s also [random, graphics, HTTP ..]

Some dos and don’ts Let’s convert! printsqrt2 = do putStr "the square root of 2 is " putStrLn (show (sqrt 2)) calcsqrt = do x <- readLn putStrLn "finding the square root of x" putStrLn (show (sqrt x))

Some dos and don’ts Let’s convert! printsqrt2 = do putStr "the square root of 2 is " putStrLn (show (sqrt 2)) printsqrt2 = putStr "the square root of 2 is " >>

Some dos and don’ts Questions? Let’s convert! calcsqrt = do x <- readLn putStrLn "finding the square root of x" putStrLn (show (sqrt x)) calcsqrt = readLn >>= \x -> putStrLn "finding the square root of x" >> Questions?

Let’s Keep Things in Scope! What does this print? x = 10 xs = map (x+) [1..] printout (x:xs) = putStrLn $ show x dostuff (x:xs) = do putStrLn $ show x printout xs dostuff xs

Let’s Keep Things in Scope! What does this print? x = 10 xs = map (x+) [1..] printout (x:xs) = putStrLn $ show x dostuff (x:xs) = do putStrLn $ show x printout xs dostuff xs 11 12

Seriously, Let’s Keep Things in Scope! How about if Haskell were dynamically scoped? x = 10 xs = map (x+) [1..] printout (x:xs) = putStrLn $ show x dostuff (x:xs) = do putStrLn $ show x printout xs dostuff xs

Seriously, Let’s Keep Things in Scope! How about if Haskell were dynamically scoped? x = 10 xs = map (x+) [1..] printout (x:xs) = putStrLn $ show x dostuff (x:xs) = do putStrLn $ show x printout xs dostuff xs 11 13

Seriously, Let’s Keep Things in Scope! How about if Haskell were dynamically scoped? x = 10 xs = map (x+) [1..] printout (x:xs) = putStrLn $ show x dostuff (x:xs) = do putStrLn $ show x printout xs dostuff xs 11 13

Seriously, Let’s Keep Things in Scope! How about if Haskell were dynamically scoped? x = 10 xs = map (x+) [1..] printout (x:xs) = putStrLn $ show x dostuff (x:xs) = do putStrLn $ show x printout xs dostuff xs Or maybe it would hang...

Seriously, Let’s Keep Things in Scope! How about if Haskell were dynamically scoped? x = 10 xs = map (x+) [1..] printout (x:xs) = putStrLn $ show x dostuff (x:xs) = do putStrLn $ show x printout xs dostuff xs Or, um...

Seriously, Let’s Keep Things in Scope! How about if Haskell were dynamically scoped? x = 10 xs = map (x+) [1..] printout (x:xs) = putStrLn $ show x dostuff (x:xs) = do putStrLn $ show x printout xs dostuff xs Yeah, this doesn’t really work with lazy evaluation.

Speaking of Lazy Evaluation... Define a list containing all integers. 1. As a non-recursive data structure 2. As a recursive data structure

Speaking of Lazy Evaluation... Define a list containing all integers. 1. As a non-recursive data structure nonzeroints = 0:foldr1 (++) [[x,(-x)] | x <- [1..]] 2. As a recursive data structure

Speaking of Lazy Evaluation... Define a list containing all integers. 1. As a non-recursive data structure nonzeroints = 0:foldr1 (++) [[x,(-x)] | x <- [1..]] 2. As a recursive data structure nonzeroints = 0 : map (\x -> if (x > 0) then (-x) else (1 - x)) nonzeroints

Any Haskell/Octopus questions? Tomorrow we start Prolog!