Some Practical Information + Programming with Lists Sept. 7 2010 Koen Lindström Claessen.

Slides:



Advertisements
Similar presentations
Modelling & Datatypes Koen Lindström Claessen. Software Software = Programs + Data.
Advertisements

1 CS101 Introduction to Computing Lecture 17 Algorithms II.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
Laziness and Infinite Datastructures Koen Lindström Claessen.
Modelling & Datatypes Koen Lindström Claessen. Software Software = Programs + Data.
Advanced Programming Handout 9 Qualified Types (SOE Chapter 12)
Introductory Computer Programming, Problem Solving and Computer Assisted Assessment Charlie Daly, DCU John Waldron, TCD.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
Recitation 1 Programming for Engineers in Python.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
CS 122 Engineering Computation Lab Lab 2 Dan De Sousa and Tim Cheeseman Department of Computer Science Drexel University April 2009 ©By the author. All.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
Recursion Recursion Chapter 12. Outline n What is recursion n Recursive algorithms with simple variables n Recursion and the run-time stack n Recursion.
Flow of Control Part 1: Selection
CS 350, slide set 5 M. Overstreet Old Dominion University Spring 2005.
1 Functional Programming Lecture 6 - Algebraic Data Types.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
1 CS161 Introduction to Computer Science Topic #9.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Week 10: Loop Invariants, Code correctness Jimmy Voss Disclaimer: Some material may have been borrowed from both the Official Course slides as well as.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Haskell Chapter 4. Recursion  Like other languages  Base case  Recursive call  Author programs a number of built-in functions as examples.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Structured Programming (COIT 29222) Term 2, 2009, Final Exam Date And Time  As advised by the university Open/Closed Book (3 hours)  Structured Programming,
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
Today’s Agenda ML Development Workflow –Emacs –Using use –The REPL More ML –Shadowing Variables –Debugging Tips –Boolean Operations –Comparison Operations.
Copyright © Curt Hill The C++ IF Statement More important details More fun Part 3.
Lite Information Koen Lindström Claessen. The Flow You prepare in advance I explain in lecture You learn with exercises You put to practice with lab assignments.
Två saker ● Labsal bokning ● Sprid ut er över salarna ● “Bracket Matching” [ " Slides: " ++ concat (intersperse ", " (map lnk gs)) | let gs = [ f | f.
Advanced Functional Programming 2010
CS314 – Section 5 Recitation 9
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Polymorphic Functions
Week 2 - Wednesday CS 121.
Laziness and Infinite Datastructures
Some Practical Information + Programming with Lists
Principles of programming languages 12: Functional programming
Object Oriented Programming
Types CSCE 314 Spring 2016.
ML: a quasi-functional language with strong typing
Haskell Chapter 2.
Introduction To Repetition The for loop
More important details More fun Part 3
CS 326 Programming Languages, Concepts and Implementation
A lightening tour in 45 minutes
Haskell Chapter 4.
Koen Lindström Claessen
Section 2 – CSE341 Patrick Larson, Spring 2013.
Java for Beginners.
The CS 5 Black Post Penguins Invade Dormitory
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Welcome to CS 1010! Algorithmic Problem Solving.
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Lesson 2: Building Blocks of Programming
Welcome to CS 1010! Algorithmic Problem Solving.
Java for Beginners University Greenwich Computing At School DASCO
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
PROGRAMMING IN HASKELL
Section 2 – CSE341 Konstantin Weitz.
Nicholas Shahan Spring 2016
CSE 341 Section 2 Winter 2018 Adapted from slides by Nick Mooney, Nicholas Shahan, Patrick Larson, and Dan Grossman.
CSE 341 PL Section 2 Justin Harjanto.
CSCE 314: Programming Languages Dr. Dylan Shell
Spencer Pearson Spring 2017
CSE 341 Section 2 Nick Mooney Spring 2017
PROGRAMMING IN HASKELL
Announcements Quiz 5 HW6 due October 23
PROGRAMMING IN HASKELL
Presentation transcript:

Some Practical Information + Programming with Lists Sept Koen Lindström Claessen

Exercises Did you go to the exercises yesterday?

Lab Assignments Total of 4 assignments –Power function –BlackJack (2 parts) –Sudoku (2 parts) –Graphical calculator (2 parts)

Each Lab has Three Deadlines First deadline: –initial part of the lab –serious try Second deadline: 1 week later –complete lab –serious try –not perfect -- feedback Final deadline: 1.5 weeks later –Can submit several times over this period –Each time you get new feedback –Final, correct solution has to be submitted before final deadline deadlines are hard

Lab Feedback -- Your function f does not work –Denote something that has to be corrected and submitted again == Your function f is a bit too complicated –Denote something that has to be corrected only if the lab has to be submitted anyway ** I see you have solved the problem –Just a regular comment, nothing to correct ++ Your implementation of f is better than mine! –Something extra good, should of course not be corrected symbols

Missing a Deadline Submitting after the deadline –In principle: Unacceptable –Submit what you have done even if it is not finished You might get one more chance –Good reason: Contact us BEFORE the deadline New opportunity: Next year!

Cheating (fusk) UNACCEPTABLE –Using someone else’s code –Showing your code to someone else Copying ing Printing Pen-and-paper writing –Copying code from the web

Instead… If you have problems –Talk to us (course assistants) –We are nice, reasonable people More time (if needed) More help –Wait until next year –DO NOT CHEAT!

If Cheating Happens…  We report this to –Disciplinary board (Chalmers) –Disciplinary board (GU) You might be suspended (”avstängd”) –1 – 3 months (no studiemedel) –This has actually happened... You might be expelled

Cheating Detection Lab graders –Discovery of similar solutions –Similar: Changing comments Changing layout Changing names of functions and variables At the end of the course –Automatic software system Pairwise similarity of solutions

Allowed Orally discuss exercises Orally discuss lab assignments Orally discuss solutions Web-based discussion board –General questions –Specific questions –Finding a lab partner –…

Lab Assignments Booking lists –Book one block at a time Extra assignments –For your own pleasure –No bonus points

Att Lämna In Skapa en grupp i Fire –2 personer (inte 1, inte 3) –Båda två ska gå med i gruppen ”Submit” i Fire –klicka på ”submit” efter uppladdningen av filerna

”Clean Code” Before you submit your code, clean it up! –Polite thing to do –Easier for us to understand your code –Easier for you to understand your code! –We will reject your solution if it is not clean –Important! To clean your code: –No long lines (<78 characters) –Consistent layout –Good comments –No ”junk” – unused code, unneccessary comments –No overly complicated function definitions

Kursevaluering Kursen utvärderas av er –3 studentrepresentanter –kursenkät Prata med representanterna –kommentar –förslag

Recursive Datatypes and Lists Koen Lindström Claessen

Types vs. Constructors data Card = Card Rank Suit a type a function a constructor function colourCard :: Card -> Colour colourCard (Card r s) = colour s the type the constructor function

Types vs. Constructors data Card = MkCard Rank Suit a type a constructor function colourCard :: Card -> Colour colourCard (MkCard r s) = colour s the type the constructor function

Recursive Datatypes data List a = Empty | Some a (List a) data [a] = [] | a : [a] uttal: ”cons”

Notation length :: [a] -> Int [12] 12 : [] [12, 0, 3, 17, 123] 12 : (0 : (3 : (17 : (123 : [])))) list with one element list-type

Quiz Vad är typen på funktionen [] ? Vad är typen på funktionen (:) ? [] :: [a] (:) :: a -> [a] -> [a]

Programming Examples maximum append (+++) reverse (rev) value :: String -> Integer (see file Lists.hs)

Lists Can represent 0, 1, 2, … things – [], [3], [”apa”,”katt”,”val”,”hund”] They all have the same type – [1,3,True,”apa”] is not allowed The order matters – [1,2,3] /= [3,1,2] Syntax – 5 : (6 : (3 : [])) == 5 : 6 : 3 : [] == [5,6,3] – ”apa” == [’a’,’p’,’a’]

More on Types Functions can have ”general” types: –polymorphism – reverse :: [a] -> [a] – (++) :: [a] -> [a] -> [a] Sometimes, these types can be restricted – Ord a => … for comparisons (, >=, …) – Eq a => … for equality (==, /=) – Num a => … for numeric operations (+, -, *, …)

Do’s and Don’ts isBig :: Integer -> Bool isBig n | n > 9999 = True | otherwise = False isBig :: Integer -> Bool isBig n = n > 9999 guards and boolean results

Do’s and Don’ts resultIsSmall :: Integer -> Bool resultIsSmall n = isSmall (f n) == True resultIsSmall :: Integer -> Bool resultIsSmall n = isSmall (f n) comparison with a boolean constant

Do’s and Don’ts resultIsBig :: Integer -> Bool resultIsBig n = isSmall (f n) == False resultIsBig :: Integer -> Bool resultIsBig n = not (isSmall (f n)) comparison with a boolean constant

Do’s and Don’ts fun1 :: [Integer] -> Bool fun1 [] = False fun1 (x:xs) = length (x:xs) == 10 fun1 :: [Integer] -> Bool fun1 xs = length xs == 10 repeated code necessary case distinction? Do not make unnecessary case distinctions

Do’s and Don’ts fun2 :: [Integer] -> Integer fun2 [x] = calc x fun2 (x:xs) = calc x + fun2 xs fun2 :: [Integer] -> Integer fun2 [] = 0 fun2 (x:xs) = calc x + fun2 xs repeated code right base case ? Make the base case as simple as possible