1 / 25

SML

SML. 0, 1, 2, ..., +, -,. true, false, if e then e else e. fun f x = e. variables. exceptions. e 1 e 2. patterns. functors. fn x => e. structures. datatypes. ?. What lies in the core of SML?. 0, 1, 2, ..., +, -,. true, false, if e then e else e. fun f x = e. variables.

icurry
Download Presentation

SML

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. SML 0, 1, 2, ..., +, -, ... true, false, if e then e else e fun f x = e variables exceptions e1 e2 patterns functors fn x => e structures datatypes

  2. ? What lies in the core of SML? 0, 1, 2, ..., +, -, ... true, false, if e then e else e fun f x = e variables exceptions e1 e2 patterns functors fn x => e structures datatypes

  3. Candidates? • booleans and if/then/else • integers • lists • variables • functions and function applications • datatypes • patterns • structures • functors • ...

  4. x fn x => e e1 e2 Core of SML

  5. -calculus

  6. CSE-321 Programming Languages-Calculus 박성우 POSTECH March 21, 2007

  7. Outline • Abstract syntax of the -calculus • Operational semantics of the l-calculus • Substitutions • Programming in the -calculus

  8. Concrete syntax program = string of characters specifies rules for parsing. operator precedence associativity keywords, ... 1 + 2 * 3 1 + (2 * 3) 1 + (2 * (3)) Abstract syntax abstracts away from details of parsing. focuses on the high-level structure of programs. suitable for studying the semantics Syntax for a Programming Language

  9. Abstract Syntax of the -Calculus • x • variable • z, s, t, f, arg, accum, ... • x. e • -abstraction • x = formal argument, e = body • ¼fn x => e • e1 e2 • application • left-associative (as in SML): • e1 e2 e3 = (e1 e2 ) e3 • e1 e2 e3 e1 (e2 e3 )

  10. Examples

  11. Outline • Abstract syntax of the -calculus V • Operational semantics of the l-calculus • Substitutions • Programming in the -calculus

  12. Semantics of Languages • Answers "what is the meaning of a given program?" • SML has a formal semantics. • What about C? • Three styles • denotational semantics • axiomatic semantics • operational semantics • The 1990s saw the renaissance of operational semantics.

  13. operation operation Value Pn P2 ... operation operation Operational Semantics • Specifies how to transform a program into a value via a sequence of operations Program let fun fac 1 = 1 | fac n = n * fac (n - 1) in fac 4 end 24

  14. reduction reduction Value En E2 ... reduction reduction Operational Semantics of -Calculus • Specifies how to transform an expression into a value via a sequence of reductions Expr

  15. Values and Reductions

  16. : -reduction redex = reducible expression Reductions

  17. _____ = Redex

  18. -Reduction Not Unique So we need a reduction strategy.

  19. Call-by-name Call-by-value

  20. Call-by-name Call-by-value

  21. Used in Haskell Lazy or non-strict functional languages The implementation uses call-by-need. Superb! Used in SML Eager or strictfunctional languages Superb! Call-by-nameCall-by-value (fn x => 0) <some horrible computation> (fn x => 0) <non-terminating computation>

  22. Assignments • Assignment 2 • average 86.68 • Be sure to take a look at the sample solution. • Assignment 3 • to be out by midnight tonight. • ??? • due on April 2 • Start early! ( Start coding early!)

  23. Quiz 1 • Next Monday • Read Chapter 2 of Course Notes. • 'fill in the blank' problems (i.e., easy) • 15 minutes • Please show up on time.Otherwise you might miss the quiz!

  24. Anonymous Feedback • To be set up sometime today (hopefully) • http://pl.postech.ac.kr/~gla/feedback/ • I will appreciate your feedback on this course. • lectures • assignments • schedule • topics • It is you who will improve this course!

More Related