From: Marc W. <mar...@gm...> - 2008-04-07 21:38:50
|
What aboou tadding something like the following to the distribution ? ============= ======================================================= module GetRows where import Control.Monad import Database.HSQL fieldNames :: Statement -> [ String ] fieldNames = (map (\(a,_,_) -> a)) . getFieldsTypes getRow2 :: (SqlBind a, SqlBind b) => (a -> b -> r) -> Statement -> IO r getRow2 f stmt = let fNs = fieldNames stmt in liftM2 f (getFieldValue stmt (fNs !! 0)) (getFieldValue stmt (fNs !! 1)) getRow3 :: (SqlBind a, SqlBind b, SqlBind c) => (a -> b -> c -> r) -> Statement -> IO r getRow3 f stmt = let fNs = fieldNames stmt in liftM3 f (getFieldValue stmt (fNs !! 0)) (getFieldValue stmt (fNs !! 1)) (getFieldValue stmt (fNs !! 2)) getRow4 :: (SqlBind a, SqlBind b, SqlBind c, SqlBind d) => (a -> b -> c -> d -> r) -> Statement -> IO r getRow4 f stmt = let fNs = fieldNames stmt in liftM4 f (getFieldValue stmt (fNs !! 0)) (getFieldValue stmt (fNs !! 1)) (getFieldValue stmt (fNs !! 2)) (getFieldValue stmt (fNs !! 3)) [...] ============= ======================================================= That's not a perfect implementation but it allows you to write just: rows = collectRows (getRow3 (,,)) stmt Sincerly Marc Weber |