Docsity

Going Meta, The Functional Programming - Lecture Slides | CIS 500, Study notes of Computer Science

Partial preview of the text

Download Going Meta, The Functional Programming - Lecture Slides | CIS 500 and more Study notes Computer Science in PDF only on Docsity!

CIS 500

Software Foundations

Fall 2003

15 September

Administrivia

If you still want to join a study group, send mail to

     . We

currently have one pending request.

announce assignments as soon as possible.Please write down your name and recitation preferences. We willSign-up sheets for recitations are being passed around the room.

HW3 is available now; due next Monday. Please look at (at least) the first two problems from HW3consider learning how to use Latex now. If you foresee a lot of technical writing in your future, you should Can be handed in either physically or electronically

(^) before

coming to this weekโ€™s recitation.

Going Meta...

programs as data The functional programming style used in OCaml is based on treating

(^) โ€” i.e., on writing functions that manipulate other

functions as their inputs and outputs.

Going Meta...

programs as data The functional programming style used in OCaml is based on treating

(^) โ€” i.e., on writing functions that manipulate other

Everything in this course is based on treatingfunctions as their inputs and outputs.

(^) programs as mathematical

objects

(^) โ€” i.e., we will be building mathematical theories whose basic

objects of study are programs (and whole programming languages).

4-a

Warning!

A much better test is โ€œI can explain it so that someone else believes it.โ€โ€œI believe it when I hear itโ€ is not a sufficient test of understanding.first appear. The material in the next couple of lectures is more slippery than it may

Basics of Induction

(Review)

Example

Theorem:

         , for every

 .

Proof: Let

  be โ€œ            .โ€

Show

 :

 ^    

Show that

  implies

   :

     

        

 

  

 

by IH

  



The result (

  for all

 ) follows by the principle of induction.

Shorthand form

Theorem:

         , for every

 .

Proof: By induction on

 .

Base case (

  ):

 ^    

Inductive case (

    ):

              

 

    

IH





Ordinary and complete induction are

(^) interderivable

(^) โ€” assuming one, we

Weโ€™ll see some other (equivalent) styles as we go along.question of style.Thus, the choice of which to use for a particular proof is purely acan prove the other.

Syntax

Abstract vs. concrete syntax

Q1: Does this grammar define a set of

(^) character strings

, a set of

(^) token

lists

, or a set of

(^) abstract syntax trees

?

Abstract vs. concrete syntax

Q1: Does this grammar define a set of

(^) character strings

, a set of

(^) token

lists , or a set of

(^) abstract syntax trees

?

sometimes calledFor this reason, grammars like the one on the previous slide aresyntax trees.A: In a sense, all three. But we are primarily interested, here, in abstract

(^) abstract grammars

. An abstract grammar

(^) defines

(^) a set

of abstract syntax trees and

(^) suggests

(^) a mapping from character strings

We thento trees.

(^) write

(^) terms as linear character strings rather than trees simply

intended, we use parentheses to disambiguate.for convenience. If there is any potential confusion about what tree is

14-a

A more explicit form of the definition

The set

of (^) terms

(^) is the smallest set such that

    ^  ^    ^   ;

(^) if

  , then

   ^         

^   ;

(^) if

  , 

, and

  , then

        

^  .

Inference rules

An alternate notation for the same definition:

   

       

 

      

      

  

 

^



^ 

^ 

          

Terminology:explicitly). Note that โ€œthe smallest set closed under...โ€ is implied (but often not stated axiom vs. rule

concrete rule vs. rule scheme