[Haskell-cafe] Type problem with simple takusen code (was: Trivialdatabase access in Haskell)

Bayley, Alistair Alistair_Bayley at invescoperpetual.co.uk
Tue Dec 12 10:43:37 EST 2006


> main :: IO ()
> main = do
>    withSession (connect "USER" "PASSWORD" "DB") $ do
>      -- simple query, returning reversed list of rows.
>      r <- doQuery (sql "select username from all_users") 
> query1Iteratee []
>      liftIO $ putStrLn $ show r
> 
> 
> The error I'm getting is
> 
> db.hs:10:64:
>     Couldn't match expected type `forall mark. DBM mark Session a'
>            against inferred type `a1 b'
>     In the second argument of `($)', namely
>         `do r <- doQuery
>                    (sql "select username from all_users") 
> ...


This is a fault in the example. Try this:

>    -- ($) replaced here with ()
>    withSession (connect "USER" "PASSWORD" "DB") ( do
>      r <- doQuery (sql ...
>      liftIO $ putStrLn $ show r  --- here should be OK
>     )

($) doesn't handle higher-ranked types, and overusing it can lead to
these kinds of errors.

Alistair
*****************************************************************
Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.
*****************************************************************


More information about the Haskell-Cafe mailing list