[Haskell-cafe] Re: Overloading functions based on arguments?

Neil Mitchell ndmitchell at gmail.com
Fri Feb 13 05:43:06 EST 2009


Hi

> 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

Why not:

substituteValue :: String -> Value -> Tree -> Tree
substituteValue x y = substitute (table1 x y)

> 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.

Languages like C++ and Java allow mutable state, object-orientated
programming and require massively verbose code - all of which are
unuseful and evil :-)

I think this is a case of trying to apply C++/Java thoughts on to
Haskell, you can map the concepts directly, but you really shouldn't.
Try writing multiple methods with many names, or simple utility
functions to convert between the cases, and it will go much nicer.

Thanks

Neil


More information about the Haskell-Cafe mailing list