<div dir="ltr"><div class="gmail_default" style="font-size:large"><br></div><br><div class="gmail_quote"><div dir="ltr">---------- Forwarded message ---------<br>From: <b class="gmail_sendername" dir="auto">Damien Mattei</b> <span dir="ltr"><<a href="mailto:damien.mattei@gmail.com">damien.mattei@gmail.com</a>></span><br>Date: Sat, Dec 29, 2018 at 9:46 AM<br>Subject: IO monad use<br>To: Damien MATTEI <<a href="mailto:damien.mattei@gmail.com">damien.mattei@gmail.com</a>><br></div><br><br><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="font-size:large">again an annoying error with my code, i want to apply sort of MAP on  list resut of my database IO accessed extracting info with another query, queries works both but i can not MAP or if i can i do not know how to SHOW the result, here is the code:</div><div style="font-size:large"><br></div><div style="font-size:large"> lstNamesBD <- mapM (\(Only name) -><br>                               do<br>                                let nameStr = Text.unpack name<br>                                bd <- getBD conn nameStr<br>                                (nameStr,bd))<br>                       names<br></div><div style="font-size:large"><br></div><div style="font-size:large">it fails to compile with this error:</div><div style="font-size:large"><br></div><div style="font-size:large">Prelude> :load UpdateSidonie<br>[1 of 1] Compiling Main             ( UpdateSidonie.hs, interpreted )<br><br>UpdateSidonie.hs:203:33: error:<br>    • Couldn't match type ‘(,) String’ with ‘IO’<br>      Expected type: IO (Maybe Float)<br>        Actual type: (String, Maybe Float)<br>    • In a stmt of a 'do' block: (nameStr, bd)<br>      In the expression:<br>        do let nameStr = unpack name<br>           bd <- getBD conn nameStr<br>           (nameStr, bd)<br>      In the first argument of ‘mapM’, namely<br>        ‘(\ (Only name)<br>            -> do let nameStr = ...<br>                  bd <- getBD conn nameStr<br>                  (nameStr, bd))’<br>    |<br>203 |                                 (nameStr,bd))<br>    |                                 ^^^^^^^^^^^^<br>Failed, no modules loaded.<br></div><div style="font-size:large"><br></div><div style="font-size:large"><br></div><div style="font-size:large">if i code like this  show does not know how to display result:</div><div style="font-size:large"><br></div><div style="font-size:large"> let lstNamesBD = Prelude.map (\(Only name) -><br>                                         do<br>                                          let nameStr = Text.unpack name<br>                                          bd <- getBD conn nameStr<br>                                          res <- (nameStr,bd)<br>                                          res)<br>                                 names</div><div style="font-size:large"><br></div><div style="font-size:large"> putStr "lstNamesBD ="<br> putStrLn $ show lstNamesBD</div><div style="font-size:large"><br></div><div style="font-size:large">*Main> :load UpdateSidonie<br>[1 of 1] Compiling Main             ( UpdateSidonie.hs, interpreted )<br><br>UpdateSidonie.hs:193:16: error:<br>    • No instance for (Show (IO (Maybe Float)))<br>        arising from a use of ‘show’<br>    • In the second argument of ‘($)’, namely ‘show lstNamesBD’<br>      In a stmt of a 'do' block: putStrLn $ show lstNamesBD<br>      In the expression:<br>        do conn <- connect<br>                     defaultConnectInfo<br>                       {connectHost = "moita", connectUser = "mattei",<br>                        connectPassword = "sidonie2", connectDatabase = "sidonie"}<br>           (rows :: [(Text, Double)]) <- query_<br>                                           conn<br>                                           "SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278"<br>           (names :: [Only Text]) <- query_<br>                                       conn<br>                                       "SELECT Nom FROM AngularDistance WHERE distance > 0.000278"<br>           let resLstNames = Prelude.map fromOnly names<br>           ....<br>    |<br>193 |     putStrLn $ show lstNamesBD<br>    |                ^^^^^^^^^^^^^^^<br>Failed, no modules loaded.<br></div><div style="font-size:large"><br></div><div style="font-size:large">help me please<br></div></div></div></div></div></div></div>
</div></div>