Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  (SPAM 3)Re:  monad and variable result (Damien Mattei)
   2. Re:  (SPAM 3)Re:  monad and variable result (Francesco Ariis)
   3. Re:  (SPAM 3)Re: (SPAM 3)Re: monad and variable result
      (Damien Mattei)


----------------------------------------------------------------------

Message: 1
Date: Mon, 10 Dec 2018 15:46:46 +0100
From: Damien Mattei <mat...@oca.eu>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] (SPAM 3)Re:  monad and variable
        result
Message-ID: <5c0e7c56.1060...@oca.eu>
Content-Type: text/plain; charset=utf-8

query returns a list i suppose because i can wirte this in my main code:
 bd_rows <- query conn qry_head (Only (name::String))

    putStrLn $ show bd_rows
    putStrLn $ show name

    let resLst = Prelude.map fromOnly bd_rows

i can o a map on bd_rows

i just want to convert this code in Main:

let qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = ?"
:: Query

--    bd_rows <- query_ conn "select `N° BD` from sidonie.Coordonnées
where Nom = 'A    20'"

    bd_rows <- query conn qry_head (Only (name::String))

    putStrLn $ show bd_rows
    putStrLn $ show name

    let resLst = Prelude.map fromOnly bd_rows

    let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text
--    let noBD2 =  _ (Prelude.head bd_rows)

    putStrLn $ show resLst

    putStrLn $ show noBDtxt

    forM_ bd_rows $ \(Only a) ->
      putStrLn $  Text.unpack a

    let noBDstr = Text.unpack noBDtxt :: String
    let noBDfp = read $ noBDstr :: Float

where i succeed in putting the Float extracted and converted from the
result of query in a variable of type Float,

i want to have this in  function getBD that take as arguments the
Connection and the String name ,i use name in the SQL query and get back
the noBD in text first ,string and finally float...

this should be done,i assume it is possible in haskell but i'm a
beginner....

i have problem finding good doc ,understanding Monads ans '<-' use and 'do'

but i assume the solution is perhaps trivial...

Le 10/12/2018 12:19, Francesco Ariis a écrit :
> Hy Damien,
> 
> On Mon, Dec 10, 2018 at 11:32:23AM +0100, Damien Mattei wrote:
>> i want  the variable local_bd_rows accessible in the 'where' clause
> 
> does `query` return IO ()? If so, no you can't*. Once the result
> is inside IO, it stays in IO. Move what you need inside out of where
> (and inside a `do`) and get ready to change the signature of
> `getBD` to
> 
>     getBD :: Connection -> String -> IO Float
> 
> -F
> 
> * (you can with unsafeSomething functions, but it is really really
> advisable not to do that).
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 

-- 
damien.mat...@unice.fr, damien.mat...@oca.eu, UNS / OCA / CNRS


------------------------------

Message: 2
Date: Mon, 10 Dec 2018 16:06:12 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] (SPAM 3)Re:  monad and variable
        result
Message-ID: <20181210150612.aicm6oalxvoxc...@x60s.casa>
Content-Type: text/plain; charset=us-ascii

On Mon, Dec 10, 2018 at 03:46:46PM +0100, Damien Mattei wrote:
> query returns a list i suppose because i can wirte this in my main code:
>  bd_rows <- query conn qry_head (Only (name::String))

`query` does not return a `[r]`, rather an `IO [r]`. The difference
is very important; if you don't get it you will always have troubles
with Haskell. This will for sure help you

    https://www.seas.upenn.edu/~cis194/fall16/lectures/06-io-and-monads.html


------------------------------

Message: 3
Date: Mon, 10 Dec 2018 17:05:29 +0100
From: Damien Mattei <mat...@oca.eu>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] (SPAM 3)Re: (SPAM 3)Re: monad and
        variable result
Message-ID: <5c0e8ec9.4010...@oca.eu>
Content-Type: text/plain; charset=utf-8

thank you, i understand the difference, but can not see a solution,
seems i need main :: IO
so keep code in main, which is not really a problem, but i wanted to
structure it  more... i will keep searching a solution, understanding
more haskell

Le 10/12/2018 16:06, Francesco Ariis a écrit :
> On Mon, Dec 10, 2018 at 03:46:46PM +0100, Damien Mattei wrote:
>> query returns a list i suppose because i can wirte this in my main code:
>>  bd_rows <- query conn qry_head (Only (name::String))
> 
> `query` does not return a `[r]`, rather an `IO [r]`. The difference
> is very important; if you don't get it you will always have troubles
> with Haskell. This will for sure help you
> 
>     https://www.seas.upenn.edu/~cis194/fall16/lectures/06-io-and-monads.html
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 

-- 
damien.mat...@unice.fr, damien.mat...@oca.eu, UNS / OCA / CNRS


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 126, Issue 8
*****************************************

Reply via email to