ekmett / lens

Lenses, Folds, and Traversals - Join us on web.libera.chat #haskell-lens
http://lens.github.io/
Other
2.03k stars 273 forks source link

reorder parameters in makeClassy #625

Open lingnand opened 8 years ago

lingnand commented 8 years ago

Right now makeClassy generates class for parameterized data types like this

class HasContainer container param where
    ...

I think it's actually a better idea to reorder it such that

class HasContainer param container where

A few reasons:

  1. a convention is that later parameters are more important (the last one being the main parameter)
  2. then we can derive newtype like
data Container t = Container { _container :: Value t }
makeClassy ''Container

newtype NewContainer = NewContainer (Container t) deriving (HasContainer t)
louispan commented 8 years ago

I agree that the last type param it makes intuitive sense for the last type parameter to the 'container'. Is there a more mathematical/computer science/robust theory behind type parameter ordering?

ekmett commented 8 years ago

Getting newtype deriving would be kind of nice.

At this point the question is is the improvement worth breaking every single user of lens that makes use of makeClassy?

I don't think so at this time. Existing users would get all sorts of weird type errors.