Presentation is loading. Please wait.

Presentation is loading. Please wait.

5 October 2001IFIP WG 2.31 preparation start drscheme set language level to Beginner open in Presentations –length1.ss –planets0.ss –lambda.ss –convert.ss.

Similar presentations


Presentation on theme: "5 October 2001IFIP WG 2.31 preparation start drscheme set language level to Beginner open in Presentations –length1.ss –planets0.ss –lambda.ss –convert.ss."— Presentation transcript:

1 5 October 2001IFIP WG 2.31 preparation start drscheme set language level to Beginner open in Presentations –length1.ss –planets0.ss –lambda.ss –convert.ss add teachpack convert.ss, then throw out (easy to find)

2 5 October 2001IFIP WG 2.32 Why do They Still Teach Scheme When Haskell is So Much Better? Matthias Felleisen (PLT) Northeastern University Rice University Houston, Texas

3 5 October 2001IFIP WG 2.33 What does the question mean? Programmers in industry? College students in senior year? –need buzz words/current technology College students in first year? –need systematic design skills

4 5 October 2001IFIP WG 2.34 Haskell vs Scheme: Two Different Universes conventional syntax type system –partitions call-by-need controlled effects parenthesized, prefix unitype system –predicates call-by-value full power of effects

5 5 October 2001IFIP WG 2.35 Haskell and Scheme: One Approach to Teaching layered languages higher-order functions design via classes of values emphasize composition over effects views of PLT not necessarily the general Scheme community

6 5 October 2001IFIP WG 2.36 Haskell loves Scheme, Scheme loves Haskell :-) The Commonalties outweigh the differences. So whats the true question?

7 5 October 2001IFIP WG 2.37 Why do They Still Teach Scheme or Haskell When Java and C# are So Fashionable ?

8 5 October 2001IFIP WG 2.38 Outline answer both questions PLTs TeachScheme! perspective national and international efforts to expose college and high school teachers to program design TeachHaskell?

9 5 October 2001IFIP WG 2.39 PLTs TeachScheme! Program Context: introductory programming at college and high school level introduce two important ideas: –program design –model(s) of computation write significant code –reaches non-majors as well as majors

10 5 October 2001IFIP WG PLTs TeachScheme! Program Scheme: simple syntax, simple semantics DrScheme: a PDE for beginners How to Design Programs (MIT, 2001) –the structure and organization of programs (systematic program design)

11 5 October 2001IFIP WG Part I: The Programming Language

12 5 October 2001IFIP WG Programming Language: Scheme Schemes notation is simple: –(, operation, operands, ) Schemes semantics is easy: –its just the rules of mathematics: 1+1 = 2 f(12) = 12 * = … With Scheme, we can focus on ideas

13 5 October 2001IFIP WG Programming Language: Scheme Again simple syntax simple semantics powerful PE rich language its a lie! more lies! do you believe this? so where are the GUIs?

14 5 October 2001IFIP WG length1 returns 0, no matter what input algebraic syntax

15 5 October 2001IFIP WG more algebraic syntax an error message concerning procedures, whatever those things are

16 5 October 2001IFIP WG Syntax is a Problem simple notational mistakes produce strange results -- without warning simple notational mistakes produce error messages beyond the students knowledge even in Scheme there are just too many features for focus on design

17 5 October 2001IFIP WG Programming Languages: Not One, Many language 1: first-order functional PL –functions and structures –simple conditional expressions language 2: higher-order functional PL –local function definitions –higher-order functions language 3: functions and effects –set! and structure mutation

18 5 October 2001IFIP WG Beginning Student Scheme (define (f x) (+ (* 5 (square x)) (* 3 x) 27)) (define-struct dollar (amount)) (define-struct planet (name picture)) ;; sign : RealNumber Symbol (define (sign x) (cond [(> x 0) +] [(= x 0) =] [(< x 0) –])))

