Maybe this is a deficiency in Dartboard
, but if you pass a string as the second parameter to the callback in your example, it prints "true" and "false" in checked mode instead of throwing an exception:typedef MyCallbackFunctionType(String,int);main() {MyCallbackFunctionType callback = (s,i) {print(s is String);print(i is int);};someFunction(callback);}someFunction(MyCallbackFunctionType callback) {callback("Hello", 'b');}
Did you mean:
someFunction(callback(String s, int i)) {
or
someFunction(void callback(String s, int i)) {
Cheers,
Peter
Actually, our function subtype rule is not the typical one. See
section "13.5 Function Types" of the specification.
Basically it says that (T) -> S is a subtype of (T') -> S' if T is a
subtype of T' or T' is a subtype of T AND if S is a subtype of S' or
S' is a subtype of S or S' is void.
This is because we want to allow you to do this:
printIt(String f()) { print (f()); }
main() {
Object f() => 'Hello, World!';
printIt(f);
}
Cheers,
Peter
Actually, our function subtype rule is not the typical one. See
section "13.5 Function Types" of the specification.
Basically it says that (T) -> S is a subtype of (T') -> S' if T is a
subtype of T' or T' is a subtype of T AND if S is a subtype of S' or
S' is a subtype of S or S' is void.
Correct. The idea is that it requires a more complicated type system
than we want to be able to precisely express what kind of function you
need. For example, if you have this function:
foo(String x(String key)) { ... }
Here foo says that it needs a function that it will pass a String and
expect a String back. The identity function has this property, but may
be typed like this:
Object identity(Object o) => o;
We want developers spending more time adding real value to their
programs instead of worrying about a fairly complicated type system
that would be required to support this otherwise.
Cheers,
Peter