Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have you tested your tutorial program? #10

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

Have you tested your tutorial program? #10

qzchenwl opened this issue Dec 16, 2011 · 1 comment

Comments

@qzchenwl
Copy link

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
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant