Overloading and overlap

Daan Leijen daan at cs.uu.nl
Tue Apr 19 16:21:43 EDT 2005


Monique Louise wrote:

>   does anyone know about any existing extensions to FFI or even to
>GHC which incorporate access to overloaded methods, which are common
>in OO environments (.NET, Java), without using "renaming techniques" ?
>  
>
I think you refer here to "overloaded methods" in the sense of methods 
with the same name
in the same class with different argument types (a la Java, or C++). 

 > class C { void foo( Int i );  void foo (Float f ): }

Note that "under the hood"
even .NET and Java use different names for each method ("renaming") to 
distinguish them.

 > class C { void foo_Int( Int i); void foo_Float( Float f); }

This compiler assigns the unoverloaded name statically once the types of 
the arguments are
known. So, when using such methods from the Haskell FFI, I think you can 
only call into the
unoverloaded names.

 > foreign import dynamic c_foo_Int :: C -> Int -> IO ()
 > foreign import dynamic c_foo_Float :: C -> Float -> IO ()

I guess you can get the overloading again by using the usual Haskell
classes:

 > class C_foo  a  where  c_foo ::  C -> a -> IO ()
 > instance C_foo Int where c_foo = c_foo_Int
 > instance C_foo Float where c_foo = c_foo_Float

I don't know of any other solution , but you may want to read
Andre Pang's master thesis (under supervision of Manuel Chackravarty)
that might have some content about this.

All the best,
 Daan Leijen.


>Thanks in advance,
>
>  
>



More information about the FFI mailing list