Strongly (very) typed language

Could anyone please tell me if there is a language which would forbids (won't compile) if you pass an argument to a fnc which is not an exact match (but has either trivial or user defined conversion to a needed type). For example if you have:

void f(int value);
//and in code you passing:
bool a = false;
f(a);

This is strictly theoretical Q.

Upvotes: 0

Views: 93

Answers (1)

roshanjames
roshanjames

Reputation: 276

This is a vague question, but all the same: Haskell, OCaml etc have this sort of behavior. If a function requires an Int - it has to be given an Int. You maybe able to write functions that coerce Ints to Bools but that doesn't change anything i.e. you still get a type error. Of course, there are languages with far more demanding type systems and complex proof obligations that Haskell and OCaml.

Scala is an interesting language where if there is a user defined coercion from one type to the other and it is non-ambiguous, the compiler will insert it for you. For example, sometimes people use it to coerce datatypes like (Int, (Int, Int)) to ((Int, Int) Int) which is handy.

Upvotes: 2

Related Questions