prosyslab-classroom / cs348-information-security

61 stars 10 forks source link

[Question][Hw0-2] Regarding specification of Type checking problem #200

Closed m-spitfire closed 1 year ago

m-spitfire commented 1 year ago

Name: Murad Bashirov

Hello. In the given examples of problem 5 there's this case:

type_check (Or (Int 1, ToBool (Int 2))) = TyBool

But given specification of Or says: $$\frac{e_1\colon \texttt{TyBool} \quad e_2\colon \texttt{TyBool}}{\texttt{Or} \hspace{.2777em} e_1 e_2 \colon \texttt{TyBool}}$$ which I interpret as, "the arguments of Or can only be boolean", but the example contradicts to this and one argument of it is int. Is there a mistake in specification or am I understanding it incorrectly?

Thanks

m-spitfire commented 1 year ago

I think this is a mistake in the specification document, as there's a test case as follows:

assert_equal (type_check (Or (Int 1, ToBool (Int 2)))) TyError );
leejy12 commented 1 year ago

Any expression that is not covered by the type rules will have its type derived to TyError. It doesn't mean that an Or expression can not have arguments that are of the type TyInt.

m-spitfire commented 1 year ago

But the given example contradicts the test case. The example says Or (Int, Bool) should have Bool result, however the test case says it should have Error result:

image

I just have this issue still open so that the given example in the document be updated in the future.

leejy12 commented 1 year ago

Ah, I see now. The document seems to be wrong in this case. Good find.

KihongHeo commented 1 year ago

Hi Murad. You are right. This is a typo in the document. Let me fix it. Thanks.