> I think the way that Hugs 1.3c handles it would meet your goals.  All that
> it requires is a strict extension to the syntax for patterns to allow type
> annotations.  These can be useful in their own right, but also can be
> applied
> to problems like the one that you gave:
> 
>   f :: [a] -> a -> [a]
>   f ((x::a):xs) y = g y
>          where
>            g :: a -> [a]
>            g q = [x,q]
> 
> The only change I've made here is to replace "x" on the left hand side of
> the definition for f with "(x::a)".  As a result, the type variable "a"
> will be in scope when the signature of g is encountered, and so will not
> be subjected to the usual, implicit universal quantification.

The monomorphism discussion highlighted a disadvantage with
the pattern notation for scoped type variables that I hadn't realised
before.  Michael suggested

  
 f :: [a] -> c
 f xs = if len > fromInteger 3 then len else 0
      where
          len :: c
          len = length xs

This relies on the 'c' from the type signature scoping over
the definition, which is on alternative notation for scoped
type variables.  On the whole I think the 'put signatures in patternss'
approach is nicer, but I don't think it can express this example,
because the relevant type is (only) in the result.  Maybe it's
Just Too Bad, but it is a pity.


Simon


Reply via email to