Comment

Comment by ericmj

Pattern matching and function overloading based on types are different but can be used for the same purposes.

For function overloading the decision for which implementation to use usually happens at compile time along with the type checking. Pattern matching happens at runtime but is more powerful since you can pattern match based on you guessed it: patterns, instead of just types.

Another small difference is that with overloading multiple functions with different signatures are created (they just share name) but with pattern matching there is a single function with multiple "function clauses".

parent ericmj 11 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton