Language extension proposal

Ralf Laemmel Ralf.Laemmel@cwi.nl
Sat, 28 Jun 2003 11:51:47 +0200


Ashley Yakeley wrote:

> 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

Suffering from persecution mania,
I prefer to know for sure that nobody never ever will 
pattern match on those a's. So I prefer to write:


-- Values serving as type arguments
type TypeArg a = a -> ()

-- Constant function as type argument
typeArg :: TypeArg a
typeArg = const ()        

-- Extract type argument from value
getTypeArg :: a -> TypeArg a 
getTypeArg _ = typeArg


I start to use this style more agressively in Strafunski
and the boilerplate gmaps. 

A side remark: Data.Dynamic does NOT use this style but rather
Ashley's:

...
typeOf :: a -> TypeRep
...

which is a pitty because there is nothing in the type which
prevents you from looking at a; its only in the comments.
Every now and then I get this wrong.
 
> The only annoyance is that you frequently have to write (MkType :: Type
> MyFloat). Syntactic sugar for _that_ would be useful.

On the other hand, supporting the above style with TypeArg's 
by an ADT, would make the whole thing entirely safe and transparent.


-- 
Ralf Laemmel
VU & CWI, Amsterdam, The Netherlands
http://www.cs.vu.nl/~ralf/
http://www.cwi.nl/~ralf/