|
|
|
|
|
by nequo
1084 days ago
|
|
> Any definition of "weakly typed" which excludes Haskell and Ocaml is farcical, inaccurate, and doesn't benefit any software engineer, especially the professional ones. Here is a definition: a language is weakly typed if and only if it has implicit type conversion. JavaScript is weakly typed: > "3" * "4"
12
Haskell is not: ghci> "3" * "4"
<interactive>:1:5: error:
• No instance for (Num String) arising from a use of ‘*’
• In the expression: "3" * "4"
In an equation for ‘it’: it = "3" * "4"
Neither is OCaml: utop # "3" * "4";;
Error: This expression has type string but an expression was expected of type
int
C++ is weakly typed: #include <iostream>
int main() {
int x = 7;
bool y = x;
std::cout << x << "\n";
std::cout << y << "\n";
return 0;
}
which prints 7
1
Haskell and OCaml are not weakly typed: ghci> let x = 7 in let (y :: Bool) = x in print y
<interactive>:4:32: error:
• No instance for (Num Bool) arising from a use of ‘x’
• In the expression: x
In a pattern binding: (y :: Bool) = x
In the expression: let (y :: Bool) = x in print y
utop # let x = 7 in let (y : bool) = x in Printf.printf "%B\n" y;;
Error: This expression has type int but an expression was expected of type bool
|
|
does typescript-like type checking (which barks on 1+”1”) with “disallow emit on error” turn javascript into the strongly typed one?