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 2.310 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 2.311 Part I: The Programming Language

12 5 October 2001IFIP WG 2.312 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 * 12 + 25 = … With Scheme, we can focus on ideas

13 5 October 2001IFIP WG 2.313 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 2.314 length1 returns 0, no matter what input algebraic syntax

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

16 5 October 2001IFIP WG 2.316 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 2.317 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 2.318 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 2.319 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 2.320 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 2.321 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 2.322 Part II: The Programming Environment

23 5 October 2001IFIP WG 2.323 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 2.324 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 2.325 Part III: Program Design Methods

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

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

28 5 October 2001IFIP WG 2.328 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 2.329 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 2.330 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 2.331 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 2.332 From Class Definitions to Function Templates the structure class definitions the structure of function templates

33 5 October 2001IFIP WG 2.333 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 2.334 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 2.335 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 2.336 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 2.337 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 2.338 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 2.339 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 2.340 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 2.341 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 2.342 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 2.343 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 2.344 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 2.345 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 2.346 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 2.347 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 2.348 Part IV: From Scheme to Java Training OO Programmers

49 5 October 2001IFIP WG 2.349 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 2.350 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 2.351 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 2.352 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 2.353 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 2.354 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 2.355 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 2.356 Why not just Java first? complex notation, complex mistakes no PE supports stratified Java design recipes drown in syntax

57 5 October 2001IFIP WG 2.357 Part V: Experiences

58 5 October 2001IFIP WG 2.358 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 2.359 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 2.360 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 2.361 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 2.362 Part V: Teach Haskell ?

63 5 October 2001IFIP WG 2.363 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 2.364 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 2.365 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 2.366 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 2.367 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 2.368 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 2.369 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 2.370 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 2.371 Conclusions

72 5 October 2001IFIP WG 2.372 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 2.373 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 2.374 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 2.375 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 2.376 The End

77 5 October 2001IFIP WG 2.377 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