Language extension proposal
Simon Peyton-Jones
simonpj@microsoft.com
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
explicitly.
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>...
Simon
| -----Original Message-----
| From: haskell-admin@haskell.org [mailto:haskell-admin@haskell.org] On
Behalf Of Ashley Yakeley
| Sent: 28 June 2003 00:25
| To: haskell@haskell.org
| Subject: Re: Language extension proposal
|=20
| In article <20030625041751.GA29774@smtp.alicorna.com>,
| Andrew J Bromage <ajb@spamcop.net> wrote:
|=20
| > 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!
|=20
| Oh I do this all the time in HBase. I simply do this:
|=20
| data Type a =3D MkType
|=20
| getType :: a -> Type a
| getType _ =3D MkType
|=20
| class (Bounded a) =3D> FloatTraits a where
| epsilon :: a
| mantissaDigits :: Type a -> Int
|=20
| The only annoyance is that you frequently have to write (MkType ::
Type
| MyFloat). Syntactic sugar for _that_ would be useful.
|=20
| --
| Ashley Yakeley, Seattle WA
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org
| http://www.haskell.org/mailman/listinfo/haskell