<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:large">yes i use do notation, but for example i have code that works in main and not in a function!</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">i print the code perheaps someone could help me:</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">first the function, so you have the import list too:</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">import Database.MySQL.Simple<br>import Database.MySQL.Simple.QueryResults<br>import Database.MySQL.Simple.Result<br><br>import Database.MySQL.Simple.QueryParams<br>import Database.MySQL.Simple.Param<br><br><br>import Control.Monad<br><br>import Data.Text as Text<br>--import Data.Int as Int<br>--import Data.List<br>import Debug.Trace<br>import Data.Maybe as Maybe<br><br><br>-- this function will return th N°BD from Sidonie for a given name<br>-- note: names have been standardized between Sidonie and WDS<br>getBD3 :: Connection -> String -> Float<br>getBD3 conn name = do<br> let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where Nom = ?" :: Query<br> (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name::String))<br> let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text<br> let noBDstr = Text.unpack noBDtxt :: String<br> let noBDfp = read $ noBDstr :: Float<br> return noBDfp</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">with this function i have this error:</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">Prelude> :load UpdateSidonie<br>[1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted )<br><br>UpdateSidonie.hs:54:13: error:<br> • Couldn't match expected type ‘Float’ with actual type ‘IO Float’<br> • In a stmt of a 'do' block:<br> (bd_rows :: [Only Text]) <- query<br> conn qry_head_BD_Sidonie (Only (name :: String))<br> In the expression:<br> do let qry_head_BD_Sidonie = ...<br> (bd_rows :: [Only Text]) <- query<br> conn qry_head_BD_Sidonie (Only (name :: String))<br> let noBDtxt = ...<br> let noBDstr = ...<br> ....<br> In an equation for ‘getBD3’:<br> getBD3 conn name<br> = do let qry_head_BD_Sidonie = ...<br> (bd_rows :: [Only Text]) <- query<br> conn qry_head_BD_Sidonie (Only (name :: String))<br> let noBDtxt = ...<br> ....<br> |<br>54 | (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name::String))<br> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>Failed, no modules loaded.<br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">i do not understand the error complaining that i return an IO float,because i'm sure it's a float in noBDfp</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">if i put the same lines of code in the main it works !!! :</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">main :: IO ()<br><br>main =<br><br> do<br> conn <- connect defaultConnectInfo<br> { connectHost = "moita",<br> connectUser = "mattei",<br> connectPassword = "sidonie2",<br> connectDatabase = "sidonie" }<br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"> let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where Nom = ?" :: Query</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"> (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name::String))</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">putStr "bd_rows ="<br>putStrLn $ show bd_rows</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"> let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text<br><br> let noBDstr = Text.unpack noBDtxt :: String<br> let noBDfp = read $ noBDstr :: Float<br><br> putStr "noBDfp ="<br> (putStrLn (show noBDfp))</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"> close conn</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">it works i have output like this:</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">*Main> main<br>bd_rows =[Only {fromOnly = "-04.3982"}]<br>noBDtxt ="-04.3982"<br>noBDfp =-4.3982<br>noBDfp + 1 = -3.3982<br><br></div><div class="gmail_default" style="font-size:large">i'm well getting a float in noBDfp , i even can add 1 to it :-) ( cool haskell...)</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">but i'm just wanting to that in the function getDB3 but it does not compile...</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">??????</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">Damien<br></div></div></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Dec 23, 2018 at 4:54 PM 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 think forgetting about monads and just using do-notation will help you.<br>
<br>
On Sun, Dec 23, 2018 at 04:44:57PM +0100, Damien Mattei wrote:<br>
> i think learning Monads from scratch again will help me<br>
> <br>
> On Sun, Dec 23, 2018 at 4:11 PM 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>
> > Yes, exactly!<br>
> ><br>
> > On Sun, Dec 23, 2018 at 02:08:57PM +0100, Damien Mattei wrote:<br>
> > > lazyness....?<br>
> > ><br>
> > > On Sun, Dec 23, 2018 at 8:40 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>
> > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote:<br>
> > > > > i have inserted trace statement that output variable<br>
> > > > > ... i have strange behavior of output:<br>
> > > ><br>
> > > > Let's take a simpler example. Do you understand why the trace<br>
> > statments<br>
> > > > from this small program appear in the order that they do? (And for<br>
> > what<br>
> > > > it's worth I really think you'll be better off writing programs using<br>
> > do<br>
> > > > notation).<br>
> > > ><br>
> > > ><br>
> > > > % cat test.hs<br>
> > > > import Debug.Trace<br>
> > > ><br>
> > > > result =<br>
> > > > let a = trace "evaluating a" 2<br>
> > > > b = trace "evaluating b" 10<br>
> > > > c = trace "evaluating c" (a + b)<br>
> > > > in c<br>
> > > > ~% ghci -e result test.hs<br>
> > > > evaluating c<br>
> > > > evaluating b<br>
> > > > evaluating a<br>
> > > > 12<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>