21

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?

luqui
  • 59,485
  • 12
  • 145
  • 204
  • 4
    For what it's worth, you can achieve this with the [reflection](http://hackage.haskell.org/package/reflection) functional pearl/package; see [this example](https://github.com/ekmett/reflection/blob/master/examples/Monoid.hs). (Full disclosure: I have commits in the package.) – ehird Mar 10 '13 at 11:39
  • 4
    As much as I love this idea (and have wanted the same thing in the past), I'm not sure this is a real question... – Ben Millwood Mar 10 '13 at 12:10
  • 2
    I'm not proposing; I was fairly sure it would have been proposed before but I couldn't find it. An acceptable answer would be one that points to a discussion of this or a similar proposal, or one from someone involved in this aspect of the community saying "I haven't seen one; here are some related things though." Does that constitute a real question? – luqui Mar 10 '13 at 20:11
  • 1
    @luqui: I suppose so, but you could do with clarifying this in the question a little – your title is certainly a little misleading :) – Ben Millwood Mar 21 '13 at 13:27

1 Answers1

1

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.

Emily
  • 2,577
  • 18
  • 38