Language extension proposal

Simon Peyton-Jones
Mon, 30 Jun 2003 09:12:54 +0100

If you have a class like this

	class FloatTraits a where
	  mantissa :: Int

then the type of mantissa is

	mantissa :: forall a. FloatTraits a =3D> 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
	sequence :: forall (m:*->*) (a:*).  [m a] -> m [a]
	data STB a s =3D s -> (a,s)		-- Oops: got the
parameters backwards

	....sequence<\b. ST b MyState, Int>...


| -----Original Message-----
| From: [] On
Behalf Of Ashley Yakeley
| Sent: 28 June 2003 00:25
| To:
| Subject: Re: Language extension proposal
| In article <>,
|  Andrew J Bromage <> wrote:
| > Another example is floating point format information, like the
| > information in C's <float.h>.  One might implement this as:
| >
| > 	class (Bounded a) =3D> 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 =3D MkType
|  getType :: a -> Type a
|  getType _ =3D MkType
|  class (Bounded a) =3D> FloatTraits a where
|    epsilon :: a
|    mantissaDigits :: Type a -> Int
| The only annoyance is that you frequently have to write (MkType ::
| MyFloat). Syntactic sugar for _that_ would be useful.
| --
| Ashley Yakeley, Seattle WA
| _______________________________________________
| Haskell mailing list