fre 2002-08-16 klockan 15.37 skrev Andrew Koenig: > David> Oh, easily solved: "in the face of ambiguity, refuse the > David> temptation to guess". There should be a best match rule, and > David> if there are two best matches, it's an error. > > In the ML example I showed earlier: > > fun len([]) = 0 > | len(h::t) = len(t) + 1 > > ordering is crucial: As long as the argument is not empty, both cases > match, so the language is defined to test the clauses in sequence. > My intuition is that people will often want to define category tests > to be done in a particular order. There is no problem with such ordering > as long as all of the tests are specified together. What does "not empty" mean in this context? "not []"? Does h::t match [] or does [2] match []? Why is the ordering crucial? In Haskell: f [] = 0 f (x:xs) = 1 + f xs is totally equivalent with: f (x:xs) = 1 + f xs f [] = 0 Of course, if the different patterns overlap, THEN ordering is crucial, I just find it odd that [] and h::t would overlap... Martin -- Martin Sjögren martin@strakt.com ICQ : 41245059 Phone: +46 (0)31 7710870 Cell: +46 (0)739 169191 GPG key: http://www.strakt.com/~martin/gpg.html
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4