19 5 October 2001IFIP WG Intermediate Student Scheme ;; h : Num (listof Num) (listof Num) (define (h D alon) (local ((define (h-aux l) (cond [(empty? l) empty] [else (cons (+ (first s) D) (h-aux (rest s)))]))) (h-aux alon))) ;; d/dx : (Num Num) (Num Num) (define (d/dx f) (local ((define (f-prime x) (/ (- (f (+ x eps)) (f (- x eps))) 2 eps)) f-prime))

20 5 October 2001IFIP WG Advanced Student Scheme (define counter 0) (define (bump) (set! bump (+ bump 1))) (define (zero-all boxes) (cond [(empty? boxes) (void)] [else (begin (set-box! (first boxes) 0) (zero-all (rest boxes)))]))

21 5 October 2001IFIP WG Lesson on Programming Languages arrange programming language in pedagogic layers … put students into a knowledge- appropriate context … focus on design ideas relative to this context

22 5 October 2001IFIP WG Part II: The Programming Environment

23 5 October 2001IFIP WG The Programming Environment one PE for all languages –supplemental code that does not conform to the language level interactive – ensure model-view separation (MVC) exploration of –program structure –program evaluation

24 5 October 2001IFIP WG DrScheme: Demo language level: catching simple errors pictures as values lexical structure, alpha renaming evaluation as algebraic reduction teachpacks: model-view separation –more in a moment …

25 5 October 2001IFIP WG Part III: Program Design Methods

26 5 October 2001IFIP WG Program Design for Beginners foster basic good habits in beginners emphasize systematic design of programs deemphasize input/output

27 5 October 2001IFIP WG Design Recipes to be designed inout How do we wire the program to the rest of the world?

28 5 October 2001IFIP WG Design Recipes to be designed inout read-from-console/compute/print file I/o graphical user interface (GUI) common gateway interface (CGI) etc.

29 5 October 2001IFIP WG Design Recipes to be designed inout How do we wire the program to the rest of the world? IMPERATIVE: Teach Model-View Separation

30 5 October 2001IFIP WG Design Recipes understand classes of data –representation of (external) information as data in your favorite language understand program as function –that is triggered by events –that consumes/produces data most important: connect class definition and function definition

31 5 October 2001IFIP WG The Basic Design Recipe data analysis and class definition contract, purpose statement, header in-out (effect) examples function template function definition testing, test suite development

32 5 October 2001IFIP WG From Class Definitions to Function Templates the structure class definitions the structure of function templates

33 5 October 2001IFIP WG Design Recipes: Class Definitions use rigorous language, not formalism naïve set theory –basic sets: numbers, chars, booleans –intervals –(labeled) products, that is, structures –(tagged) unions –self-references –mutual references –vectors (natural numbers)

34 5 October 2001IFIP WG Design Recipes: Class Definitions (2) (define-struct spider (name size legs)) A spider is a structure: (make-spider symbol number number)

35 5 October 2001IFIP WG Design Recipes: Class Definitions (3) A zoo animal is either a spider an elephant a giraffe a mouse … Each of these classes of animals has its own definition

36 5 October 2001IFIP WG Design Recipes: Class Definitions (4) A list of zoo animals is either empty (cons animal a-list-of-zoo-animals) Lets make examples: empty (by definition) (cons (make-spider Asterix 1 6) empty) (cons (make-spider Obelix 99 6) (cons … …))

37 5 October 2001IFIP WG Design Recipes: Class Definitions (5) (define-struct child (name father mother)) A family tree is either unknown (make-child symbol a-family-tree a-family-tree-2) Many, if not most, interesting class definitions are self-referential.

38 5 October 2001IFIP WG Design Recipes: Function Templates (Structure) a function template reflects the structure of the class definitions this match helps –designers guide the process –readers comprehend –teachers diagnose weaknesses –modifiers/maintainers analyze or change

39 5 October 2001IFIP WG Design Recipes: Templates (2) is it a basic class? is it a union? is it a structure? is it self-referential? domain knowledge case analysis extract field values annotate for recursion

40 5 October 2001IFIP WG Design Recipes: Templates (3) A list of zoo animals is either empty (cons animal a-list-of-zoo-animals) ;; fun-for-zoo : list-of-zoo-animals -> ??? (define (fun-for-zoo a-loZA) … ) is it a union?

41 5 October 2001IFIP WG Design Recipes: Templates (4) A list of zoo animals is either empty (cons animal a-list-of-zoo-animals) ;; fun-for-zoo : list-of-zoo-animals -> ??? (define (fun-for-zoo a-loZA) (cond [ > > ] [ > > ])) what are the sub-classes

42 5 October 2001IFIP WG Design Recipes: Templates (5) A list of zoo animals is either empty (cons animal a-list-of-zoo-animals) ;; fun-for-zoo : list-of-zoo-animals -> ??? (define (fun-for-zoo a-loZA) (cond [ (empty? a-loZA) > ] [ (cons? a-loZA) > ])) are any of the potential inputs structures?

43 5 October 2001IFIP WG Design Recipes: Templates (6) A list of zoo animals is either empty (cons animal a-list-of-zoo-animals) ;; fun-for-zoo : list-of-zoo-animals -> ??? (define (fun-for-zoo a-loZA) (cond [ (empty? a-loZA) … ] [ (cons? a-loZA) … (first a-loZA) … … (rest a-loZA) … ])) is the class definition self-referential?

44 5 October 2001IFIP WG Design Recipes: Templates (7) A list of zoo animals is either empty (cons animal a-list-of-zoo-animals) ;; fun-for-zoo : list-of-zoo-animals -> ??? (define (fun-for-zoo a-loZA) (cond [ (empty? a-loZA) … ] [ (cons? a-loZA) … (first a-loZA) … … (rest a-loZA) … ]))

45 5 October 2001IFIP WG Design Recipes: Defining Functions templates remind beginners of all the information that is available –which cases –which field values, argument values –which natural recursions are computed the goal of function definitions is –to compute with the available values –to combine the computed effects

46 5 October 2001IFIP WG Design Recipes: Overview basic data, intervals of numbers structures unions self-reference in class description mutual references generative recursion special attributes: –accumulators –effects abstraction of designs

47 5 October 2001IFIP WG Design Recipes: Conclusion get students used to discipline from DAY ONE use scripted question-and-answer game until they realize they can do it on their own works well as long as class definitions are standard

48 5 October 2001IFIP WG Part IV: From Scheme to Java Training OO Programmers

49 5 October 2001IFIP WG Scheme to Java: OO Computing focus: objects and method invocation basic operations: –creation –select field –mutate field select method via polymorphism structures and functions basic operations: –creation –select field –mutate field –recognize kind f(o) becomes o.f()

50 5 October 2001IFIP WG Scheme to Java: OO Programming develop class and interface hierarchy allocate code of function to proper subclass develop class definitions allocate code of function to proper cond-clause

51 5 October 2001IFIP WG Scheme to Java: Class Hierarchy A list of zoo animals is either empty (cons animal a-list-of-zoo-animals) List of zoo animals EmptyCons: animal list of zoo animals

52 5 October 2001IFIP WG Scheme to Java: Code Allocation ;; fun-for-zoo : list-of-zoo-animals -> ??? (define (fun-for-zoo a-loZA) (cond [ (empty? a-loZA) ] [ (cons? a-loZA) … (first a-loZA) … … (rest a-loZA) … ])) List of zoo animals Empty: Cons: animal list of zoo animals

53 5 October 2001IFIP WG Scheme to Java: Ketchup & Caviar abstract class List_Zoo_Animal { int fun_for_list(); } class Cons extends List_Zoo_Animal { Zoo_Animal first; List_Zoo_Animal rest; int fun_for_list() { return 1 + rest.fun_for_list(); } class Empty extends List_Zoo_Animal { int fun_for_list() { return 0; }

54 5 October 2001IFIP WG Scheme to Java: Ketchup & Caviar abstract class List_Zoo_Animal { int fun_for_list(); } class Cons extends List_Zoo_Animal { Zoo_Animal first; List_Zoo_Animal rest; int fun_for_list() { return 1 + rest.fun_for_list(); } class Empty extends List_Zoo_Animal { int fun_for_list() { return 0; }

55 5 October 2001IFIP WG Scheme to Java the design recipes work step for step for the production of OO programs the differences are notational the differences are instructive

56 5 October 2001IFIP WG Why not just Java first? complex notation, complex mistakes no PE supports stratified Java design recipes drown in syntax

57 5 October 2001IFIP WG Part V: Experiences

58 5 October 2001IFIP WG Experiences: Rice Constraints life-long learners accommodate industry long-time enable students to gain industry experience after two semesters no trends, no fashion oo programming components until recently: –C++ now more and more: –Java, true OOP

59 5 October 2001IFIP WG Experiences: The Rice Experiment beginners: no experience, up to three years of experience comp sci introduction: TeachScheme curriculum good evaluation huge growth many different teachers applied comp introduction: C/C++ curriculum weak evaluations little growth several teachers second semester: OOP, classical data structures, patterns

60 5 October 2001IFIP WG Experiences: The Rice Experiment Faculty with preferences for C/C++ state that students from the Scheme introduction perform better on exams and projects in second course than students from the C/C++ introduction Students with lots of experiences eventually understand how much the course adds to their basis

61 5 October 2001IFIP WG Experiences: Secondary Schools trained around 200 teachers/professors 120+ deployed the curriculum, reuse it better basis for second courses much higher retention rate –especially among females

62 5 October 2001IFIP WG Part V: Teach Haskell ?

63 5 October 2001IFIP WG Social Theorem 1: Beginners make mistakes. Corollary: Teaching efforts must help beginners and teachers find and help mistakes in designs, notation, and evaluations.

64 5 October 2001IFIP WG Social Theorem 2: To beginners, its about two things: the computer and the human. Corollary: Adding intermediate layers doesnt help.

65 5 October 2001IFIP WG Haskells Key Features conventional syntax types lazy data controlled effects see theorem 1 see theorem 2 yet another recipe too difficult, interesting

66 5 October 2001IFIP WG Working with Haskell (1) queens_kill :: Int -> [Int] -> Bool -- determine whether a queen can be placed in file lcon, -- places the preceding files of the board queesn_kill locn places = helper places 1 where helper [] _ = False helper (hd:tl) offset = lcon == hd || -- same file lcon == hd + offset || -- right diagonal lcon == hd - offset || -- left diagonal helper tl offset + 1

67 5 October 2001IFIP WG Working with Haskell (2) Reading file: `nq.hs`: Type checking ERROR: `nq.hs` (line 6): Bool is not an instance of class `Num` line 6: helper [] _ = False

68 5 October 2001IFIP WG Working with Haskell (3) queens_kill :: Int -> [Int] -> Bool -- determine whether a queen can be placed in file lcon, -- places the preceding files of the board queesn_kill locn places = helper places 1 where helper [] _ = false helper (hd:tl) offset = lcon == hd || -- same file lcon == hd + offset || -- right diagonal lcon == hd - offset || -- left diagonal helper tl offset + 1

69 5 October 2001IFIP WG Working with Haskell (3) queens_kill :: Int -> [Int] -> Bool -- determine whether a queen can be placed in file lcon, -- places the preceding files of the board queesn_kill locn places = helper places 1 where helper [] _ = false helper (hd:tl) offset = lcon == hd || -- same file lcon == hd + offset || -- right diagonal lcon == hd - offset || -- left diagonal helper tl (offset + 1)

70 5 October 2001IFIP WG Keys to TeachScheme!s Success: on to Haskell tower of languages pde support for (1) other pde support design recipes –emphasis on classes of values tower of types tower of notation pde support for both easy adapt for lazy data adapt for controlled effects

71 5 October 2001IFIP WG Conclusions

72 5 October 2001IFIP WG Conclusion training good programmers does not mean starting them on currently fashionable languages provide a strong, rigorous foundation in data-oriented, class-oriented thinking then, and only then, expose to fashion

73 5 October 2001IFIP WG Conclusion students wish to intern during summer OOP languages are here to stay constraints on introductory courses: –students likely to have some experience –students need to see some OOP language –non-standard students check out CS

74 5 October 2001IFIP WG Conclusion teach Scheme for the first semester teach an OOP language for second teaches students: –about classes of values –rigorous program development –interests non-standard students

75 5 October 2001IFIP WG My Ideal Scenario TeachScheme!: for speedy start (O)CAML: for types (and classes) Haskell: for reasoning about effects and lazy data Java/C#: for classes and real world Felleisen Harper Hudak Steele

76 5 October 2001IFIP WG The End

77 5 October 2001IFIP WG Credits Findler Flanagan Flatt Krishnamurthi Cartwright Clements Friedman Steckler


Download ppt "5 October 2001IFIP WG 2.31 preparation start drscheme set language level to Beginner open in Presentations –length1.ss –planets0.ss –lambda.ss –convert.ss."

Similar presentations


Ads by Google