|
|
|
|
|
by Dn_Ab
4214 days ago
|
|
Dynamic dispatch is a special case of predicate dispatch. In particular, captainmuon pointed out that: >Pattern matching in functional languages solves this in a different way. captainmuon wanted a more flexible way of dispatching on types similar to what can be done with Pattern matching (which is also a special case of predicate dispatch). In the post I linked to above this example is given: Basically, instead of basing the dispatch on an "is_a" check, you check whether a general predicate is valid on the argument. So, in imaginary syntax instead of writing int foo( int a, int b):
if a > 0
return a
else
return b-a
you'd write: int foo ( gt_zero? a, int b): return a
int foo ( int a, int b): return b
|
|