[Haskell-cafe] Re: Overloading functions based on arguments?
noteed at gmail.com
Fri Feb 13 05:41:33 EST 2009
2009/2/13 Daniel Kraft <d at domob.eu>:
> Colin Adams wrote:
>> If you have two functions that do two different things, then they
>> certainly OUGHT to have different names.
> Well, they do "the same thing" but for different arguments; it's like this:
> Table is a table of name-value pairs I want to substitute in a tree-like
> structure using:
> substitute :: Table -> Tree -> Tree
> For substituting a single name-value pair I want to define this utitlity
> routine so I don't have to construct a Table all the time in the user code:
> substitute :: String -> Value -> Tree -> Tree
> In the case I believe it would certainly be good to be able to name both
> functions the same, but I fear I can not do so? There are languages where
> this is explicitelly allowed (e.g. C++ or Java), so I don't think it is such
> an unuseful or evil thing.
That's probably not Evil, but it's much clearer to know what something
is by looking at its name (or the name of the function used on).
So, substituteOne and substituteMany are much clearer...
More information about the Haskell-Cafe