More Haskell Blue Sky: Partial Type Annotations

John Meacham john@repetae.net
Thu, 11 Apr 2002 12:55:51 -0700


I actually have wanted a similar thing at times, the proposal I had in
mind was a bit less drastic, simply allow '_' in type signatures which
will unify with any arbitrary type. that way you can give any function
the type 
f :: _ -> _
or if you just want to resstrict part of the type you could say
f :: _ -> Int 
or something like that.

This gives you most of what your proposal does but doesnt break existing
programs. the main thing it doesnt allow would be stating that two types
are equivalant, yet unconstrained otherwise. such as f :: a -> a   for
instance. note that i would love it if forall and exists were made
explicit, but it is a bit late for that, at least without breaking
things.
	John


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

-- 
---------------------------------------------------------------------------
John Meacham - California Institute of Technology, Alum. - john@repetae.net
---------------------------------------------------------------------------