3 ms·
>> foo(Somedata(a,b)) = a >> foo(Somedata(1,2)) 1 It is term rewriting. If I understand you correctly, this should work as you would expect. Thanks for taki
by bendmorris 16y ago
>> foo(Somedata(a,b)) = a
>> foo(Somedata(1,2))
1
It is term rewriting. If I understand you correctly, this should work as you would expect.
Thanks for taking some time to play around with it. There are definitely still some bugs to work out in the interpreter; any details you can provide about the issues you find would be much appreciated.
- tumult 16y agoLooks like it was because I had a space after the comma. Oops! Why did you choose to distinguish between data constructors and functions?
- bendmorris 16y agoWhoops, that'd be a parsing error. Thanks for catching that. I think different syntax for data constructors and functions reduces ambiguity and adds to readability.
- tumult 16y agoOne 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.
- tumult 16y agoForgot to also add: good job so far, but clean it up so it works with cabal/hackage :)