|Version 2 (modified by ross@…, 10 years ago) (diff)|
Scoped Type Variables
Type annotations, which Haskell 98 allows in expressions, are also allowed in patterns and (currently in GHC only) in result type signatures, attached to the left side of a function definition. New type variables in these annotations scope over the function body, permitting locally defined variables to be given signatures in situations where it would be impossible in Haskell 98, e.g.
sortImage :: Ord b => (a -> b) -> [a] -> [a] sortImage (f::a->b) = sortBy cmp where cmp :: a -> a -> Ordering cmp x y = compare (f x) (f y)
Note that although GHC and Hugs use the same syntax, the meaning of type variables is quite different, and there are other differences too.