Determines the variable under the usual semantics

Assignment Help Computer Engineering
Reference no: EM131450439

Assignment: Type Inference.

(provide B R

         (struct-out Γ) (struct-out ≡)

         α-type-generator)

(provide some-terms some-types some-type-information

         type-info)

#| The Language of Terms.

 A term is one of:

   • <boolean-literal> - represented by a boolean

   • <numeric-literal> - represented by a number

   • <identifier> - represented by a symbol that:

° is not one of 'if, 'λ, 'local, or 'define

° uniquely determines the variable under the usual semantics, i.e. no variables with different scopes have the same name

° is not one of '??oolean, 'Real, or '→

° does not start with a greek letter

• (if <condition-term><consequent-term><alternative-term>)

- represented by a list with the symbol 'if and three terms

• (λ (<identifier> ...) <body-term>)

- represented by a list with the symbol 'λ, a list of symbols, and a term

• (local [(define <identifier><initializer-term>)]

<body-term>)

- represented by a list with the symbol 'local,

a singleton list containing a list with the symbol 'define, a symbol, and a term, and a term

• (<function-term><argument-term> ...) - represented by a non-empty list of terms

These representations should be familiar, and the prose descriptions are just reminders. |#

#| * Make some example terms.

Define 'some-terms' to contain one of each kind of:

   • base case term

   • recursive term, using only your base case terms as component terms, and

° for each of your base case terms, use it in at least one of these terms

   • recursive term, using only your previous recursive terms as component terms

° for each of your previous recursive terms, use it in at least one of these terms

For each kind of term whose definition includes any number of identifiers or any number of component terms, have at least one of each of that kind of term where:

    • zero identifiers are used

    • two identifiers are used

    • zero component terms are used

    • two component terms are used

 A term can be used to cover more than one of these cases. |#

