Question

Computer Science question about Scala. The background information is long but question itself is short on the end.
I will give thumb up, thank you!

In class, we mentioned that developing a static type system for catching run time errors is much harder. Let us try and see what happens.

Let us modify our type grammar to have two different types of numbers: zero and non-zer

NonZeroNumType ZeroNumType

with the following subset of Lettuce just involving arithmetic and let bindings:

I Expr Const(Double) Iden(Identifier) Plus(Expr, Expr) Did Expr, Expr) → l Let(Identifier, Type, Expr, Expr)

Goal: Guarantee that a numeric value that receives type ZeroNumType must be 00 and a numeric value that receives NonZeroNumType must always be non-zero.

Semantic Rules:

Constant: The new rule for constants are

typeOf (Const(f),a)- NonZeroNumType (const-non-zero) f-0 typeOf(Const(f), a)- ZeroNumType (const-zero)

Identifiers: The rule for identifiers remains unchanged (see notes).

Plus: The new rules for plus are

typeOfel , α-Zero NumType. typeOf(e2, a)ZeroNumT ype typeOf(Plus(el, e2), a)- ZeroNumType (plus-zero) typeOfiel, a)- NonZeroN

Division: The rules for division are


typeOf(el,a) ZeroNumType, typeOf (e2, a)- Non ZeroNumType typeOf (Div(e1, e2), a)-ZeroNumType (div-zero) typeOf (e2, a) Zero

Let Binding: Rules are unchanged (see notes).

We claim that if a Lettuce program is annotated with the types ZeroNumType and NonZeroNumType, and the type annotations are according to the rules above, then any attempt to divide a number by zero will result in typeerror rather than a runtime exception thrown when evaluating the program using an interpreter.

!!!Question!!!:

(B) Point out which rule among the ones provided is incorrect (techically an incorrect type rule is called unsound).

NonZeroNumType ZeroNumType
I Expr Const(Double) Iden(Identifier) Plus(Expr, Expr) Did Expr, Expr) → l Let(Identifier, Type, Expr, Expr)
typeOf (Const(f),a)- NonZeroNumType (const-non-zero) f-0 typeOf(Const(f), a)- ZeroNumType (const-zero)
typeOfel , α-Zero NumType. typeOf(e2, a)ZeroNumT ype typeOf(Plus(el, e2), a)- ZeroNumType (plus-zero) typeOfiel, a)- NonZeroNumT ype typeOf(e2, a)- ZeroNumType typeOf (Plus(e1, e2), a) - NonZero NumT ype (plus-non-zero-I) ZeroNumType, e2, a typeOfel , α) = Zero NumT typeOf(e2.α)= NonZeroNumType typeOf (Plusle1, e2), a) - NonZero NumType (plus-non-zero-2) typeOf(el, a)-NonZeroNumType, typeOf(e2, a)- NonZeroNumType typeOf (Plusle1, e2), a) - NonZeroNumType (plus-non-zero-3)
typeOf(el,a) ZeroNumType, typeOf (e2, a)- Non ZeroNumType typeOf (Div(e1, e2), a)-ZeroNumT'ype (div-zero) typeOf (e2, a) ZeroNumiType typeOf Div(e1, e2), a) - typeerror (div-error) typeOf el, a)NonZeroNumType, typeOf (e2,aNonZeroNumType typeOf (Div(e1, e2), a) NonZeroNumType (div-ok)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Re 74Pe しら。 pe Soundness ie、 to use -Type Scr.pt ; t easier m troc. tional norms avasript is ped, de facto existin in -the olDate Page Eえist; code灬;that ;t) Anal, I assume Covar ant Orrays -ire ser ipt was not created in a vo,d esh, nr ypsystem. t na

Add a comment
Know the answer?
Add Answer to:
Computer Science question about Scala. The background information is long but question itself is ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Computer Science question about Scala. The background information is long but question itself is ...

    Computer Science question about Scala. The background information is long but question itself is short on the end. I will give thumb up, thank you! In class, we mentioned that developing a static type system for catching run time errors is much harder. Let us try and see what happens. Let us modify our type grammar to have two different types of numbers: zero and non-zer with the following subset of Lettuce just involving arithmetic and let bindings: Goal: Guarantee...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT