[SOLVED] 代写 我们用的是DrRack 的软件, 代码在另外一个文档里面

30 $

File Name: 代写_我们用的是DrRack_的软件,_代码在另外一个文档里面.zip
File Size: 706.5 KB

SKU: 8275160059 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


我们用的是DrRack 的软件, 代码在另外一个文档里面

Hi,
For what it’s worth, it was just pointed out to me that one of my test programs:
{rec {fac : (number -> number) {fun {n}
{if {< n 2} 1{* n {fac {- n 1}}}}}}{fac 6}}

is not syntactically correct.It should be:

{rec {fac : (number -> number) {fun {n : number}
 {if {< n 2} 1 
 {* n {fac {- n 1}}}}}}

{fac 6}}

That is, I missed the type declaration for the fun parameter.I’m surprised no one mentioned this to me.Here are some comments I wrote in response to email questions.  They might or might not be of interest.For the fun type check, you have some inputlike:  {fun {x : number}              {< x 10}}which becomes the TBOB tree:(fun ‘x (numType) (lt (id ‘x) (num 10)))So when you’re processing this in the get-type code, the variant [fun (arg type body) …has arg set to ‘x,    type set to (numType),and body set to (lt (id ‘x) (num 10)).Now, looking at the input code, you should be able to say that the correct type of this expression is(funType (numType) (boolType)).How does your program figure this out?Since we’re typing a “fun” expression, we know that the answer will be a  (funType …The domain type will be the type of the argument [which is “type” above], so the answer will be  (funType type …and now we need to figure out the type of the body.  Working by hand, we figured out boolType was the answer because the body is a “lt” tree, which returns a boolean value.So, the codomain type is the type of the body, i.e. (funType type (get-type body …Now, what do we want for the type environment.We need to figure out the type of an expression that involves “x”, so at some point will we want to lookup x in the type environment.We know the type of x from the input, so we extend the type environment to include this binding for the arg: (funType type (get-type body (aTypeSub arg type tenv)))=======================================The grammar describes what a type specification might look like: ::= number
| boolean
| ( -> )
So, the fields in the function type can be anything that matches this pattern.  That  includes boolean and also other function types.
You can see some of these types used in the sample programs.  Your current code looks for “fun”, but there’s nothing like that in the input.  The type parser knows it has a function type when it finds a list rather than an atom.  In that case, it calls itself recursively to process the domain specification, makes sure the second element in the list is ‘-> and calls itself recursively to process the codomain specification.
Here are some examples of legal types:
number
boolean
( number -> number )
( number -> boolean )
( boolean -> boolean )
( boolean -> number )
( ( number -> boolean ) -> number )
( ( number -> number ) -> ( number -> boolean) )
( number -> ( number -> boolean ) )
etc.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 我们用的是DrRack 的软件, 代码在另外一个文档里面
30 $