[Haskell-cafe] Re: how would this be done? type classes? existential types?

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Fri Mar 17 12:12:11 EST 2006


Matthias Fischmann wrote:
> On Thu, Mar 16, 2006 at 12:40:00PM +0000, Chris Kuklewicz wrote:
>> (Why isn't it "resourceName :: String" ?)
> 
> when i am trying this, ghc complains that the type of resourceName
> doesn't have any occurrance of 'a', and i feel that it must be harder
> for the type engine to figure things out if there isn't, so
> resourceName is still a mapping from resources to their names.

Yes, if you had

     resourceName :: forall a. Resource a => String

then there'd be nothing to prevent the expression (resourceName :: String) 
from evaluating to any resource name in any context.

A trick you can pull is to define

     data Proxy a = Proxy

and give resourceName's parameter the type Proxy a instead of a. This makes 
it clear that it's only the type you care about, not the value. The downside 
is that it tends to be less convenient to use, which is presumably why 
standard library functions with this problem (like floatRadix and sizeOf) 
don't use this solution.

-- Ben



More information about the Haskell-Cafe mailing list