<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:large">yes it works, i had not set the return</div><div class="gmail_default" style="font-size:large">in the mapM version, that's my problem with i too often throw dices, do not know why its mapM or map that works, i put a return in a deseperate moment.... :-)</div><div class="gmail_default" style="font-size:large">still learning monads, find this that explain the concept:</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><a href="http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html#translations">http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html#translations</a></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">and this but just at the beginning i am:</div><div class="gmail_default" style="font-size:large"><a href="https://wiki.haskell.org/All_About_Monads">https://wiki.haskell.org/All_About_Monads</a></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">thanks again for your help</div><div class="gmail_default" style="font-size:large">Damien<br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 29, 2018 at 11:51 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">Why are you using map? You were right the first time with mapM:<br>
<br>
lstNamesBD <- mapM (\(Only name) -><br>
do<br>
let nameStr = Text.unpack name<br>
bd <- getBD conn nameStr<br>
return (nameStr,bd))<br>
names<br>
<br>
On Sat, Dec 29, 2018 at 11:42:05AM +0100, Damien Mattei wrote:<br>
> thank you tom,<br>
> in fact reading doc as i saw i never used return read in monad doc i<br>
> already put it in my code this gives this that compiles:<br>
> let lstNamesBD = Prelude.map (\(Only name) -><br>
> do<br>
> let strName = Text.unpack name<br>
> getBD conn strName >>= (\bd -><br>
> <br>
> return (strName,bd)))<br>
> names<br>
> <br>
> but sticked now for displaying it because it is now an IO tuple of 2 and i<br>
> can not display it with some functions like this , it fails to compile:<br>
> <br>
> -- 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>
> <br>
> or with that tested first:<br>
> <br>
> 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>
> <br>
> On Sat, Dec 29, 2018 at 11:30 AM Tom Ellis <<br>
> <a href="mailto:tom-lists-haskell-cafe-2017@jaguarpaw.co.uk" target="_blank">tom-lists-haskell-cafe-2017@jaguarpaw.co.uk</a>> wrote:<br>
> <br>
> > 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<br>
> > 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<br>
> > 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.<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>