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

Conal Elliott conal at conal.net
Fri Feb 13 14:13:03 EST 2009


Hi Daniel,

A more functional approach might be:

    type Substitution = String -> Maybe Value
    single :: String -> Value -> Substitution
    table  :: Table -> Substitution

    substitute :: Substitution -> Tree -> Tree

For better performance and a lot more features, you could switch to

    type Substitution = Data.Map String Value

- Conal

On Fri, Feb 13, 2009 at 2:40 AM, Daniel Kraft <d at domob.eu> wrote:

> 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.
>
>
> Daniel
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090213/3bab0f41/attachment.htm


More information about the Haskell-Cafe mailing list