Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-18 Thread Tom Ellis
On Sun, Aug 18, 2013 at 10:16:06PM +0200, Hartmut Pfarr wrote:
> I played a bit with your suggestion, and it is running now :-)
> But instead of  IO [Int]  I think we need  IO [Only Int]   because
> of the 1-element-tupel problem?

Yes you're right.  I had forgotten that postgresql-simple dealt with
single-column tables with "Only".  Well done for getting it working!

Tom

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


Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-18 Thread Hartmut Pfarr

Hi Tom,
I played a bit with your suggestion, and it is running now :-)
But instead of  IO [Int]  I think we need  IO [Only Int]   because of 
the 1-element-tupel problem?


With   IO [Only Int]   it looks like this:

---
{-# LANGUAGE OverloadedStrings #-}

import Database.PostgreSQL.Simple

myconn :: ConnectInfo
myconn = defaultConnectInfo {
connectUser = "test",
connectPassword = "test",
connectDatabase = "test"}

main :: IO ()
main = do
  c <- connect myconn :: IO Connection
  rs <- query_ c "select 2 + 2" :: IO [Only Int]
  putStrLn $ "Result from database " ++ show (fromOnly $ head rs)
  return ()
---

Best regards
Hartmut

On 08/18/2013 12:11 AM, Tom Ellis wrote:

On Sat, Aug 17, 2013 at 11:59:24PM +0200, Hartmut Pfarr wrote:

{-# LANGUAGE OverloadedStrings #-}

import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple.FromRow

hello :: (FromRow a) => IO [a]
hello = do
   conn <- connect defaultConnectInfo
   query_ conn "select 2 + 2"


Either

 main = print =<< (hello :: IO [Int])

or give hello a monomorphic type signature, such as

 hello :: IO [Int]

Tom

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




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


Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Hartmut Pfarr

... thx all for helping. Now the coding works: it puts the following out.
Kind regards
Hartmut


*Main> main
Only {fromOnly = 4}
--
Only {fromOnly = 101}
Only {fromOnly = 102}
Only {fromOnly = 103}
--
blub 101 51
blub 102 52
blub 103 53


The Coding is:

-- PostgreSQL-Simple test

{-# LANGUAGE OverloadedStrings #-}

import Database.PostgreSQL.Simple
import Data.Foldable
import qualified Data.Text as Text

myconn :: ConnectInfo
myconn = defaultConnectInfo {
connectUser = "test",
connectPassword = "test",
connectDatabase = "test"}

db_calc :: (FromRow a) => IO [a]
db_calc = do
  conn <- connect myconn
  query_ conn "select 2 + 2"

hr :: IO ()
hr = putStrLn "--"

main :: IO ()
main = do
  conn <- connect myconn

  -- Let Database calculate 2+2
  x1 <- db_calc
  forM_ x1 $ \h ->
putStrLn $ show (h :: Only Int)

  -- Select single integer column
  hr; x2 <- query_ conn "select aaa from aaa"
  forM_ x2 $ \(col1) ->
putStrLn $ show (col1 :: Only Int)

  -- select integer and text columns together
  hr; x3 <- query_ conn "select aaa,bbb,textcol from aaa"
  forM_ x3 $ \(int_col_1,int_col_2,text_col_3) ->
putStrLn $
  Text.unpack text_col_3 ++ " "
  ++ show (int_col_1 :: Int) ++ " "
  ++ show (int_col_2 :: Int)

  return ()



On 08/18/2013 12:12 AM, Brandon Allbery wrote:

On Sat, Aug 17, 2013 at 5:59 PM, Hartmut Pfarr
mailto:[email protected]>> wrote:

   query_ conn "select 2 + 2"

I've no errors any more.
But: I don't see any result (for sure, it is not coeded yet)


Yes, because you're not capturing it; it's the return value from
`query_`, which you are throwing away above instead of capturing with
some kind of `res <- query_ ...`. Again, see that section of the
documentation I pointed to for how to get results.

--
brandon s allbery kf8nh   sine nomine associates
[email protected]  [email protected]

unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net



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


Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Brandon Allbery
On Sat, Aug 17, 2013 at 5:59 PM, Hartmut Pfarr
wrote:

>   query_ conn "select 2 + 2"
>
> I've no errors any more.
> But: I don't see any result (for sure, it is not coeded yet)
>

Yes, because you're not capturing it; it's the return value from `query_`,
which you are throwing away above instead of capturing with some kind of
`res <- query_ ...`. Again, see that section of the documentation I pointed
to for how to get results.

-- 
brandon s allbery kf8nh   sine nomine associates
[email protected]  [email protected]
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
___
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Tom Ellis
On Sat, Aug 17, 2013 at 11:59:24PM +0200, Hartmut Pfarr wrote:
> {-# LANGUAGE OverloadedStrings #-}
> 
> import Database.PostgreSQL.Simple
> import Database.PostgreSQL.Simple.FromRow
> 
> hello :: (FromRow a) => IO [a]
> hello = do
>   conn <- connect defaultConnectInfo
>   query_ conn "select 2 + 2"

Either

main = print =<< (hello :: IO [Int])

or give hello a monomorphic type signature, such as 

hello :: IO [Int]

Tom

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


Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Hartmut Pfarr

Thx, I changed now from query to query_
Now the coding is like that:


{-# LANGUAGE OverloadedStrings #-}

import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple.FromRow

hello :: (FromRow a) => IO [a]
hello = do
  conn <- connect defaultConnectInfo
  query_ conn "select 2 + 2"

main = return ()


I've no errors any more.
But: I don't see any result (for sure, it is not coeded yet)

I need some help to get data from "hello" via "FromRow" into the main 
function.


E.g. I want to put the "hello" database result (the number "4") to the 
screen.


Could anybody give an advice how I can accomplish this?

Kind regards
Hartmut


On 08/17/2013 07:53 PM, Brandon Allbery wrote:

On Sat, Aug 17, 2013 at 1:35 PM, Hartmut Pfarr
mailto:[email protected]>> wrote:

(The example is identical to the first 5-liner-example in the
package documentation)


As I read it, the example has a typo: it should be using `query_`
instead of `query`. See
http://hackage.haskell.org/packages/archive/postgresql-simple/0.3.5.0/doc/html/Database-PostgreSQL-Simple.html#g:9
for detals.

--
brandon s allbery kf8nh   sine nomine associates
[email protected]  [email protected]

unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net



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


Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Brandon Allbery
On Sat, Aug 17, 2013 at 1:35 PM, Hartmut Pfarr
wrote:

> (The example is identical to the first 5-liner-example in the package
> documentation)
>

As I read it, the example has a typo: it should be using `query_` instead
of `query`. See
http://hackage.haskell.org/packages/archive/postgresql-simple/0.3.5.0/doc/html/Database-PostgreSQL-Simple.html#g:9for
detals.

-- 
brandon s allbery kf8nh   sine nomine associates
[email protected]  [email protected]
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
___
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe