If you have a class like this class FloatTraits a where mantissa :: Int
then the type of mantissa is mantissa :: forall a. FloatTraits a => Int There's nothing wrong with this in principle; the difficulty is that when you say mantissa + 4 you aren't saying which float type to get the mantissa of. Earlier messages have outlined workarounds, but in some ways the "real" solution is to provide a syntax for type application. A polymorphic function should be applied to a type argument; these type arguments are always implicit in Haskell, but are explicit in System F. They are also explicit in O-O languages that support polymorphism. For example, in C++ one might say mantissa<Double> + 4 And in fact that's just what we *want* to say here. (The workarounds in earlier emails all amount to passing a *value* argument as a proxy for a type argument.) If we could only figure out a good syntax for (optional) type application, it would deal rather nicely with many of these cases. Trouble is, '<..>' gets confused with comparisons. And when there are multiple foralls, it's not obvious what order to supply the type parameters. It'd be useful in other situations too. For example, one could have lambdas at the type level, if one was willing to instantiate them explicitly. sequence :: forall (m:*->*) (a:*). [m a] -> m [a] data STB a s = s -> (a,s) -- Oops: got the parameters backwards ....sequence<\b. ST b MyState, Int>... Simon | -----Original Message----- | From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ashley Yakeley | Sent: 28 June 2003 00:25 | To: [EMAIL PROTECTED] | Subject: Re: Language extension proposal | | In article <[EMAIL PROTECTED]>, | Andrew J Bromage <[EMAIL PROTECTED]> wrote: | | > Another example is floating point format information, like the | > information in C's <float.h>. One might implement this as: | > | > class (Bounded a) => FloatTraits a where | > epsilon :: a -- OK | > mantissaDigits :: Int -- Not OK! | | Oh I do this all the time in HBase. I simply do this: | | data Type a = MkType | | getType :: a -> Type a | getType _ = MkType | | class (Bounded a) => FloatTraits a where | epsilon :: a | mantissaDigits :: Type a -> Int | | The only annoyance is that you frequently have to write (MkType :: Type | MyFloat). Syntactic sugar for _that_ would be useful. | | -- | Ashley Yakeley, Seattle WA | | _______________________________________________ | Haskell mailing list | [EMAIL PROTECTED] | http://www.haskell.org/mailman/listinfo/haskell _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell