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

  Design a shift register with parallel load

Design a shift register with parallel load that operates according to the following function table:

  One approach to operating system design is to provide as

one approach to operating system design is to provide as small a kernel as possible and to make all other modules

  How many edges are there in a tree with 57 vertices

How many edges are there in a tree with 57 vertices - How many internal vertices are there in a full binary tree of height 10?

  Early in 1999 hotel managers simon andrews and sybil jones

early in 1999 hotel managers simon andrews and sybil jones decided to leave one of the europes largest hotel chains and

  What are the models that describe use cases in more detail

What are the models that describe use cases in more detail? Which part of a use case description can also be modeled by using an activity diagram? List the parts or compartments of a fully developed use case description.

  What is the average latency time for disk

What is the disk transfer rate in bytes per second and what are the minimum and maximum latency times for this disk? What is the average latency time for this disk?

  Record the single process that is using the most memory

Record the total number of processes that are actively running. Record the single process that is using the most memory. Exploring the Activity Monitor (Screenshot and written response required).

  Introduce relationship sets or additional entity sets

Introduce relationship sets or additional entity sets

  Show a letter grade based upon the average

In this script, convert pseudocode that uses a decision structure into a shell script. The script then will accept three grades, calculate an average, and then display a letter grade based upon the average.You will need to use either the if statem..

  Questionwrite a program use a matrix represents an island

questionwrite a program use a matrix represents an island surrounded by water. two bridges lead out of the island. a

  Overview of company and client business case

What is your companys expertise and Ensure that the expertise matches the skill sets required for the business case you have chosen - Overview of Company and Client Business Case

  Functionalities of pharmacy information systems

Analyze the different functionalities of the pharmacy information systems which can aid in reduction of the medication errors and make at least two recommendations for the improvements in future systems.

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