1 / 19

Introduction to Call-by-Name/Need in Programming Languages

This post discusses the concepts of call-by-name and call-by-need in programming languages, with a focus on Haskell. It also explores the future of programming languages and the potential of call-by-name/need in modern language design.

lmengel
Download Presentation

Introduction to Call-by-Name/Need in Programming Languages

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. CSE-321 Programming LanguagesCall-by-name/need 박성우 POSTECH June 9, 2006

  2. Call-by-name

  3. Rule App • Evaluates argument e' only when it is necessary to do so

  4. Call-by-need • Semantically equivalent to call-by-name • Never evaluates the same expression more than once

  5. Graph Representation • let square = fn x => mult x x let main = square (square 3) @ @ @ @ x square mult square 3 x mult x x square (square 3)

  6. square under Call-by-need • let square = fn x => mult x x let main = square (square 3) @ @ @ x @ x mult mult x ² call-by-name call-by-need

  7. Graph Reduction • let square = fn x => mult x x let main = square (square 3) square= @ @ @ @ x square mult square 3 ²

  8. @ square 3 Graph Reduction • let square = fn x => mult x x let main = square (square 3) square= @ @ mult ²

  9. @ @ 3 mult ² Graph Reduction • let square = fn x => mult x x let main = square (square 3) @ @ mult ²

  10. Graph Reduction • let square = fn x => mult x x let main = square (square 3) @ @ 9 mult ²

  11. Outline • Introduction to call-by-need V • Haskell • don't think operationally, i.e., how. • think 'declaratively, i.e., what. • Future of programming languages

  12. "Hello, Haskell" inc :: Integer -> Integer inc n = n + 1 length :: [a] -> Integer length [] = 0 length (x:xs) = 1 + length xs head :: [a] -> a head (x:xs) = x tail :: [a] -> [a] tail (x:xs) = xs

  13. List Comprehension • List of all f x such that x is drawn from xs. [f x | x <- xs] • Quick sort quicksort [] = [] quicksort (x:xs) = quicksort [ y | y <- xs, y < x] ++ [x] ++ quicksort [y | y <- xs, y >= x]

  14. Infinite Data Structures • An infinite list of ones ones = 1 : ones • Infinite list of successive integers beginning with n numsFrom n = n : numsFrom (n + 1) • Infinite list of squares squares = map (^2) (numsFrom 0)

  15. Infinite Fibonacci! fib = 1 : 1 : [ a + b | (a, b) <- zip fib (tail fib) ] fib = 1 : 1 : 2 : 3 : 5 : 8 : 13 : ... tail fib = 1 : 2 : 3 : 5 : 8 : 13 : ... zip ... = (1,1) : (1, 2) : (2, 3) : (3, 5) : ... a + b 2 3 5 8

  16. Outline • Introduction to call-by-need V • Haskell V • Future of programming languages

  17. Functional vs. Imperative • Functional languages are in the minority • not because they are ill-designed • not because they are difficult to learn • but because ... • Imperative languages are in the majority • not because they are elegant • not because they are easy to learn • but because of their popularity in the past

  18. Future of Programming Languages • Criteria of little importance • memory requirement • speed • integrated programming environments • ... • Criteria of ultimate importance • specification • specification • specification • ...

  19. PostechML • Call-by-value + call-by-need • next-generation functional languages • Mechanized safety proof • automatic proof of type safety from language definition • Scientific computation • dimension analysis • network communication • ...

More Related