[Haskell-cafe] Overloading functions based on arguments?

Eugene Kirpichov ekirpichov at gmail.com
Fri Feb 13 05:25:27 EST 2009


class Foobar a b where
  foobar :: a -> b -> Int

instance Foobar String Int where ...
instance Foobar Int String where ...

2009/2/13 Daniel Kraft <d at domob.eu>:
> Hi,
>
> I just came across a problem like this:  Suppose I've got two related
> functions that do similar things, and I want to call them the same... Like
> in:
>
> foobar :: String -> Int -> Int
> foobar :: Int -> String -> Int
>
> (Bad example, but I hope you got the point.)
>
> Is this kind of overloading (instead of the polymorphism based overloading)
> possible in Haskell?  Namely to have two functions with the same name but
> different signatures so they could be distinguished by a call's parameters?
>  I fear not...  So I guess I have to name the functions differently, right?
>
> Thanks,
> Daniel
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list