| just a thought .. why is it that some declarations
| (data, type, newtype, class, instance) are only allowed
| at the (module) top level? in some cases i'd like to have
| more locality, and less namespace pollution.
Let me add: local declaration might also increase the expressibility of
Haskell! So it's not merely about name space pollution. Haskell's type class
system is currently limited in that it is not possible to create a
dictionary that depends on dynamic values. Let me give an example:
there are two ways of defining a generic sorting routine.
> sort :: (Ord a) => [a] -> [a]
> sortBy :: Rel a -> [a] -> [a]
> type Rel a = a -> a -> Bool
As it stands `sortBy' is more general than `sort': I can define `sort'
in terms of `sortBy' but not the other way round. [However, sometimes
it is far more convenient to implement `sort' than `sortBy'.]
> sort = sortBy (<=)
If local instance declarations were admissable I could possibly write
... lots of hand-waving ...
> sortBy (rel :: Rel a) = sort where instance Ord a where (<=) = rel
Hmm. That may look dauting but could possibly be put to work.
JUST A THOUGHT
Cheers, Ralf