Hi,

instead of writing a function getTransaction that retrieves the connection you could write a function withConnection that doesn't return the connection itself but performs an operation on the connection:

withConnection ::
        (forall c. Connection c => c -> Transaction a) -> Transaction a
withConnection f = Transaction (\t@(TransactionT c) ->
        let Transaction tf = f c in tf t)

Then execute becomes:

execute :: String -> Transaction ()
execute s = withConnection (\c -> connectionExecute c s)


Regards,
  Martin.


getConnection :: Transaction c
getConnection = Transaction (\t@(TransactionT c) -> (c, t))

class Connection c where
  connectionExecute :: c -> String -> Transaction ()

execute :: String -> Transaction ()
execute s = connectionExecute getConnection s

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to