Have you tested your tutorial program? #10

Open
qzchenwl opened this Issue Dec 16, 2011 · 1 comment

1 participant

@qzchenwl
someNumHandler :: Handler App App ()
someNumHandler = do
  mnum <- getParam "num"
  let n = fromMaybe 11 mnum
  msgs <- getMessages n
  writeBS . pack $ show msgs

Type error:
let n = fromMaybe 11 mnum

@qzchenwl

Another strange problem.

This compiles

instance HasHdbc (Handler App App) Connection where
  getPool = with db $ gets hdbcPool

This doesn't

instance HasHdbc (Handler App App) Connection IO where
  getConnSrc = with dbLens $ gets connSrc

The strange point is that the type class is defined as

class  (IConnection c, ConnSrc s, MonadControlIO m)
  =>   HasHdbc m c s | m -> c s where
  getConnSrc :: m (s c)

I get getPool from the comment

-- | Instantiate this typeclass on 'Handler b YourSnapletState' so this snaplet
-- can find the resource pool. Typically you would instantiate it for Snap's
-- Handler type and use your snaplet's lens to this snaplet to access this
-- snaplet's state, which contains the pool. Suppose your snaplet state type is
-- defined as follows, where 'Connection' is the connection type from the HDBC
-- database adapter of your choosing:
--
-- > data App = App
-- >  { _dbLens :: Snaplet (HdbcSnaplet Connection) }
--
-- Then a typical instance you will want to define in your own snaplet is the
-- following:
--
-- > instance HasHdbc (Handler b App) Connection where
-- >   getPool = with dbLens $ gets hdbcPool
--
class  (IConnection c, ConnSrc s, MonadControlIO m)
  =>   HasHdbc m c s | m -> c s where
  getConnSrc :: m (s c)

How to understand this behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment