More Haskell Blue Sky: Partial Type Annotations

Simon Peyton-Jones simonpj@microsoft.com
Thu, 11 Apr 2002 04:29:46 -0700


Already in GHC, and describe in our paper on scoped type variables:
	http://research.microsoft.com/~simonpj/papers/scoped-tyvar

Simon

| -----Original Message-----
| From: Ashley Yakeley [mailto:ashley@semantic.org]=20
| Sent: 11 April 2002 12:11
| To: Haskell List
| Subject: More Haskell Blue Sky: Partial Type Annotations
|=20
|=20
| I sometimes come across a situation when I only want to provide a=20
| _partial_ type annotation, perhaps because the full type has some=20
| variable unified with some variable in some other type annotation, or=20
| something. For instance:
|=20
|   f :: forall a. [a] -> [a] -> [a]
|   f x y =3D g x where
|     g [] =3D y
|     g (_:_) =3D x
|=20
| ...there doesn't seem to be a way of giving a type annotation=20
| for 'g'.=20
| Theoretically it's '[a] -> [a]', but where 'a' is the same as=20
| the 'a' in=20
| the type signature for 'f'.
|=20
| Under this proposal, unqualified type variables would be=20
| considered to be=20
| 'free' rather than implicitly forall-qualified. So for instance, any=20
| function could be given the partial type annotation 'a -> b'. For=20
| instance, all these annotations would be the same given this function:
|=20
|   k :: a
|   k :: a -> ba
|   k :: a -> b -> a
|   k :: forall b. a -> b -> a
|   k :: forall a b. a -> b -> a
|=20
|   k x y =3D x
|=20
| ...and these would both be the same, but different from the previous:
|=20
|   k' :: Int -> ba
|   k' :: forall b. Int -> b -> Int
|=20
|   k' x y =3D x
|=20
| And so we could write this:
|=20
|   f :: forall a. [a] -> [a] -> [a]
|   f x y =3D g x where
|     g :: [a] -> [a] -- partial annotation may be sufficient
|     g [] =3D y
|     g (_:_) =3D x
|=20
| I admit that's a bit of a change, and might break programs... In=20
| addition, it doesn't address the occasional need to tie type=20
| annotations=20
| together, something that has often made me add ugly dummy=20
| arguments used=20
| just for their type.
|=20
| --=20
| Ashley Yakeley, Seattle WA
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
|=20