[Haskell-beginners] database, list result, extraction and conversion

Damien Mattei mattei at oca.eu
Fri Dec 7 09:33:27 UTC 2018


yes thanks you
i had swapped the arguments of map in my code, i lack sleeping those days
this solution worked :
 let resLst = Prelude.map fromOnly bd_rows

but not this:

let noBD2 = Prelude.map _ bd_rows

Prelude> :load UpdateSidonie
[1 of 1] Compiling Main             ( UpdateSidonie.hs, interpreted )

UpdateSidonie.hs:94:29: error:
    • Found hole: _ :: Only Text -> b
      Where: ‘b’ is a rigid type variable bound by
               the inferred type of noBD2 :: [b]
               at UpdateSidonie.hs:94:9-37
    • In the first argument of ‘Prelude.map’, namely ‘_’
      In the expression: Prelude.map _ bd_rows
      In an equation for ‘noBD2’: noBD2 = Prelude.map _ bd_rows
    • Relevant bindings include
        noBD2 :: [b] (bound at UpdateSidonie.hs:94:9)
        noBD :: Text (bound at UpdateSidonie.hs:93:9)
        resLst :: [Text] (bound at UpdateSidonie.hs:91:9)
        bd_rows :: [Only Text] (bound at UpdateSidonie.hs:86:5)
        qry_head :: Query (bound at UpdateSidonie.hs:79:9)
        qry :: [Char] (bound at UpdateSidonie.hs:77:9)
        (Some bindings suppressed; use -fmax-relevant-binds=N or
-fno-max-relevant-binds)
      Valid substitutions include
        undefined :: forall (a :: TYPE r).
                     GHC.Stack.Types.HasCallStack =>
                     a
          (imported from ‘Prelude’ at UpdateSidonie.hs:1:1
           (and originally defined in ‘GHC.Err’))
   |
94 |     let noBD2 = Prelude.map _ bd_rows
   |                             ^
Failed, no modules loaded.


it's annoying ,since i add 'import' ,i must Prelude.* basic functions:
import Database.MySQL.Simple
import Database.MySQL.Simple.QueryResults
import Database.MySQL.Simple.Result
import Control.Monad
import Data.Text

i must use Prelude.map, Prelude.head

is there a solution to this problem?



Le 07/12/2018 09:59, Francesco Ariis a écrit :
> On Fri, Dec 07, 2018 at 09:44:03AM +0100, Damien Mattei wrote:
>>  let noBD = fromOnly (Prelude.head bd_rows)
>>
>> give me a solution, but i'm still searching a solution with map has in a
>> list there could be more than one result...
> 
> So put this in your code
> 
>     let noBD = map _ bd_rows
> 
> `_` will tell the compiler "tell me which type goes there". Then you
> can choose the appropriate function!
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 

-- 
Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS


More information about the Beginners mailing list