<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:large">thank you tom,</div><div class="gmail_default" style="font-size:large">in fact reading doc as i saw i never used return read in monad doc i already put it in my code this gives this that compiles:</div><div class="gmail_default" style="font-size:large"> let lstNamesBD = Prelude.map (\(Only name) -><br>                                        do<br>                                         let strName = Text.unpack name<br>                                         getBD conn strName >>= (\bd -><br>                                                                      return (strName,bd)))<br>                                names<br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">but sticked now for displaying it because it is now an IO tuple of 2 and i can not display it with some functions like this , it fails to compile:</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">--   putStr "lstNamesBD ="<br>--   putStrLn $ show lstNamesBD<br><br>   forM_ lstNamesBD $ \t2 -><br>         do<br>           n <- fst t2<br>           b <- snd t2<br>           putStrLn $ (show n) ++ " " ++ maybe "NULL" show b<br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">or with that tested first:</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"> forM_ lstNamesBD $ \(name,bd) -><br>           putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd<br>Prelude> :load UpdateSidonie<br>[1 of 1] Compiling Main            ( UpdateSidonie.hs, interpreted )<br><br>UpdateSidonie.hs:207:22: error:<br>   • Couldn't match expected type ‘(IO a1, b0)’<br>                 with actual type ‘IO (String, Maybe Float)’<br>   • In the first argument of ‘fst’, namely ‘t2’<br>     In a stmt of a 'do' block: n <- fst t2<br>     In the expression:<br>       do n <- fst t2<br>          b <- snd t2<br>          putStrLn $ (show n) ++ " " ++ maybe "NULL" show b<br>   |<br>207 |            n <- fst t2<br>   |                     ^^<br><br>UpdateSidonie.hs:208:22: error:<br>   • Couldn't match expected type ‘(a0, IO (Maybe a2))’<br>                 with actual type ‘IO (String, Maybe Float)’<br>   • In the first argument of ‘snd’, namely ‘t2’<br>     In a stmt of a 'do' block: b <- snd t2<br>     In the expression:<br>       do n <- fst t2<br>          b <- snd t2<br>          putStrLn $ (show n) ++ " " ++ maybe "NULL" show b<br>   |<br>208 |            b <- snd t2<br>   |                     ^^<br><br>UpdateSidonie.hs:211:25: error:<br>   • Couldn't match expected type ‘IO (String, Maybe Float)’<br>                 with actual type ‘(a3, Maybe a4)’<br>   • In the pattern: (name, bd)<br>     In the second argument of ‘($)’, namely<br>       ‘\ (name, bd)<br>          -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd’<br>     In a stmt of a 'do' block:<br>       forM_ lstNamesBD<br>         $ \ (name, bd)<br>             -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd<br>   |<br>211 |    forM_ lstNamesBD $ \(name,bd) -><br>   |                        ^^^^^^^^^<br>Failed, no modules loaded.<br>Prelude> <br><br></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 29, 2018 at 11:30 AM Tom Ellis <<a href="mailto:tom-lists-haskell-cafe-2017@jaguarpaw.co.uk">tom-lists-haskell-cafe-2017@jaguarpaw.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I guess you want<br>
<br>
  return (nameStr, bd)<br>
<br>
Every statement in a do-block must be of type `IO a` for some `a`. <br>
`(nameStr, bd)` is a pure value of type `(String, Maybe Float)`. You turn<br>
it into a value of type `IO (String, Maybe Float)` using `return`.<br>
<br>
Tom<br>
<br>
On Sat, Dec 29, 2018 at 10:08:32AM +0100, Damien Mattei wrote:<br>
> ---------- Forwarded message ---------<br>
> From: Damien Mattei <<a href="mailto:damien.mattei@gmail.com" target="_blank">damien.mattei@gmail.com</a>><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" target="_blank">damien.mattei@gmail.com</a>><br>
> <br>
> <br>
> again an annoying error with my code, i want to apply sort of MAP on list<br>
> resut of my database IO accessed extracting info with another query,<br>
> queries works both but i can not MAP or if i can i do not know how to SHOW<br>
> the result, here is the code:<br>
> <br>
>Â lstNamesBD <- mapM (\(Only name) -><br>
>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â do<br>
>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â let nameStr = Text.unpack name<br>
>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â bd <- getBD conn nameStr<br>
>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (nameStr,bd))<br>
>Â Â Â Â Â Â Â Â Â Â Â Â names<br>
> <br>
> it fails to compile with this error:<br>
> <br>
> 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>
> <br>
> <br>
> if i code like this show does not know how to display result:<br>
> <br>
>Â 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<br>
> <br>
>Â putStr "lstNamesBD ="<br>
>Â putStrLn $ show lstNamesBD<br>
> <br>
> *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 =<br>
> "sidonie"}<br>
>Â Â Â Â Â Â (rows :: [(Text, Double)]) <- query_<br>
>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â conn<br>
>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "SELECT Nom,distance FROM<br>
> AngularDistance WHERE distance > 0.000278"<br>
>Â Â Â Â Â Â (names :: [Only Text]) <- query_<br>
>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â conn<br>
>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "SELECT Nom FROM AngularDistance<br>
> 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>
> <br>
> help me please<br>
<br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> To (un)subscribe, modify options or view archives go to:<br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
> Only members subscribed via the mailman list are allowed to post.<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>