[Haskell-cafe] Re: Foralls in records
Martin Huschenbett
huschi at gmx.org
Wed Mar 14 05:04:42 EDT 2007
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
More information about the Haskell-Cafe
mailing list