Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proposal for local data declarations / instances

Tags:

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?

like image 538
luqui Avatar asked Mar 10 '13 08:03

luqui


1 Answers

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.

like image 154
Artyom Avatar answered Sep 28 '22 19:09

Artyom