1 / 77

preparation

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). Why do “They” Still Teach Scheme When Haskell is So Much Better?. Matthias Felleisen (PLT)

gallia
Download Presentation

preparation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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) IFIP WG 2.3

  2. Why do “They” Still Teach SchemeWhen Haskell is So Much Better? Matthias Felleisen (PLT) Northeastern University Rice University Houston, Texas IFIP WG 2.3

  3. 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 IFIP WG 2.3

  4. 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 IFIP WG 2.3

  5. 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 IFIP WG 2.3

  6. Haskell loves Scheme, Scheme loves Haskell :-) The Commonalties outweigh the differences. So what’s the true question? IFIP WG 2.3

  7. Why do “They” Still Teach Scheme or Haskell When Java and C# are So Fashionable? IFIP WG 2.3

  8. Outline • answer both questions • PLT’s TeachScheme! perspective national and international efforts to expose college and high school teachers to program design • “TeachHaskell”? IFIP WG 2.3

  9. PLT’s 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 IFIP WG 2.3

  10. PLT’s 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) IFIP WG 2.3

  11. Part I: The Programming Language IFIP WG 2.3

  12. Programming Language: Scheme • Scheme’s notation is simple: • (, operation, operands, ) • Scheme’s semantics is easy: • it’s just the rules of mathematics: • 1+1 = 2 • f(12) = 12 * 12 + 25 = … • With Scheme, we can focus on ideas IFIP WG 2.3

  13. Programming Language: Scheme Again simple syntax simple semantics powerful PE rich language it’s a lie! more lies! do you believe this? so where are the GUIs? IFIP WG 2.3

  14. algebraic syntax length1 returns 0, no matter what input IFIP WG 2.3

  15. more algebraic syntax an error message concerning procedures, whatever those things are IFIP WG 2.3

  16. 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 IFIP WG 2.3

  17. 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 IFIP WG 2.3

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

  19. Intermediate Student Scheme ;; 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)) ;; 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))) IFIP WG 2.3

  20. 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)))])) IFIP WG 2.3

  21. 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 IFIP WG 2.3

  22. Part II: The Programming Environment IFIP WG 2.3

  23. 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 IFIP WG 2.3

  24. 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 … IFIP WG 2.3

  25. Part III: Program Design Methods IFIP WG 2.3

  26. Program Design for Beginners • foster basic good habits in beginners • emphasize systematic design of programs • deemphasize input/output IFIP WG 2.3

  27. Design Recipes to be designed in out How do we wire the “program” to the rest of the world? IFIP WG 2.3

  28. Design Recipes to be designed in out • read-from-console/compute/print • file I/o • graphical user interface (GUI) • common gateway interface (CGI) • etc. IFIP WG 2.3

  29. Design Recipes to be designed in out How do we wire the “program” to the rest of the world? IMPERATIVE: Teach Model-View Separation IFIP WG 2.3

  30. 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 IFIP WG 2.3

  31. 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 IFIP WG 2.3

  32. From Class Definitions to Function Templates • the structure class definitions • the structure of function templates IFIP WG 2.3

  33. 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) IFIP WG 2.3

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

  35. 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 IFIP WG 2.3

  36. Design Recipes: Class Definitions (4) • A list of zoo animals is either • empty • (cons animal a-list-of-zoo-animals) • Let’s make examples: • empty (by definition) • (cons (make-spider ‘Asterix 1 6) empty) • (cons (make-spider ‘Obelix 99 6) (cons … …)) IFIP WG 2.3

  37. 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. IFIP WG 2.3

  38. 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 IFIP WG 2.3

  39. 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 IFIP WG 2.3

  40. 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? IFIP WG 2.3

  41. 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 [ <<condition>> <<answer>> ] [ <<condition>> <<answer>> ])) what are the sub-classes IFIP WG 2.3

  42. 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) <<answer>> ] [ (cons? a-loZA) <<answer>> ])) are any of the potential inputs structures? IFIP WG 2.3

  43. 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? IFIP WG 2.3

  44. 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) … ])) IFIP WG 2.3

  45. 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 IFIP WG 2.3

  46. 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 IFIP WG 2.3

  47. 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” IFIP WG 2.3

  48. Part IV: From Scheme to Java Training OO Programmers IFIP WG 2.3

  49. 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() IFIP WG 2.3

  50. 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 IFIP WG 2.3

More Related