(define some-terms

  '())

#| The Semantics of Terms.

 The terms have the familiar semantics, except the conditional requires that its condition

  produces a boolean value.

Recall that the <identifier> bound by 'local' is in the scope of its initializing term. |#

#| The Language of Types.

A type is one of:

   • boolean - represented by the symbol '??oolean

   • number - represented by the symbol 'Real

   • function from argument type(s) to result type

     - represented by a list of the argument type(s), the symbol '→, then the result type:

        (<argument-type> ... → <result-type>)

   • type variable - represented by a symbol that is not one of:

° 'if, 'λ, 'local, or 'define

° 'Boolean, 'Real, or '→ |#

(define R 'Real)

(define B 'Boolean)

#| * Make some example types.

Define 'some-types' to contain one of each kind of:

   • base case type

   • recursive type, using only your base case types as component types

   • recursive type, using only your previous recursive types as component types

Have at least one function type for a thunk, and one for a binary function. |#

(define some-types

  '())

#| Type Information for Terms.

During type inference, information about the type of a term will be:

   • a type for the term

   • type constraints: a list of pairs of types that must be "compatible" for the term to be properly typed

The type information is defined by structural induction/recursion:

   • <boolean-literal>

     type: boolean

     constraints: empty

   • <numeric-literal>

     type: number

     constraints: empty

   • <identifier>

     type: a type variable whose name is the identifier's name

     constraints: empty

   • (if <condition-term><consequent-term><alternative-term>)

     type: the type of the consequent

     constraints:

° the condition's type is compatible with boolean

° the consequent's type is compatible with the alternative's type

° all the constraints from the condition, consequent, and alternative

   • (λ (<identifier> ...) <body-term>)

     type: a function type

° the argument types are the types of the parameter identifiers [as if those were terms]

° the result type is the body's type constraints: the body term's constraints

• (<function-term><argument-term> ...)

type: a type variable whose name is 'α<index> for a natural number <index> that has not yet been used constraints:

° the function term's type is compatible with a function type whose:

- argument types are the the argument terms' types

- result type is the type of this function call term

° all the constraints from the function term and argument terms

• (local [(define <identifier><initializer-term>)]

<body-term>)

type: the body's type

constraints:

° the initializer's type is compatible with the identifier's type [as if it were a term]

° all the constraints from the initializer and body |#

#| Struct for the type information of a term. [The latex name is \Gamma]. |#

(struct Γ (type constraints) #:transparent)

#| Struct for a single compatibility constraint. [The latex name is \equiv]. |#

(struct ≡ (type0 type1) #:transparent)

; Example of type information, from one of the 'some-example-terms' I made for myself:

#;(Γ 'α0 (list (≡ 'b B)

               (≡ 'a B)

               (≡ B R)

               (≡ 'a '(→ α0))))

#;(Γ 'α0 (list (≡ 'b '??oolean)

               (≡ 'a '??oolean)

               (≡ '??oolean 'Real)

               (≡ 'a '(→ α0))))

#| * Determine the type information for each of your example terms.

For each term in your 'some-example-terms', determine its type information by applying the above algorithm, and put the result in 'some-type-information': |#

(define some-type-information

  '())

#| * Implement the algorithm you traced manually above.

Implement 'type-info' to take a term and an α type generator, producing its type information. |#

#| (α-type-generator index) produces a stateful thunk that produces types of the form 'α<index>.

The index defaults to starting at 0, but depending on how you make your test cases you might find it useful to set the initial index to something other than 0. |#

(define ((α-type-generator [index 0]))

(local-require (only-in racket/syntax format-symbol))

(set! index (add1 index))

(format-symbol "α~a" (sub1 index)))

(define (type-info a-term [αs (α-type-generator)])

#| '↓' is a new kind of pattern, meant to be used as a sub-pattern, that:

• automatically recurses on a component term where it occurs

• binds the type and constraints of the resulting Γ instance to the two supplied names

For example, instead of matching

component-term

inside a pattern and then extracting the type and constraints from (t-i component-term) in the result expression, you can instead use (↓ component-type component-constraints) and then in the result the names 'component-type' and 'component-constraints' will be       bound for you to the type and constraints of (t-i component-term).

But first start writing your implementation without '↓', until you notice the repetition in the code you are writing. That repetition is what '↓' can eliminate. |#

  (define-match-expander ↓

    (syntax-rules ()

      [(↓ <name-for-a-component-type><name-for-a-component-constraints>)

       (app t-i (Γ <name-for-a-component-type><name-for-a-component-constraints>))]))

  (define (t-i a-term)

    (match a-term

      [_ (Γ (αs) (list))]))

  (t-i a-term)

Attachment:- Assignment File.rar

Reference no: EM131450439

Questions Cloud

About the valuing bonds : Even though most corporate bonds in the United States make coupon payments semiannually, bonds issued elsewhere often have annual coupon payments.
Present value and multiple cash flows : Present Value and Multiple Cash Flows-Investment X offers to pay you $4,700 per year for eight years, whereas Investment Y offers to pay you $6,700 per year
Number of frames vs number of page fault : Draw a graph and show the relationship between number of frames vs number of page fault
Contractual elements and the sufficiency of the term : With being mindful of contractual elements and the sufficiency of the terms of the agreement, what things should be included and covered in the promissory note?
Determines the variable under the usual semantics : CSC324 2017 Winter. Assignment: Type Inference. uniquely determines the variable under usual semantics, i.e. no variables with different scopes have same name
What alternative solution might someone else recommend : What might somebody else say to show your proposed solution is wrong?What could you say to show s/he is wrong?
How much does the investor gain or ose if the exchange rate : How much does the investor gain or ose if the exchange rate at the end of hte contract is (a) $1.4900/pound and (b) $1.5200/pound?
Identify business model and key competitors : Then find the latest financial statements and try to learn as much as possible about its top management and board of directors.
How we can improve that by offering a marketing plan : develop a detailed Marketing Plan Outline for a new sports-related promotion or attraction in Arizona.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd