
query returns a list i suppose because i can wirte this in my main code: bd_rows <- query conn qry_head (Only (name::String)) putStrLn $ show bd_rows putStrLn $ show name let resLst = Prelude.map fromOnly bd_rows i can o a map on bd_rows i just want to convert this code in Main: let qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = ?" :: Query -- bd_rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom = 'A 20'" bd_rows <- query conn qry_head (Only (name::String)) putStrLn $ show bd_rows putStrLn $ show name let resLst = Prelude.map fromOnly bd_rows let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text -- let noBD2 = _ (Prelude.head bd_rows) putStrLn $ show resLst putStrLn $ show noBDtxt forM_ bd_rows $ \(Only a) -> putStrLn $ Text.unpack a let noBDstr = Text.unpack noBDtxt :: String let noBDfp = read $ noBDstr :: Float where i succeed in putting the Float extracted and converted from the result of query in a variable of type Float, i want to have this in function getBD that take as arguments the Connection and the String name ,i use name in the SQL query and get back the noBD in text first ,string and finally float... this should be done,i assume it is possible in haskell but i'm a beginner.... i have problem finding good doc ,understanding Monads ans '<-' use and 'do' but i assume the solution is perhaps trivial... Le 10/12/2018 12:19, Francesco Ariis a écrit :
Hy Damien,
On Mon, Dec 10, 2018 at 11:32:23AM +0100, Damien Mattei wrote:
i want the variable local_bd_rows accessible in the 'where' clause
does `query` return IO ()? If so, no you can't*. Once the result is inside IO, it stays in IO. Move what you need inside out of where (and inside a `do`) and get ready to change the signature of `getBD` to
getBD :: Connection -> String -> IO Float
-F
* (you can with unsafeSomething functions, but it is really really advisable not to do that). _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Damien.Mattei@unice.fr, Damien.Mattei@oca.eu, UNS / OCA / CNRS