3 ms·
One reason to have separate domains for data and functions is that it allows you to have types. If you start with the presumption that you aren't going to have
by tumult 16y ago
One reason to have separate domains for data and functions is that it allows you to have types. If you start with the presumption that you aren't going to have types, you no longer need to make this distinction.
Scotch only goes half-way. For example, I can't do this in Scotch:
>> foo(a,b) = a
>> foo(bar(a,b),bar(c,d)) = bar(a,c)
>> bar(a) = "spaghetti"
>> foo("baz","qux")
"baz"
>> foo(foo(bar("baz","qux"),bar("corge","grault")))
"baz"
>> foo(bar("anything"),bar("something"))
"spaghetti"
Scotch distinguishes between data construction and function application, but the only benefit you get out of it is that you won't get any typing errors.
If you are interested by the sort of very powerful pattern matching demonstrated above, check out languages in the family of term rewriting, of which the newest and coolest is Pure, http://code.google.com/p/pure-lang/ http://code.google.com/p/pure-lang/, powered by LLVM with influence from Haskell. It is also dynamically typed (by necessity).
Another popular example of term rewriting is the Mathematica language, used in the software package of the same name.