snapframework / snap

Top-level package for the official Snap Framework libraries, includes the snaplets API as well as infrastructure for sessions, auth, and templates.
http://snapframework.com/
BSD 3-Clause "New" or "Revised" License
455 stars 68 forks source link

HasX classes for all snaplets #100

Closed mikeplus64 closed 10 years ago

mikeplus64 commented 10 years ago

For consistency and convenience, just as there is a HasHeist class, there should be classes for all snaplets, ie

-- I'm not sure if SnapletLens should be used, or why it's used at all.

class HasSession b where
  sessionLens :: Lens' b (Snaplet SessionManager)

class HasAuth b where
  authLens :: Lens' b (Snaplet (AuthManager b))
mightybyte commented 10 years ago

One of the general design principles we've taken with the Snap Framework as a whole is to minimize our use of type classes. A type class is essentially global state with information for a specific type. A design built around a HasAuth type class is implicitly saying that there can only be one method of auth for the type b. This made sense for Heist, but does not make sense for sessions and auth. It is easy to imagine situations where one would want more than one form of sessions or authentication, so we deliberately chose to not use type classes in these cases.