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

George Pollard porges at porg.es
Fri Feb 13 05:48:44 EST 2009


On Fri, 2009-02-13 at 11:40 +0100, Daniel Kraft 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

You can write it like this:

  class Substitutable a where
  	substitute :: a -> Tree -> Tree

  instance Substitutable Table where ...
  instance Substitutable (String, Value) where ...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090213/c72aa156/attachment.bin


More information about the Haskell-Cafe mailing list