[Haskell-cafe] Local types
m.farkasdyck at gmail.com
Mon Jan 25 08:11:07 UTC 2016
I often wish to be able to define local types and instances, so, for example:
import Data.Set as Set
ordNubBy :: (a -> a -> Ordering) -> [a] -> [a]
ordNubBy cmp = go Set.empty
where newtype T = T a
instance Ord T where T x `compare` T y = cmp x y
go _  = 
go ys (x:xs) = bool (x:) id (T x ∈ ys) $ go (Set.insert (T x) ys) xs
The notion is that type and instance declarations would become legal in `let` or `where` bonds; they would effectively declare new types and instances in that scope for each use of that term; and such local types and instances could never leave the scope they were defined in, by enforcement, so consistency of instances would be preserved.
I know some related work which proposes local instances  but none i know proposes also local types.
I'm seeking some feedback here before i formalize further and potentially start making implements. Thoughts? Questions? Better ideas? Critical flaws?
More information about the Haskell-Cafe