<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>