Proposal for local data declarations / instances

2019-03-14 11:51发布

I'm curious, and have been unable to find a proposal for something like this in Haskell. Consider if sort had been written but not sortBy.

sortBy :: forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy f = map getX . sort . map X
    where
    newtype X = X { getX :: a }
    instance Ord X where
        compare (X a) (X b) = f a b

Has anyone seen this proposal?

1条回答
萌系小妹纸
2楼-- · 2019-03-14 12:20

Apparently, local instances have been discussed briefly at Haskell Prime mailing list: http://web.archiveorange.com/archive/v/eKcS7T2qBpy7czBE2Jei, and more fully in the 6th chapter of Oleg’s paper “Functional Pearl: Implicit Configurations”. I have heard practically nothing about local data declarations, though.

查看更多
登录 后发表回答