From mattei at oca.eu Mon Dec 3 11:21:54 2018 From: mattei at oca.eu (Damien Mattei) Date: Mon, 3 Dec 2018 12:21:54 +0100 Subject: [Haskell-beginners] database access,extracting result... Message-ID: <5C0511D2.6030902@oca.eu> {-# LANGUAGE OverloadedStrings #-} import Database.MySQL.Simple import Control.Monad import Data.Text as Text import Data.Int main :: IO () main = do conn <- connect defaultConnectInfo { connectHost = "moita", connectUser = "mattei", connectPassword = "******", connectDatabase = "sidonie" } rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom = 'A 20'" --putStrLn $ show rows forM_ rows $ \(fname, lname) -> putStrLn $ fname ++ " " ++ Text.unpack lname ++ " " here is the error: *Main> :load Toto [1 of 1] Compiling Main ( Toto.hs, interpreted ) Ok, one module loaded. *Main> main *** Exception: ConversionFailed {errSQLType = "1 values: [(VarString,Just \"-04.3982\")]", errHaskellType = "2 slots in target type", errFieldName = "[\"N\\194\\176 BD\"]", errMessage = "mismatch between number of columns to convert and number in target type"} -04.3982 is the values i want to put in a variable,it's the N° BD (Durchmusterung Number) ??? any help greatly appeciated ;-) -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From mattei at oca.eu Mon Dec 3 14:40:39 2018 From: mattei at oca.eu (Damien Mattei) Date: Mon, 3 Dec 2018 15:40:39 +0100 Subject: [Haskell-beginners] database access,extracting result... In-Reply-To: <5C0511D2.6030902@oca.eu> References: <5C0511D2.6030902@oca.eu> Message-ID: <5C054067.3090908@oca.eu> just find myself this solution: main :: IO () main = do conn <- connect defaultConnectInfo { connectHost = "moita", connectUser = "mattei", connectPassword = "****", connectDatabase = "sidonie" } rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom = 'A 20'" forM_ rows $ \(Only a) -> putStrLn $ Text.unpack a Le 03/12/2018 12:21, Damien Mattei a écrit : > {-# LANGUAGE OverloadedStrings #-} > > import Database.MySQL.Simple > import Control.Monad > import Data.Text as Text > import Data.Int > > > main :: IO () > main = do > conn <- connect defaultConnectInfo > { connectHost = "moita", > connectUser = "mattei", > connectPassword = "******", > connectDatabase = "sidonie" } > > rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom > = 'A 20'" > > --putStrLn $ show rows > > forM_ rows $ \(fname, lname) -> > putStrLn $ fname ++ " " ++ Text.unpack lname ++ " " > > > here is the error: > > *Main> :load Toto > [1 of 1] Compiling Main ( Toto.hs, interpreted ) > Ok, one module loaded. > *Main> main > *** Exception: ConversionFailed {errSQLType = "1 values: > [(VarString,Just \"-04.3982\")]", errHaskellType = "2 slots in target > type", errFieldName = "[\"N\\194\\176 BD\"]", errMessage = "mismatch > between number of columns to convert and number in target type"} > > -04.3982 is the values i want to put in a variable,it's the N° BD > (Durchmusterung Number) > > > ??? > > any help greatly appeciated ;-) > > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From toad3k at gmail.com Mon Dec 3 14:42:11 2018 From: toad3k at gmail.com (David McBride) Date: Mon, 3 Dec 2018 09:42:11 -0500 Subject: [Haskell-beginners] database access,extracting result... In-Reply-To: <5C0511D2.6030902@oca.eu> References: <5C0511D2.6030902@oca.eu> Message-ID: Here's how it works, every time you supply a query, you supply the parameters to the query in a tuple. Furthermore the results can be gotten back as a tuple by type hinting each value. Warning: I have not run this code, but it should be close. query "select age, is_old from user where uid = ? and name = ? (uid :: Int, name :: String) :: IO [(Integer, Bool)] But what happens when you want to supply a single parameter (or receive a single value?) query "select * from user where uid = ?" (uid) The problem with that is (uid) is not a tuple. It's just an integer in parenthesis. There in fact is no way to specify a tuple of one length. So mysql-simple (and other libraries) very often have a single type meant to be used as a single element tuple. In mysql-simple's (and postgresql-simple) case that is the (Only a) type. (Side note, I wish these were in the standard Tuple module, as this comes once in awhile). query "select name from user where uid = ?" (Only uid) :: IO [Only String] Remember that you can also make your own records implement the QueryParams and QueryResults classes so that you can write On Mon, Dec 3, 2018 at 6:22 AM Damien Mattei wrote: > {-# LANGUAGE OverloadedStrings #-} > > import Database.MySQL.Simple > import Control.Monad > import Data.Text as Text > import Data.Int > > > main :: IO () > main = do > conn <- connect defaultConnectInfo > { connectHost = "moita", > connectUser = "mattei", > connectPassword = "******", > connectDatabase = "sidonie" } > > rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom > = 'A 20'" > > --putStrLn $ show rows > > forM_ rows $ \(fname, lname) -> > putStrLn $ fname ++ " " ++ Text.unpack lname ++ " " > > > here is the error: > > *Main> :load Toto > [1 of 1] Compiling Main ( Toto.hs, interpreted ) > Ok, one module loaded. > *Main> main > *** Exception: ConversionFailed {errSQLType = "1 values: > [(VarString,Just \"-04.3982\")]", errHaskellType = "2 slots in target > type", errFieldName = "[\"N\\194\\176 BD\"]", errMessage = "mismatch > between number of columns to convert and number in target type"} > > -04.3982 is the values i want to put in a variable,it's the N° BD > (Durchmusterung Number) > > > ??? > > any help greatly appeciated ;-) > > > -- > Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Tue Dec 4 15:33:55 2018 From: mattei at oca.eu (Damien Mattei) Date: Tue, 4 Dec 2018 16:33:55 +0100 Subject: [Haskell-beginners] database access,extracting result... In-Reply-To: References: <5C0511D2.6030902@oca.eu> Message-ID: <5C069E63.1060905@oca.eu> thank you David, i did something like that: rows <- query_ conn "SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278" forM_ rows $ \(name,distance) -> putStrLn $ Text.unpack name ++ " " ++ show (distance :: Double) output: ... HJ 2900 3.333333333882682e-2 HJ 3340 1.6666666646205367e-2 HLD 73 1.666666666807325e-2 HLD 152 1.666666666807325e-2 HLD 158 1.666666666807325e-2 HO 6 0.19569724135990224 HO 15 1.666666666807325e-2 ... and it works Damien Le 03/12/2018 15:42, David McBride a écrit : > Here's how it works, every time you supply a query, you supply the > parameters to the query in a tuple. Furthermore the results can be > gotten back as a tuple by type hinting each value. Warning: I have not > run this code, but it should be close. > > query "select age, is_old from user where uid = ? and name = ? (uid :: > Int, name :: String) :: IO [(Integer, Bool)] > > But what happens when you want to supply a single parameter (or receive > a single value?) > > query "select * from user where uid = ?" (uid) > > The problem with that is (uid) is not a tuple. It's just an integer in > parenthesis. There in fact is no way to specify a tuple of one length. > So mysql-simple (and other libraries) very often have a single type > meant to be used as a single element tuple. In mysql-simple's (and > postgresql-simple) case that is the (Only a) type. (Side note, I wish > these were in the standard Tuple module, as this comes once in awhile). > > query "select name from user where uid = ?" (Only uid) :: IO [Only String] > > Remember that you can also make your own records implement the > QueryParams and QueryResults classes so that you can write > > On Mon, Dec 3, 2018 at 6:22 AM Damien Mattei > wrote: > > {-# LANGUAGE OverloadedStrings #-} > > import Database.MySQL.Simple > import Control.Monad > import Data.Text as Text > import Data.Int > > > main :: IO () > main = do > conn <- connect defaultConnectInfo > { connectHost = "moita", > connectUser = "mattei", > connectPassword = "******", > connectDatabase = "sidonie" } > > rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom > = 'A 20'" > > --putStrLn $ show rows > > forM_ rows $ \(fname, lname) -> > putStrLn $ fname ++ " " ++ Text.unpack lname ++ " " > > > here is the error: > > *Main> :load Toto > [1 of 1] Compiling Main ( Toto.hs, interpreted ) > Ok, one module loaded. > *Main> main > *** Exception: ConversionFailed {errSQLType = "1 values: > [(VarString,Just \"-04.3982\")]", errHaskellType = "2 slots in target > type", errFieldName = "[\"N\\194\\176 BD\"]", errMessage = "mismatch > between number of columns to convert and number in target type"} > > -04.3982 is the values i want to put in a variable,it's the N° BD > (Durchmusterung Number) > > > ??? > > any help greatly appeciated ;-) > > > -- > Damien.Mattei at unice.fr , > Damien.Mattei at oca.eu , UNS / OCA / CNRS > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > _______________________________________________ > 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 From mrkaan888 at yandex.com Wed Dec 5 11:15:59 2018 From: mrkaan888 at yandex.com (=?iso-8859-1?b?RXn8cA==?= Kaan AKAY) Date: Wed, 05 Dec 2018 11:15:59 +0000 Subject: [Haskell-beginners] About Installing Sqlite3, HDBC and convertible Message-ID: <1544008559.23100.0@smtp.yandex.com.tr> Hi. I want to use sqlite3. When I work to install it, I got this error: hdbc-sqlite3-master$ ghc --make -o setup Setup.lhs hdbc-sqlite3-master$ ghc --make -o setup Setup.hs [1 of 1] Compiling Main ( Setup.hs, Setup.o ) Linking setup ... hdbc-sqlite3-master$ ./setup configure Configuring HDBC-sqlite3-2.3.3.1... setup: At least the following dependencies are missing: HDBC >=2.3.0.0, utf8-string -any When I want to install HDBC, I got this error: HDBC-2.4.0.2$ ghc --make -o setup Setup.lhs HDBC-2.4.0.2$ ./setup configure Configuring HDBC-2.4.0.2... setup: At least the following dependencies are missing: convertible >=1.1.0.0, utf8-string -any Then I install convertible and I got any errors then first I work to install HDBC but I got the same error. So what can I do else? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Wed Dec 5 08:40:51 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 5 Dec 2018 09:40:51 +0100 Subject: [Haskell-beginners] About Installing Sqlite3, HDBC and convertible In-Reply-To: <1544008559.23100.0@smtp.yandex.com.tr> References: <1544008559.23100.0@smtp.yandex.com.tr> Message-ID: <5C078F13.10108@oca.eu> i'm new to haskell and i'm assume you're trying to compile all the stuff "by hand", instead why don't you install cabal and install them using cabal? i'm trying also to use database with haskell,i use cabal to install HDBC this way:(from my comments in code) -- install those modules with cabal: /usr/local/bin/cabal update (if needed) /usr/local/bin/cabal install HDBC Damien Le 05/12/2018 12:15, Eyüp Kaan AKAY a écrit : > Hi. I want to use sqlite3. When I work to install it, I got this error: > *hdbc-sqlite3-master$* ghc --make -o setup Setup.lhs > *hdbc-sqlite3-master$* ghc --make -o setup Setup.hs > [1 of 1] Compiling Main ( Setup.hs, Setup.o ) > Linking setup ... > *hdbc-sqlite3-master$* ./setup configure > Configuring HDBC-sqlite3-2.3.3.1... > setup: At least the following dependencies are missing: > HDBC >=2.3.0.0, utf8-string -any > > When I want to install HDBC, I got this error: > > *HDBC-2.4.0.2$* ghc --make -o setup Setup.lhs > *HDBC-2.4.0.2$ *./setup configure > Configuring HDBC-2.4.0.2... > setup: At least the following dependencies are missing: > convertible >=1.1.0.0, utf8-string -any > > Then I install convertib le and I got any errors then first I work to > install HDBC but I got the same error. So what can I do else? > > > > > > > > > > _______________________________________________ > 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 From mattei at oca.eu Wed Dec 5 10:29:30 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 5 Dec 2018 11:29:30 +0100 Subject: [Haskell-beginners] Database simple-mysql Message-ID: <5C07A88A.6030706@oca.eu> why does this works: let name = "'A 20'" bd_rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom = 'A 20'" putStrLn $ show bd_rows putStrLn $ show name i got: [Only {fromOnly = "-04.3982"}] "'A 20'" -04.3982 but not with this: bd_rows <- query conn "select `N° BD` from sidonie.Coordonnées where Nom = ?" (Only (name::String)) i got an empty result: [] ... ??? -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From mattei at oca.eu Wed Dec 5 16:02:48 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 5 Dec 2018 17:02:48 +0100 Subject: [Haskell-beginners] database error simply by using a sting in a variable Message-ID: <5C07F6A8.9010909@oca.eu> why i'm getting this error? code: let name = "'A 20'" let qry = "select `N° BD` from Coordonnées where Nom = " ++ name putStrLn qry bd_rows <- query_ conn qry putStrLn $ show bd_rows putStrLn $ show name forM_ bd_rows $ \(Only a) -> putStrLn $ Text.unpack a error: *Main> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:74:28: error: • Couldn't match expected type ‘Query’ with actual type ‘[Char]’ • In the second argument of ‘query_’, namely ‘qry’ In a stmt of a 'do' block: bd_rows <- query_ conn qry In the expression: do conn <- connect defaultConnectInfo {connectHost = "moita", connectUser = "mattei", connectPassword = "sidonie2", connectDatabase = "sidonie"} rows <- query_ conn "SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278" forM_ rows $ \ (name, distance) -> putStrLn $ unpack name ++ " " ++ show (distance :: Double) let name = "'A 20'" .... | 74 | bd_rows <- query_ conn qry | ^^^ Failed, no modules loaded. -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From fa-ml at ariis.it Wed Dec 5 16:12:03 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Wed, 5 Dec 2018 17:12:03 +0100 Subject: [Haskell-beginners] database error simply by using a sting in a variable In-Reply-To: <5C07F6A8.9010909@oca.eu> References: <5C07F6A8.9010909@oca.eu> Message-ID: <20181205161203.jlrb3viu4hx2ldu3@x60s.casa> Hello Damien, On Wed, Dec 05, 2018 at 05:02:48PM +0100, Damien Mattei wrote: > • Couldn't match expected type ‘Query’ with actual type ‘[Char]’ GHC would like to have a `Query`, but you are providing a `String`. You didn't specify which library you are using, but I am willing to bet there is an appropriate ":: String -> Query" function. That of you need to put {-# Language OverloadedStrings -#} on top of your file. Does that work? -F From mattei at oca.eu Wed Dec 5 16:28:03 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 5 Dec 2018 17:28:03 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: database error simply by using a sting in a variable In-Reply-To: <20181205161203.jlrb3viu4hx2ldu3@x60s.casa> References: <5C07F6A8.9010909@oca.eu> <20181205161203.jlrb3viu4hx2ldu3@x60s.casa> Message-ID: <5C07FC93.6080005@oca.eu> Le 05/12/2018 17:12, Francesco Ariis a écrit : > Hello Damien, > > On Wed, Dec 05, 2018 at 05:02:48PM +0100, Damien Mattei wrote: >> • Couldn't match expected type ‘Query’ with actual type ‘[Char]’ > > GHC would like to have a `Query`, but you are providing a `String`. > You didn't specify which library you are using, but I am willing to > bet there is an appropriate ":: String -> Query" function. > > That of you need to put > > {-# Language OverloadedStrings -#} i had put it alreeady > > on top of your file. Does that work? no i begin to understand that {-# Language OverloadedStrings -#} is working on string but not on string in variable or concatenation , i should have to create an object of type Query from the String... ??? finally ,having a beginning of solution: let qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = ?" :: Query putStrLn qry bd_rows <- query conn qry_head (Only (name::String)) > -F > > _______________________________________________ > 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 From mattei at oca.eu Wed Dec 5 16:28:43 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 5 Dec 2018 17:28:43 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: database error simply by using a sting in a variable In-Reply-To: <20181205161203.jlrb3viu4hx2ldu3@x60s.casa> References: <5C07F6A8.9010909@oca.eu> <20181205161203.jlrb3viu4hx2ldu3@x60s.casa> Message-ID: <5C07FCBB.80002@oca.eu> thanks for your help Le 05/12/2018 17:12, Francesco Ariis a écrit : > Hello Damien, > > On Wed, Dec 05, 2018 at 05:02:48PM +0100, Damien Mattei wrote: >> • Couldn't match expected type ‘Query’ with actual type ‘[Char]’ > > GHC would like to have a `Query`, but you are providing a `String`. > You didn't specify which library you are using, but I am willing to > bet there is an appropriate ":: String -> Query" function. > > That of you need to put > > {-# Language OverloadedStrings -#} > > on top of your file. Does that work? > -F > > _______________________________________________ > 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 From fa-ml at ariis.it Wed Dec 5 16:46:55 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Wed, 5 Dec 2018 17:46:55 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: database error simply by using a sting in a variable In-Reply-To: <5C07FC93.6080005@oca.eu> References: <5C07F6A8.9010909@oca.eu> <20181205161203.jlrb3viu4hx2ldu3@x60s.casa> <5C07FC93.6080005@oca.eu> Message-ID: <20181205164655.yjt2kc74dplxhakf@x60s.casa> On Wed, Dec 05, 2018 at 05:28:03PM +0100, Damien Mattei wrote: > i begin to understand that {-# Language OverloadedStrings -#} is working > on string but not on string in variable or concatenation , i should have > to create an object of type Query from the String... ??? Yes, OverloadedStrings works on String *literals* not on String variables! From ian at zenhack.net Wed Dec 5 18:19:26 2018 From: ian at zenhack.net (Ian Denhardt) Date: Wed, 05 Dec 2018 13:19:26 -0500 Subject: [Haskell-beginners] database error simply by using a sting in a variable In-Reply-To: <5C07F6A8.9010909@oca.eu> References: <5C07F6A8.9010909@oca.eu> Message-ID: <154403396683.872.1499410688028997872@localhost> It sounds from the later posts like you've made some progress. I just want to call out one thing: Quoting Damien Mattei (2018-12-05 11:02:48) > let name = "'A 20'" > let qry = "select `N° BD` from Coordonnées where Nom = " ++ name I'll hazard a guess that you're using the sqlite-simple library. From their documentation on the Query type: > This type is intended to make it difficult to construct a SQL query by > concatenating string fragments, as that is an extremely common way to > accidentally introduce SQL injection vulnerabilities into an > application. From later messages it looks like you worked out the OverloadedStrings thing and ended up (correctly) moving to some code that uses the ? interpolation syntax: ".... where Nom = ?". I just wanted to stress that this is the right way to do things, and the distinction is important. This is a general thing when working with SQL: don't construct queries by gluing strings together; it's a great way to have vulnerabilities in your app. Happy Hacking, -Ian From mike_k_houghton at yahoo.co.uk Thu Dec 6 10:38:06 2018 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Thu, 6 Dec 2018 10:38:06 +0000 Subject: [Haskell-beginners] Regex Message-ID: <30682AE0-1182-472F-8677-68065C52835A@yahoo.co.uk> Hi, Which package is the most popular and/or easy to used for dealing with regular expressions? My regex is quite simple and I just need to get 2 or 3 capture groups from the result. Many thanks Mike From mattei at oca.eu Thu Dec 6 11:16:08 2018 From: mattei at oca.eu (Damien Mattei) Date: Thu, 6 Dec 2018 12:16:08 +0100 Subject: [Haskell-beginners] database, list result, extraction and conversion Message-ID: <5C0904F8.5030806@oca.eu> again un haskell beginner question ;-) ... i have this: [Only {fromOnly = "-04.3982"}] as result of a database query, i understand it's a list and i can get the first element: *Main> Data.List.head [Only {fromOnly = "-04.3982"}] Only {fromOnly = "-04.3982"} *Main> let s = Data.List.head [Only {fromOnly = "-04.3982"}] *Main> s Only {fromOnly = "-04.3982"} *Main> show s "Only {fromOnly = \"-04.3982\"}" but how can i get the String "-04.3982" ? and after converting it to a Float -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From fa-ml at ariis.it Thu Dec 6 13:07:40 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 6 Dec 2018 14:07:40 +0100 Subject: [Haskell-beginners] database, list result, extraction and conversion In-Reply-To: <5C0904F8.5030806@oca.eu> References: <5C0904F8.5030806@oca.eu> Message-ID: <20181206130740.rkgddr6x5av7nwdl@x60s.casa> On Thu, Dec 06, 2018 at 12:16:08PM +0100, Damien Mattei wrote: > *Main> show s > "Only {fromOnly = \"-04.3982\"}" > > but how can i get the String "-04.3982" ? and after converting it to a > Float? I suspect that "fromOnly" accessor will do! http://hackage.haskell.org/package/mysql-simple-0.4.5/docs/Database-MySQL-Simple.html#t:Only From toad3k at gmail.com Thu Dec 6 13:44:45 2018 From: toad3k at gmail.com (David McBride) Date: Thu, 6 Dec 2018 08:44:45 -0500 Subject: [Haskell-beginners] Regex In-Reply-To: <30682AE0-1182-472F-8677-68065C52835A@yahoo.co.uk> References: <30682AE0-1182-472F-8677-68065C52835A@yahoo.co.uk> Message-ID: In Haskell virtually everyone uses parser combinator libraries like parsec, megaparsec, or attoparsec depending on their needs. Many people ask this question and are then disappointed when they can't find a definitively standard regex library to use. That's because they are barely needed. That's not to say that there are no such libraries There are. But I personally couldn't suggest any as I have not been compelled to use one in many years. On Thu, Dec 6, 2018, 05:38 mike h Hi, > > Which package is the most popular and/or easy to used for dealing with > regular expressions? > My regex is quite simple and I just need to get 2 or 3 capture groups from > the result. > > Many thanks > > Mike > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Thu Dec 6 13:53:44 2018 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Thu, 6 Dec 2018 13:53:44 +0000 (UTC) Subject: [Haskell-beginners] Regex In-Reply-To: References: <30682AE0-1182-472F-8677-68065C52835A@yahoo.co.uk> Message-ID: <1613373168.5016348.1544104424647@mail.yahoo.com> :) I get a real buzz out of writing parser combinators. So, perversely - if only to broaden my Haskell knowledge, I decided to try using regexs. LOL I'll see where this takes me! Thanks Mike On Thursday, 6 December 2018, 13:45:21 GMT, David McBride wrote: In Haskell virtually everyone uses parser combinator libraries like parsec, megaparsec, or attoparsec depending on their needs. Many people ask this question and are then disappointed when they can't find a definitively standard regex library to use. That's because they are barely needed. That's not to say that there are no such libraries  There are. But I personally couldn't suggest any as I have not been compelled to use one in many years. On Thu, Dec 6, 2018, 05:38 mike h From mike_k_houghton at yahoo.co.uk Thu Dec 6 13:53:44 2018 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Thu, 6 Dec 2018 13:53:44 +0000 (UTC) Subject: [Haskell-beginners] Regex In-Reply-To: References: <30682AE0-1182-472F-8677-68065C52835A@yahoo.co.uk> Message-ID: <1613373168.5016348.1544104424647@mail.yahoo.com> :) I get a real buzz out of writing parser combinators. So, perversely - if only to broaden my Haskell knowledge, I decided to try using regexs. LOL I'll see where this takes me! Thanks Mike On Thursday, 6 December 2018, 13:45:21 GMT, David McBride wrote: In Haskell virtually everyone uses parser combinator libraries like parsec, megaparsec, or attoparsec depending on their needs. Many people ask this question and are then disappointed when they can't find a definitively standard regex library to use. That's because they are barely needed. That's not to say that there are no such libraries  There are. But I personally couldn't suggest any as I have not been compelled to use one in many years. On Thu, Dec 6, 2018, 05:38 mike h From mattei at oca.eu Thu Dec 6 14:54:45 2018 From: mattei at oca.eu (Damien Mattei) Date: Thu, 6 Dec 2018 15:54:45 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: database, list result, extraction and conversion In-Reply-To: <20181206130740.rkgddr6x5av7nwdl@x60s.casa> References: <5C0904F8.5030806@oca.eu> <20181206130740.rkgddr6x5av7nwdl@x60s.casa> Message-ID: <5C093835.9040401@oca.eu> if it was so easy! GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help Prelude> fromOnly [Only {fromOnly = "-04.3982"}] :1:12: error: Not in scope: data constructor ‘Only’ and in a program: bd_rows <- query conn qry_head (Only (name::String)) putStrLn $ show bd_rows putStrLn $ show name let resLst = [] let noBD = fromOnly bd_rows forM_ bd_rows $ \(Only a) -> putStrLn $ Data.Text.unpack a Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:93:25: error: • Couldn't match expected type ‘Only a’ with actual type ‘[Only Text]’ • In the first argument of ‘fromOnly’, namely ‘bd_rows’ In the expression: fromOnly bd_rows In an equation for ‘noBD’: noBD = fromOnly bd_rows • Relevant bindings include noBD :: a (bound at UpdateSidonie.hs:93:9) | 93 | let noBD = fromOnly bd_rows | ^^^^^^^ Failed, no modules loaded. Le 06/12/2018 14:07, Francesco Ariis a écrit : > On Thu, Dec 06, 2018 at 12:16:08PM +0100, Damien Mattei wrote: >> *Main> show s >> "Only {fromOnly = \"-04.3982\"}" >> >> but how can i get the String "-04.3982" ? and after converting it to a >> Float? > > I suspect that "fromOnly" accessor will do! > > http://hackage.haskell.org/package/mysql-simple-0.4.5/docs/Database-MySQL-Simple.html#t:Only > > > _______________________________________________ > 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 From fa-ml at ariis.it Thu Dec 6 16:10:00 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 6 Dec 2018 17:10:00 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: database, list result, extraction and conversion In-Reply-To: <5C093835.9040401@oca.eu> References: <5C0904F8.5030806@oca.eu> <20181206130740.rkgddr6x5av7nwdl@x60s.casa> <5C093835.9040401@oca.eu> Message-ID: <20181206161000.ys7d3mlo57xyqv66@x60s.casa> On Thu, Dec 06, 2018 at 03:54:45PM +0100, Damien Mattei wrote: > if it was so easy! Damien, you must heed the compiler! > UpdateSidonie.hs:93:25: error: > • Couldn't match expected type ‘Only a’ > with actual type ‘[Only Text]’ > • In the first argument of ‘fromOnly’, namely ‘bd_rows’ > In the expression: fromOnly bd_rows > In an equation for ‘noBD’: noBD = fromOnly bd_rows > • Relevant bindings include > noBD :: a (bound at UpdateSidonie.hs:93:9) > | > 93 | let noBD = fromOnly bd_rows > | ^^^^^^^ > Failed, no modules loaded. So you applied `fromOnly` to `bd_rows`. fromOnly has type fromOnly :: Only a -> a Now GHC is complaining: • I was expecting ‘Only a’ but you gave me ‘[Only Text]’ So either call "head" on [Only Text] (unsafe!) or map over it. See if it works and if not, fire again here -F From bkunyiha at gmail.com Thu Dec 6 20:03:42 2018 From: bkunyiha at gmail.com (Bill Kunyiha) Date: Thu, 6 Dec 2018 12:03:42 -0800 Subject: [Haskell-beginners] (SPAM 3)Re: database, list result, extraction and conversion In-Reply-To: <20181206161000.ys7d3mlo57xyqv66@x60s.casa> References: <5C0904F8.5030806@oca.eu> <20181206130740.rkgddr6x5av7nwdl@x60s.casa> <5C093835.9040401@oca.eu> <20181206161000.ys7d3mlo57xyqv66@x60s.casa> Message-ID: Thank you for reaching out to me. Is this a remote position? I live in Los Angeles and cannot relocate. Thank You Bill Kunyiha On Thu, Dec 6, 2018 at 8:10 AM Francesco Ariis wrote: > On Thu, Dec 06, 2018 at 03:54:45PM +0100, Damien Mattei wrote: > > if it was so easy! > > Damien, you must heed the compiler! > > > UpdateSidonie.hs:93:25: error: > > • Couldn't match expected type ‘Only a’ > > with actual type ‘[Only Text]’ > > • In the first argument of ‘fromOnly’, namely ‘bd_rows’ > > In the expression: fromOnly bd_rows > > In an equation for ‘noBD’: noBD = fromOnly bd_rows > > • Relevant bindings include > > noBD :: a (bound at UpdateSidonie.hs:93:9) > > | > > 93 | let noBD = fromOnly bd_rows > > | ^^^^^^^ > > Failed, no modules loaded. > > So you applied `fromOnly` to `bd_rows`. fromOnly has type > > fromOnly :: Only a -> a > > Now GHC is complaining: > > • I was expecting ‘Only a’ > but you gave me ‘[Only Text]’ > > So either call "head" on [Only Text] (unsafe!) or map over it. > See if it works and if not, fire again here > -F > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Fri Dec 7 08:44:03 2018 From: mattei at oca.eu (Damien Mattei) Date: Fri, 7 Dec 2018 09:44:03 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: (SPAM 3)Re: database, list result, extraction and conversion In-Reply-To: <20181206161000.ys7d3mlo57xyqv66@x60s.casa> References: <5C0904F8.5030806@oca.eu> <20181206130740.rkgddr6x5av7nwdl@x60s.casa> <5C093835.9040401@oca.eu> <20181206161000.ys7d3mlo57xyqv66@x60s.casa> Message-ID: <5C0A32D3.8020508@oca.eu> 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... D Le 06/12/2018 17:10, Francesco Ariis a écrit : > On Thu, Dec 06, 2018 at 03:54:45PM +0100, Damien Mattei wrote: >> if it was so easy! > > Damien, you must heed the compiler! heed? > >> UpdateSidonie.hs:93:25: error: >> • Couldn't match expected type ‘Only a’ >> with actual type ‘[Only Text]’ >> • In the first argument of ‘fromOnly’, namely ‘bd_rows’ >> In the expression: fromOnly bd_rows >> In an equation for ‘noBD’: noBD = fromOnly bd_rows >> • Relevant bindings include >> noBD :: a (bound at UpdateSidonie.hs:93:9) >> | >> 93 | let noBD = fromOnly bd_rows >> | ^^^^^^^ >> Failed, no modules loaded. > > So you applied `fromOnly` to `bd_rows`. fromOnly has type > > fromOnly :: Only a -> a > > Now GHC is complaining: > > • I was expecting ‘Only a’ > but you gave me ‘[Only Text]’ > > So either call "head" on [Only Text] (unsafe!) or map over it. > See if it works and if not, fire again here > -F > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From fa-ml at ariis.it Fri Dec 7 08:59:56 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 7 Dec 2018 09:59:56 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: (SPAM 3)Re: database, list result, extraction and conversion In-Reply-To: <5C0A32D3.8020508@oca.eu> References: <5C0904F8.5030806@oca.eu> <20181206130740.rkgddr6x5av7nwdl@x60s.casa> <5C093835.9040401@oca.eu> <20181206161000.ys7d3mlo57xyqv66@x60s.casa> <5C0A32D3.8020508@oca.eu> Message-ID: <20181207085956.2tmvjeczk23gf5d4@x60s.casa> 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! From mattei at oca.eu Fri Dec 7 09:33:27 2018 From: mattei at oca.eu (Damien Mattei) Date: Fri, 7 Dec 2018 10:33:27 +0100 Subject: [Haskell-beginners] database, list result, extraction and conversion In-Reply-To: <20181207085956.2tmvjeczk23gf5d4@x60s.casa> References: <5C0904F8.5030806@oca.eu> <20181206130740.rkgddr6x5av7nwdl@x60s.casa> <5C093835.9040401@oca.eu> <20181206161000.ys7d3mlo57xyqv66@x60s.casa> <5C0A32D3.8020508@oca.eu> <20181207085956.2tmvjeczk23gf5d4@x60s.casa> Message-ID: <5C0A3E67.10400@oca.eu> 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 From mattei at oca.eu Mon Dec 10 10:32:23 2018 From: mattei at oca.eu (Damien Mattei) Date: Mon, 10 Dec 2018 11:32:23 +0100 Subject: [Haskell-beginners] monad and variable result Message-ID: <5C0E40B7.6010909@oca.eu> have some code that works but want to put it in a simple function without sucess: getBD :: Connection -> String -> Float getBD conn name = noBDfp where qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = ?" :: Query bd_rows = do local_bd_rows <- query conn qry_head (Only (name::String)) return local_bd_rows i want the variable local_bd_rows accessible in the 'where' clause how can i do that? note the goal is to do the same thing of my main function that works : main :: IO () --main :: Int main = do conn <- connect defaultConnectInfo { connectHost = "moita", connectUser = "mattei", connectPassword = "******", connectDatabase = "sidonie" } -- we get all the Double Stars that have angular distance superior to a threshold of 1 second = 0.000278 degree rows <- query_ conn "SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278" forM_ rows $ \(name,distance) -> putStrLn $ Text.unpack name ++ " " ++ show (distance :: Double) -- we will get the Durchmusterung Number BD from Sidonie and WDS and compare them for a given name -- Warning: there could be multiple result in WDS for a given entry name (due to components) -- first we get the N°BD from sidonie let name = "A 20" -- let qry = "select `N° BD` from Coordonnées where Nom = " ++ name 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 putStr "noBDfp =" (putStrLn (show noBDfp)) close conn print "Exit." for now i have errors in the function: Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:47:28: error: • Ambiguous type variable ‘r0’ arising from a use of ‘query’ prevents the constraint ‘(QueryResults r0)’ from being solved. Relevant bindings include bd_rows :: IO [r0] (bound at UpdateSidonie.hs:46:9) Probable fix: use a type annotation to specify what ‘r0’ should be. These potential instances exist: instance Result a => QueryResults (Only a) -- Defined in ‘Database.MySQL.Simple.QueryResults’ instance (Result a, Result b) => QueryResults (a, b) -- Defined in ‘Database.MySQL.Simple.QueryResults’ instance (Result a, Result b, Result c) => QueryResults (a, b, c) -- Defined in ‘Database.MySQL.Simple.QueryResults’ ...plus 21 others (use -fprint-potential-instances to see them all) • In a stmt of a 'do' block: local_bd_rows <- query conn qry_head (Only (name :: String)) In the expression: do local_bd_rows <- query conn qry_head (Only (name :: String)) return local_bd_rows In an equation for ‘bd_rows’: bd_rows = do local_bd_rows <- query conn qry_head (Only (name :: String)) return local_bd_rows | 47 | local_bd_rows <- query conn qry_head (Only (name::String)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Failed, no modules loaded. -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From fa-ml at ariis.it Mon Dec 10 11:19:43 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 10 Dec 2018 12:19:43 +0100 Subject: [Haskell-beginners] monad and variable result In-Reply-To: <5C0E40B7.6010909@oca.eu> References: <5C0E40B7.6010909@oca.eu> Message-ID: <20181210111943.d3lwkltanakf3x7t@x60s.casa> 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). From mattei at oca.eu Mon Dec 10 14:46:46 2018 From: mattei at oca.eu (Damien Mattei) Date: Mon, 10 Dec 2018 15:46:46 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: monad and variable result In-Reply-To: <20181210111943.d3lwkltanakf3x7t@x60s.casa> References: <5C0E40B7.6010909@oca.eu> <20181210111943.d3lwkltanakf3x7t@x60s.casa> Message-ID: <5C0E7C56.1060403@oca.eu> 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 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 From fa-ml at ariis.it Mon Dec 10 15:06:12 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 10 Dec 2018 16:06:12 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: monad and variable result In-Reply-To: <5C0E7C56.1060403@oca.eu> References: <5C0E40B7.6010909@oca.eu> <20181210111943.d3lwkltanakf3x7t@x60s.casa> <5C0E7C56.1060403@oca.eu> Message-ID: <20181210150612.aicm6oalxvoxcwxv@x60s.casa> 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 From mattei at oca.eu Mon Dec 10 16:05:29 2018 From: mattei at oca.eu (Damien Mattei) Date: Mon, 10 Dec 2018 17:05:29 +0100 Subject: [Haskell-beginners] (SPAM 3)Re: (SPAM 3)Re: monad and variable result In-Reply-To: <20181210150612.aicm6oalxvoxcwxv@x60s.casa> References: <5C0E40B7.6010909@oca.eu> <20181210111943.d3lwkltanakf3x7t@x60s.casa> <5C0E7C56.1060403@oca.eu> <20181210150612.aicm6oalxvoxcwxv@x60s.casa> Message-ID: <5C0E8EC9.4010406@oca.eu> 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 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 From makos999 at gmail.com Wed Dec 12 10:45:23 2018 From: makos999 at gmail.com (Mr. Akos) Date: Wed, 12 Dec 2018 11:45:23 +0100 Subject: [Haskell-beginners] Regex In-Reply-To: References: <30682AE0-1182-472F-8677-68065C52835A@yahoo.co.uk> Message-ID: I have positive experiences with regex-compat, regex-posix packages, you can get these from hackage. When your expression becomes more complicated it may be worth to use parsers instead: faster processing, refactoring parsers is also easier. On Thu, Dec 6, 2018 at 2:45 PM David McBride wrote: > In Haskell virtually everyone uses parser combinator libraries like > parsec, megaparsec, or attoparsec depending on their needs. > > Many people ask this question and are then disappointed when they can't > find a definitively standard regex library to use. That's because they are > barely needed. > > That's not to say that there are no such libraries > There are. But I personally couldn't suggest any as I have not been > compelled to use one in many years. > > On Thu, Dec 6, 2018, 05:38 mike h >> Hi, >> >> Which package is the most popular and/or easy to used for dealing with >> regular expressions? >> My regex is quite simple and I just need to get 2 or 3 capture groups >> from the result. >> >> Many thanks >> >> Mike >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- People seldom notice clothes, if you wear a big smile. My grandmother uses Ubuntu, don't you think so?! OLVASD: http://www.xkcd.org/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Thu Dec 13 09:15:41 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Thu, 13 Dec 2018 09:15:41 +0000 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake Message-ID: Hello, I try to write this sort of code xdsme' :: SomeDataCollection -> Maybe Cell -> Maybe SpaceGroup -> GZiped -> [Path Abs File] -> ReaderT Beamline IO () xdsme' c@(SomeDataCollection SCollect SHdf5 _) cell sg z is = do -- xdsme compute the output path by himself. cwd' <- toProcessDataPath c rdir <- resultsPrefixFile xdsMePrefix c dir <- resultsPrefixDir ("xdsme_" ++ xdsMePrefix) c dir' <- resultsPrefixFile "" c xmlPath <- parseRelFile $ toFilePath dir' ++ "_xdsme.xml" xml <- parseAbsFile $ toFilePath cwd' toFilePath dir toFilePath xmlPath uploadedPath <- parseRelFile $ toFilePath dir' ++ "_xdsme.uploaded" uploaded <- parseAbsFile $ toFilePath cwd' toFilePath dir toFilePath uploadedPath let shakeFiles' = toFilePath cwd' toFilePath dir ".shake/" let images = getImages c z liftIO $ shake shakeOptions{ shakeFiles=shakeFiles' , shakeReport=["/tmp/shake.html"] , shakeVerbosity=Diagnostic} $ do want [toFilePath uploaded] -- execute xdsme and deal with input dependencies toFilePath xml %> \_out -> do need (map toFilePath is) processXdsMe cwd' cell sg rdir images toFilePath uploaded %> \_out -> do need [toFilePath xml] container <- liftIO . fromFile . toFilePath $ xml -- post processing let attachment = _autoProcProgramAttachment . _autoProcProgramContainer $ container attachment' <- toRuchePath attachment <- HERE PROBLEM _ <- copyAttachment' attachment attachment' let container' = (autoProcProgramContainer . autoProcProgramAttachment .~ attachment') container -- replace attachement -- upload into ISPYB liftIO $ storeAutoProcIntoISPyB c NoAnomalous container' cmd_ ("touch" :: String) (toFilePath uploaded) where toRuchePath :: (MonadReader Beamline m, MonadThrow m) => [AutoProcProgramAttachment WithPrefix] -> m [AutoProcProgramAttachment ISPyB] toRuchePath = mapM go where go :: (MonadReader Beamline m, MonadThrow m) => AutoProcProgramAttachment WithPrefix -> m (AutoProcProgramAttachment ISPyB) go a = do (d, _) <- toPath a b <- ask newd <- mkText255 . pack . toRuchePath' b . fromAbsDir $ d return a {filePath = newd} but when I try to compile this I get this error. How can I teach ghc how to solve this issue ? thanks for your help Frederic src/XdsMe.hs:211:22-43: error: • Could not deduce (MonadThrow Action) arising from a use of ‘toRuchePath’ from the context: t ~ 'Collect bound by a pattern with constructor: SCollect :: SCollectType 'Collect, in an equation for ‘xdsme'’ at src/XdsMe.hs:180:30-37 or from: f ~ 'ISPyB.DataCollection.Hdf5 bound by a pattern with constructor: SHdf5 :: SCollectSourceFormat 'ISPyB.DataCollection.Hdf5, in an equation for ‘xdsme'’ at src/XdsMe.hs:180:39-43 • In a stmt of a 'do' block: attachment' <- toRuchePath attachment In the expression: do { need [toFilePath xml]; container <- liftIO . fromFile . toFilePath $ xml; let attachment = _autoProcProgramAttachment . _autoProcProgramContainer $ container; attachment' <- toRuchePath attachment; .... } In the second argument of ‘(%>)’, namely ‘\ _out -> do { need [...]; container <- liftIO . fromFile . toFilePath $ xml; .... }’ From fa-ml at ariis.it Thu Dec 13 10:45:40 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 13 Dec 2018 11:45:40 +0100 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: References: Message-ID: <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> Hello Frédéric, On Thu, Dec 13, 2018 at 09:15:41AM +0000, PICCA Frederic-Emmanuel wrote: > Hello, > > I try to write this sort of code > > [...] . > but when I try to compile this I get this error. > How can I teach ghc how to solve this issue ? This > src/XdsMe.hs:211:22-43: error: > • Could not deduce (MonadThrow Action) > arising from a use of ‘toRuchePath’ Must has to mean that *inside* the do block starting with toFilePath uploaded %> \_out -> do `MonadThrow` does not work. I stress inside vs. outside because the outermost `do` block is of type `ReaderT Beamline IO ()` (which *is* an instance of `MonadThrow`), while `Action` apparently is not. I can think of two solutions: - Make `Action` an instance of `MonadThrow` - Let the throw happen outside that `do` block Let us know if that helped -F From frederic-emmanuel.picca at synchrotron-soleil.fr Thu Dec 13 10:56:17 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Thu, 13 Dec 2018 10:56:17 +0000 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> References: , <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> Message-ID: Hello > - Make `Action` an instance of `MonadThrow` If I read the documentationof Action, I have this. So you are right Action has no Instance for MonadThrow. BUT it seems that there is a LiftIO available. Do you think that it can be usefull or must I create a dedicated instance of Action https://hackage.haskell.org/package/shake-0.17.3/docs/Development-Shake.html#t:Action > - Let the throw happen outside that `do` block I can not move this out of the o`block because I need a computation done in the block. Maybe there is a way but I do not know how... Cheers Frederic From fa-ml at ariis.it Thu Dec 13 11:31:45 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 13 Dec 2018 12:31:45 +0100 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: References: <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> Message-ID: <20181213113145.v22rncvjcnh74vxm@x60s.casa> On Thu, Dec 13, 2018 at 10:56:17AM +0000, PICCA Frederic-Emmanuel wrote: > If I read the documentationof Action, I have this. > So you are right Action has no Instance for MonadThrow. > > BUT it seems that there is a LiftIO available. > Do you think that it can be usefull or must I create a dedicated instance of Action Using LiftIO should work fine! From frederic-emmanuel.picca at synchrotron-soleil.fr Thu Dec 13 13:33:55 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Thu, 13 Dec 2018 13:33:55 +0000 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: <20181213113145.v22rncvjcnh74vxm@x60s.casa> References: <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> , <20181213113145.v22rncvjcnh74vxm@x60s.casa> Message-ID: > Using LiftIO should work fine! I endup with this error src/XdsMe.hs:214:31-52: error: • Could not deduce (Control.Monad.Reader.Class.MonadReader Beamline IO) arising from a use of ‘toRuchePath’ from the context: t ~ 'Collect bound by a pattern with constructor: SCollect :: SCollectType 'Collect, in an equation for ‘xdsme'’ at src/XdsMe.hs:183:30-37 or from: f ~ 'ISPyB.DataCollection.Hdf5 bound by a pattern with constructor: SHdf5 :: SCollectSourceFormat 'ISPyB.DataCollection.Hdf5, in an equation for ‘xdsme'’ at src/XdsMe.hs:183:39-43 • In the second argument of ‘($)’, namely ‘toRuchePath attachment’ In a stmt of a 'do' block: attachment' <- liftIO $ toRuchePath attachment In the expression: do { need [toFilePath xml]; container <- liftIO . fromFile . toFilePath $ xml; let attachment = _autoProcProgramAttachment . _autoProcProgramContainer $ container; attachment' <- liftIO $ toRuchePath attachment; .... } Here the signature of the function xdsme' :: SomeDataCollection -> Maybe Cell -> Maybe SpaceGroup -> GZiped -> [Path Abs File] -> ReaderT Beamline IO () xdsme' c@(SomeDataCollection SCollect SHdf5 _) cell sg z is = do From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Dec 14 11:29:20 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 14 Dec 2018 11:29:20 +0000 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: References: <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> , <20181213113145.v22rncvjcnh74vxm@x60s.casa>, Message-ID: Hello, In fact I do not understand this error message, and thus I do not understand how to fix this ? How Can I give hint to ghc in order to fix this compilation error. thanks for your help. Frederic src/XdsMe.hs:214:31-52: error: • Could not deduce (Control.Monad.Reader.Class.MonadReader Beamline IO) arising from a use of ‘toRuchePath’ from the context: t ~ 'Collect bound by a pattern with constructor: SCollect :: SCollectType 'Collect, in an equation for ‘xdsme'’ at src/XdsMe.hs:183:30-37 or from: f ~ 'ISPyB.DataCollection.Hdf5 bound by a pattern with constructor: SHdf5 :: SCollectSourceFormat 'ISPyB.DataCollection.Hdf5, in an equation for ‘xdsme'’ at src/XdsMe.hs:183:39-43 • In the second argument of ‘($)’, namely ‘toRuchePath attachment’ In a stmt of a 'do' block: attachment' <- liftIO $ toRuchePath attachment In the expression: do { need [toFilePath xml]; container <- liftIO . fromFile . toFilePath $ xml; let attachment = _autoProcProgramAttachment . _autoProcProgramContainer $ container; attachment' <- liftIO $ toRuchePath attachment; .... } Here the signature of the function xdsme' :: SomeDataCollection -> Maybe Cell -> Maybe SpaceGroup -> GZiped -> [Path Abs File] -> ReaderT Beamline IO () xdsme' c@(SomeDataCollection SCollect SHdf5 _) cell sg z is = do From fa-ml at ariis.it Fri Dec 14 12:00:02 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 14 Dec 2018 13:00:02 +0100 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: References: <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> <20181213113145.v22rncvjcnh74vxm@x60s.casa> Message-ID: <20181214120002.pagbsxgh655mjqbn@x60s.casa> On Fri, Dec 14, 2018 at 11:29:20AM +0000, PICCA Frederic-Emmanuel wrote: > src/XdsMe.hs:214:31-52: error: > • Could not deduce (Control.Monad.Reader.Class.MonadReader > Beamline IO) > arising from a use of ‘toRuchePath’ > from the context: t ~ 'Collect Are you by chance using existential quantification or gadts? I might need a self contained example to load on ghci. From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Dec 14 12:58:29 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 14 Dec 2018 12:58:29 +0000 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: <20181214120002.pagbsxgh655mjqbn@x60s.casa> References: <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> <20181213113145.v22rncvjcnh74vxm@x60s.casa> , <20181214120002.pagbsxgh655mjqbn@x60s.casa> Message-ID: ________________________________________ De : Beginners [beginners-bounces at haskell.org] de la part de Francesco Ariis [fa-ml at ariis.it] Envoyé : vendredi 14 décembre 2018 13:00 À : beginners at haskell.org Objet : Re: [Haskell-beginners] MonadThrow, MonadReader and shake On Fri, Dec 14, 2018 at 11:29:20AM +0000, PICCA Frederic-Emmanuel wrote: > src/XdsMe.hs:214:31-52: error: > • Could not deduce (Control.Monad.Reader.Class.MonadReader > Beamline IO) > arising from a use of ‘toRuchePath’ > from the context: t ~ 'Collect Are you by chance using existential quantification or gadts? Yes exactly data SomeDataCollection where SomeDataCollection :: SCollectType t -> SCollectSourceFormat f -> DataCollection t f -> SomeDataCollection data CollectType = Collect | Caracterization deriving Show data SCollectType a where SCollect :: SCollectType 'Collect SCaracterization :: SCollectType 'Caracterization data CollectSourceFormat = Cbf | Hdf5 | Hdf5' deriving Show data SCollectSourceFormat a where SCbf :: SCollectSourceFormat 'Cbf SHdf5 :: SCollectSourceFormat 'Hdf5 SHdf5' :: SCollectSourceFormat 'Hdf5' With All these extensions. {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE UnicodeSyntax #-} sorry I do not have a public branch with the current modifications. Cheers Frederic From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Dec 14 13:04:14 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 14 Dec 2018 13:04:14 +0000 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: References: <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> <20181213113145.v22rncvjcnh74vxm@x60s.casa> , <20181214120002.pagbsxgh655mjqbn@x60s.casa>, Message-ID: I forgot this on. data DataCollection (t :: CollectType) (f :: CollectSourceFormat) = DataCollection { actualCenteringPosition :: Text , axisEnd :: Double , axisRange :: Double , axisStart :: Double , beamShape :: Text , beamSizeAtSampleX :: Double , beamSizeAtSampleY :: Double , centeringMethod :: Maybe Text , dataCollectionId :: DataCollectionId , dataCollectionNumber :: Int , detector2theta :: Double , detectorDistance :: Double , endTime :: Text , exposureTime :: Double , fileTemplate :: Text , flux :: Double , fluxEnd :: Double , imageDirectory :: Path Abs Dir , imagePrefix :: Text -- (FilePath) , imageSuffix :: Maybe Text -- (FilePath) ?? Maybe , kappaStart :: Double , numberOfImages :: Int , numberOfPasses :: Int , omegaStart :: Maybe Double , overlap :: Double , phiStart :: Double , printableForReport :: Int , resolution :: Double , resolutionAtCorner :: Maybe Double , rotationAxis :: Text , runStatus :: Text , slitGapHorizontal :: Double , slitGapVertical :: Double , startImageNumber :: Int , startTime :: Text , synchrotronMode :: Text , transmission :: Double , undulatorGap1 :: Maybe Double , undulatorGap2 :: Maybe Double , wavelength :: Double , xbeam :: Double , xtalSnapshotFullPath1 :: Maybe (Path Abs File) , xtalSnapshotFullPath2 :: Maybe (Path Abs File) , xtalSnapshotFullPath3 :: Maybe (Path Abs File) , xtalSnapshotFullPath4 :: Maybe (Path Abs File) , ybeam :: Double , dataCollectionGroupId :: Int } deriving Show Where we get the t and f parameter. :)) From fa-ml at ariis.it Fri Dec 14 15:07:45 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 14 Dec 2018 16:07:45 +0100 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: References: <20181213104540.j2lqm2rbiqb44l5r@x60s.casa> <20181213113145.v22rncvjcnh74vxm@x60s.casa> <20181214120002.pagbsxgh655mjqbn@x60s.casa> Message-ID: <20181214150745.rfc63yjeh4ptycg3@x60s.casa> On Fri, Dec 14, 2018 at 12:58:29PM +0000, PICCA Frederic-Emmanuel wrote: > Yes exactly > ... > With All these extensions. > ... > sorry I do not have a public branch with the current modifications. Far too much for me to chew! Maybe post in haskell-cafe@ and see what they say -F From sylvain at haskus.fr Sat Dec 15 09:06:43 2018 From: sylvain at haskus.fr (Sylvain Henry) Date: Sat, 15 Dec 2018 10:06:43 +0100 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: References: Message-ID: <3f2fc567-501f-e026-fcdc-3789bd4af125@haskus.fr> Hello, The` toRuchePath` function has the following constraints on `m`: `MonadReader Beamline m, MonadThrow m` In your code, `m ~ Action` (from Shake) which doesn't fulfil the constraints (hence the error). If you use `liftIO` as suggested (possible because Action has a MonadIO instance), `m ~ IO` which doesn't fulfil the constraints (hence the other error). If you want `m ~ ReaderT Beamline m IO`, you can use something like: `liftIO $ runReaderT stateBeforeCallingShake $ toRuchePath attachements` (you need `stateBeforeCallingShake <- ask` before calling shake). It should fulfil the constraints because we have instances for `MonadThrow IO` and `MonadThrow m => MonadThrow (ReaderT r m)`. Hope that helps, Sylvain On 13/12/2018 10:15, PICCA Frederic-Emmanuel wrote: > Hello, > > I try to write this sort of code > > xdsme' :: SomeDataCollection > -> Maybe Cell > -> Maybe SpaceGroup > -> GZiped > -> [Path Abs File] > -> ReaderT Beamline IO () > xdsme' c@(SomeDataCollection SCollect SHdf5 _) cell sg z is = do > -- xdsme compute the output path by himself. > cwd' <- toProcessDataPath c > rdir <- resultsPrefixFile xdsMePrefix c > dir <- resultsPrefixDir ("xdsme_" ++ xdsMePrefix) c > dir' <- resultsPrefixFile "" c > xmlPath <- parseRelFile $ toFilePath dir' ++ "_xdsme.xml" > xml <- parseAbsFile $ toFilePath cwd' toFilePath dir toFilePath xmlPath > uploadedPath <- parseRelFile $ toFilePath dir' ++ "_xdsme.uploaded" > uploaded <- parseAbsFile $ toFilePath cwd' toFilePath dir toFilePath uploadedPath > > let shakeFiles' = toFilePath cwd' toFilePath dir ".shake/" > let images = getImages c z > > liftIO $ shake shakeOptions{ shakeFiles=shakeFiles' > , shakeReport=["/tmp/shake.html"] > , shakeVerbosity=Diagnostic} $ do > want [toFilePath uploaded] > > -- execute xdsme and deal with input dependencies > toFilePath xml %> \_out -> do > need (map toFilePath is) > processXdsMe cwd' cell sg rdir images > > toFilePath uploaded %> \_out -> do > need [toFilePath xml] > > container <- liftIO . fromFile . toFilePath $ xml > > -- post processing > let attachment = _autoProcProgramAttachment . _autoProcProgramContainer $ container > > attachment' <- toRuchePath attachment <- HERE PROBLEM > > _ <- copyAttachment' attachment attachment' > > let container' = (autoProcProgramContainer . autoProcProgramAttachment .~ attachment') container -- replace attachement > > -- upload into ISPYB > liftIO $ storeAutoProcIntoISPyB c NoAnomalous container' > cmd_ ("touch" :: String) (toFilePath uploaded) > > > where > > toRuchePath :: (MonadReader Beamline m, MonadThrow m) > => [AutoProcProgramAttachment WithPrefix] > -> m [AutoProcProgramAttachment ISPyB] > toRuchePath = mapM go > where > go :: (MonadReader Beamline m, MonadThrow m) > => AutoProcProgramAttachment WithPrefix > -> m (AutoProcProgramAttachment ISPyB) > go a = do > (d, _) <- toPath a > b <- ask > newd <- mkText255 . pack . toRuchePath' b . fromAbsDir $ d > return a {filePath = newd} > > > but when I try to compile this I get this error. > How can I teach ghc how to solve this issue ? > > thanks for your help > > Frederic > > src/XdsMe.hs:211:22-43: error: > • Could not deduce (MonadThrow Action) > arising from a use of ‘toRuchePath’ > from the context: t ~ 'Collect > bound by a pattern with constructor: > SCollect :: SCollectType 'Collect, > in an equation for ‘xdsme'’ > at src/XdsMe.hs:180:30-37 > or from: f ~ 'ISPyB.DataCollection.Hdf5 > bound by a pattern with constructor: > SHdf5 :: SCollectSourceFormat 'ISPyB.DataCollection.Hdf5, > in an equation for ‘xdsme'’ > at src/XdsMe.hs:180:39-43 > • In a stmt of a 'do' block: attachment' <- toRuchePath attachment > In the expression: > do { need [toFilePath xml]; > container <- liftIO . fromFile . toFilePath $ xml; > let attachment > = _autoProcProgramAttachment . _autoProcProgramContainer > $ container; > attachment' <- toRuchePath attachment; > .... } > In the second argument of ‘(%>)’, namely > ‘\ _out > -> do { need [...]; > container <- liftIO . fromFile . toFilePath $ xml; > .... }’ > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From frederic-emmanuel.picca at synchrotron-soleil.fr Sat Dec 15 11:29:52 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sat, 15 Dec 2018 11:29:52 +0000 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: <3f2fc567-501f-e026-fcdc-3789bd4af125@haskus.fr> References: , <3f2fc567-501f-e026-fcdc-3789bd4af125@haskus.fr> Message-ID: > Hello, Hello sylvain. > The` toRuchePath` function has the following constraints on `m`: > `MonadReader Beamline m, MonadThrow m` > In your code, `m ~ Action` (from Shake) which doesn't fulfil the > constraints (hence the error). [...] > If you want `m ~ ReaderT Beamline m IO`, you can use something like: > `liftIO $ runReaderT stateBeforeCallingShake $ toRuchePath attachements` > (you need `stateBeforeCallingShake <- ask` before calling shake). ok, I will check this :). Does it mean that if an instance of the MonadReader was writtent for shake (Action). it should work out of the box ? Fred From sylvain at haskus.fr Tue Dec 18 10:56:03 2018 From: sylvain at haskus.fr (Sylvain Henry) Date: Tue, 18 Dec 2018 11:56:03 +0100 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: References: <3f2fc567-501f-e026-fcdc-3789bd4af125@haskus.fr> Message-ID: <3b721fa7-cf7c-635e-ae79-0e4810c20f95@haskus.fr> >> If you want `m ~ ReaderT Beamline m IO`, you can use something like: >> `liftIO $ runReaderT stateBeforeCallingShake $ toRuchePath attachements` >> (you need `stateBeforeCallingShake <- ask` before calling shake). > ok, I will check this :). I've swapped the args above, it should be: liftIO $ runReaderT (toRuchePath attachements) stateBeforeCallingShake > Does it mean that if an instance of the MonadReader was writtent for shake (Action). it should work out of the box ? With additional `MonadThrow Action` and `MonadReader Beamline Action` instances it should work. But the MonadReader one is really specific to your use case. Cheers, Sylvain From frederic-emmanuel.picca at synchrotron-soleil.fr Wed Dec 19 09:30:39 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Wed, 19 Dec 2018 09:30:39 +0000 Subject: [Haskell-beginners] MonadThrow, MonadReader and shake In-Reply-To: <3b721fa7-cf7c-635e-ae79-0e4810c20f95@haskus.fr> References: <3f2fc567-501f-e026-fcdc-3789bd4af125@haskus.fr> , <3b721fa7-cf7c-635e-ae79-0e4810c20f95@haskus.fr> Message-ID: > I've swapped the args above, it should be: > liftIO $ runReaderT (toRuchePath attachements) stateBeforeCallingShake Hello, I was struggling with strange errors :). Now it works. thanks a lot. I am just wondering if the best it not to add a parameter to my toRuchePath function and avoid the Reader Monad. this would simplify the code I gess. > With additional `MonadThrow Action` and `MonadReader Beamline Action` > instances it should work. But the MonadReader one is really specific to > your use case. I will try also this. thansk a lot. Frederic From math.simplex at gmail.com Thu Dec 27 05:57:17 2018 From: math.simplex at gmail.com (Graham Gill) Date: Thu, 27 Dec 2018 00:57:17 -0500 Subject: [Haskell-beginners] fclabels-2.0.3.3 build hangs on ghc-8.6.3/cabal-2.4.1.0 under Windows 10 Message-ID: <4395eae9-86d3-3ead-d434-fc535ac26a44@gmail.com> While trying to build the haskell-ide-engine project (https://github.com/haskell/haskell-ide-engine) on Windows 10, using my system global install of ghc-8.6.3, the process seems to hang while building fclabels-2.0.3.3. (I followed the project build instructions, using command > .\build-all.ps1 8.6.3 in the project root folder, which uses stack resolver lts-13.0 and ghc-8.6.3.) I get the same result (process never finishes) trying to build fclabels by itself: > stack install fclabels --stack-yaml .\stack-8.6.3.yaml in the haskell-ide-engine root folder. To simplify, I tried to build fclabels with cabal install (cabal-2.4.1.0) in my home folder (where there are no .cabal files present): > cabal -v -j1 v2-install fclabels Output is attached. The process hangs at compiling Data.Label.Base source to object file. Windows task manager shows ghc working merrily away (overnight, on my first attempt) without finishing. On the other hand, if I run > stack install fclabels --stack-yaml .\stack-8.4.4.yaml in the haskell-ide-engine root folder, which uses stack resolver lts-12.20 and ghc-8.4.4, fclabels-2.0.3.3 builds successfully. Because of the complexity of cabal and stack package management I don't know where to pin the blame, perhaps it's on my own system setup, hence don't know where/whether to file a bug report. Regards, Graham -------------- next part -------------- C:\Users\Graham>cabal list fclabels * fclabels Synopsis: First class accessor labels implemented as lenses. Default available version: 2.0.3.3 Installed versions: [ Not installed ] Homepage: https://github.com/sebastiaanvisser/fclabels License: BSD3 * fclabels-monadlib Synopsis: MonadLib monadic interface for the "fclabels" package. Default available version: 0.2.1 Installed versions: [ Not installed ] License: BSD3 C:\Users\Graham>cabal -v -j1 v2-install fclabels Reading available packages of hackage.haskell.org... Using most recent state specified from most recent cabal update index-state(hackage.haskell.org) = 2018-12-27T03:04:10Z "C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe" "--numeric-version" looking for tool ghc-pkg near compiler in C:\Program Files\Haskell Platform\8.6.3\bin found ghc-pkg in C:\Program Files\Haskell Platform\8.6.3\bin\ghc-pkg.exe "C:\Program Files\Haskell Platform\8.6.3\bin\ghc-pkg.exe" "--version" "C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe" "--supported-languages" "C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe" "--info" creating C:\Users\Graham\AppData\Local\Temp\cabal-install.-4532\dist-newstyle creating C:\Users\Graham\AppData\Local\Temp\cabal-install.-4532\dist-newstyle\cache Compiler settings changed, reconfiguring... "C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe" "--numeric-version" looking for tool ghc-pkg near compiler in C:\Program Files\Haskell Platform\8.6.3\bin found ghc-pkg in C:\Program Files\Haskell Platform\8.6.3\bin\ghc-pkg.exe "C:\Program Files\Haskell Platform\8.6.3\bin\ghc-pkg.exe" "--version" "C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe" "--supported-languages" "C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe" "--info" "C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe" "--print-global-package-db" Reading available packages of hackage.haskell.org... Using most recent state specified from most recent cabal update index-state(hackage.haskell.org) = 2018-12-27T03:04:10Z "C:\local\gtk\bin\pkg-config.exe" "--version" "C:\local\gtk\bin\pkg-config.exe" "--variable" "pc_path" "pkg-config" "C:\local\gtk\bin\pkg-config.exe" "--version" "C:\local\gtk\bin\pkg-config.exe" "--list-all" "C:\local\gtk\bin\pkg-config.exe" "--modversion" "libpng14" "cairo-win32" "cairo" "fontconfig" "gail" "gtk+-win32-2.0" "cairo-pdf" "pangowin32" "gio-2.0" "freetype2" "cairo-gobject" "cairo-ps" "gdk-win32-2.0" "libpng" "gobject-2.0" "pixman-1" "pangocairo" "cairo-win32-font" "cairo-svg" "cairo-fc" "cairo-png" "glib-2.0" "gmodule-2.0" "pango" "gthread-2.0" "gio-windows-2.0" "gdk-2.0" "gtk+-2.0" "cairo-ft" "atk" "gdk-pixbuf-2.0" "gmodule-no-export-2.0" "pangoft2" Resolving dependencies... Component graph for fclabels-2.0.3.3: component lib component fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279 include base-4.12.0.0 include mtl-2.2.2 include template-haskell-2.14.0.0 include transformers-0.5.5.0 unit fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279 include base-4.12.0.0 include mtl-2.2.2 include template-haskell-2.14.0.0 include transformers-0.5.5.0 Data.Label=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label,Data.Label.Base=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Base,Data.Label.Derive=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Derive,Data.Label.Failing=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Failing,Data.Label.Monadic=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Monadic,Data.Label.Mono=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Mono,Data.Label.Partial=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Partial,Data.Label.Point=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Point,Data.Label.Poly=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Poly,Data.Label.Total=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Total Build profile: -w ghc-8.6.3 -O1 In order, the following will be built: - fclabels-2.0.3.3 (lib) (requires build) creating C:\Users\Graham\AppData\Local\Temp\cabal-install.-4532\dist-newstyle\build creating C:\Users\Graham\AppData\Local\Temp\cabal-install.-4532\dist-newstyle\tmp Extracting C:\Users\Graham\AppData\Roaming\cabal\packages\hackage.haskell.org\fclabels\2.0.3.3\fclabels-2.0.3.3.tar.gz to C:\Users\Graham\AppData\Local\Temp\cabal-install.-4532\dist-newstyle\tmp\src-4532... Updating fclabels.cabal with the latest revision from the index. creating dist Using internal setup method with build-type Simple and args: ["configure","--verbose=2","--builddir=dist","--ghc","--prefix=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279","--bindir=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\\bin","--libdir=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\\lib","--libsubdir=","--dynlibdir=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\\lib","--libexecdir=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\\libexec","--libexecsubdir=","--datadir=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\\share","--datasubdir=","--docdir=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\\share\\doc","--htmldir=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\\share\\doc\\html","--haddockdir=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\\share\\doc\\html","--sysconfdir=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\\etc","--enable-library-vanilla","--disable-library-profiling","--disable-shared","--disable-static","--disable-executable-dynamic","--disable-profiling","--profiling-detail=default","--library-profiling-detail=default","--enable-optimization","--disable-debug-info","--disable-library-for-ghci","--disable-split-sections","--disable-split-objs","--disable-executable-stripping","--disable-library-stripping","--package-db=clear","--package-db=global","--package-db=C:\\Users\\Graham\\AppData\\Roaming\\cabal\\store\\ghc-8.6.3\\package.db","--extra-include-dirs=C:\\Program Files\\Haskell Platform\\8.6.3\\mingw\\include","--extra-include-dirs=C:\\Program Files\\Haskell Platform\\8.6.3\\mingw\\include","--cid=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279","--extra-lib-dirs=C:\\Program Files\\Haskell Platform\\8.6.3\\mingw\\lib","--extra-lib-dirs=C:\\Program Files\\Haskell Platform\\8.6.3\\mingw\\lib","--extra-prog-path=C:\\Program Files\\Haskell Platform\\8.6.3\\msys\\usr\\bin,\nC:\\Users\\Graham\\AppData\\Roaming\\cabal\\bin","--dependency=base=base-4.12.0.0","--dependency=mtl=mtl-2.2.2","--dependency=template-haskell=template-haskell-2.14.0.0","--dependency=transformers=transformers-0.5.5.0","--disable-coverage","--exact-configuration","--with-ghc=C:\\Program Files\\Haskell Platform\\8.6.3\\bin\\ghc.exe","--with-ghc-pkg=C:\\Program Files\\Haskell Platform\\8.6.3\\bin\\ghc-pkg.exe","--ghc-option=-hide-all-packages","lib:fclabels"] Using Parsec parser Configuring library for fclabels-2.0.3.3.. Dependency base ==4.12.0.0: using base-4.12.0.0 Dependency mtl ==2.2.2: using mtl-2.2.2 Dependency template-haskell ==2.14.0.0: using template-haskell-2.14.0.0 Dependency transformers ==0.5.5.0: using transformers-0.5.5.0 Source component graph: component lib Configured component graph: component fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279 include base-4.12.0.0 include mtl-2.2.2 include template-haskell-2.14.0.0 include transformers-0.5.5.0 Linked component graph: unit fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279 include base-4.12.0.0 include mtl-2.2.2 include template-haskell-2.14.0.0 include transformers-0.5.5.0 Data.Label=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label,Data.Label.Base=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Base,Data.Label.Derive=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Derive,Data.Label.Failing=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Failing,Data.Label.Monadic=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Monadic,Data.Label.Mono=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Mono,Data.Label.Partial=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Partial,Data.Label.Point=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Point,Data.Label.Poly=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Poly,Data.Label.Total=fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279:Data.Label.Total Ready component graph: definite fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279 depends base-4.12.0.0 depends mtl-2.2.2 depends template-haskell-2.14.0.0 depends transformers-0.5.5.0 Using Cabal-2.4.1.0 compiled by ghc-8.6 Using compiler: ghc-8.6.3 Using install prefix: C:\Users\Graham\AppData\Roaming\cabal\store\ghc-8.6.3\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279 Executables installed in: C:\Users\Graham\AppData\Roaming\cabal\store\ghc-8.6.3\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\bin Libraries installed in: C:\Users\Graham\AppData\Roaming\cabal\store\ghc-8.6.3\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\lib Dynamic Libraries installed in: C:\Users\Graham\AppData\Roaming\cabal\store\ghc-8.6.3\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\lib Private executables installed in: C:\Users\Graham\AppData\Roaming\cabal\store\ghc-8.6.3\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\libexec Data files installed in: C:\Users\Graham\AppData\Roaming\cabal\store\ghc-8.6.3\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\share Documentation installed in: C:\Users\Graham\AppData\Roaming\cabal\store\ghc-8.6.3\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\share\doc Configuration files installed in: C:\Users\Graham\AppData\Roaming\cabal\store\ghc-8.6.3\fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279\etc Using alex version 3.2.4 found on system at: C:\Program Files\Haskell Platform\8.6.3\lib\extralibs\bin\alex.exe Using ar found on system at: C:\Program Files\Haskell Platform\8.6.3\lib\../mingw/bin\ar.exe No c2hs found No cpphs found No doctest found Using gcc version 7.2.0 found on system at: C:\Program Files\Haskell Platform\8.6.3\lib\../mingw/bin\gcc.exe Using ghc version 8.6.3 given by user at: C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe Using ghc-pkg version 8.6.3 given by user at: C:\Program Files\Haskell Platform\8.6.3\bin\ghc-pkg.exe No ghcjs found No ghcjs-pkg found No greencard found Using haddock version 2.22.0 found on system at: C:\Program Files\Haskell Platform\8.6.3\bin\haddock.exe Using happy version 1.19.9 found on system at: C:\Program Files\Haskell Platform\8.6.3\lib\extralibs\bin\happy.exe Using haskell-suite found on system at: haskell-suite-dummy-location Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location No hmake found Using hpc version 0.67 found on system at: C:\Program Files\Haskell Platform\8.6.3\bin\hpc.exe Using hsc2hs version 0.68.5 found on system at: C:\Program Files\Haskell Platform\8.6.3\bin\hsc2hs.exe Using hscolour version 1.24 found on system at: C:\Program Files\Haskell Platform\8.6.3\lib\extralibs\bin\HsColour.exe No jhc found Using ld found on system at: C:\Program Files\Haskell Platform\8.6.3\lib\../mingw/bin\ld.exe Using pkg-config version 0.26 found on system at: C:\local\gtk\bin\pkg-config.exe Using runghc version 8.6.3 found on system at: C:\Program Files\Haskell Platform\8.6.3\bin\runghc.exe Using strip version 2.29 found on system at: C:\Program Files\Haskell Platform\8.6.3\mingw\bin\strip.exe Using tar found on system at: C:\Program Files (x86)\GnuWin32\bin\tar.exe No uhc found Using internal setup method with build-type Simple and args: ["build","--verbose=2","--builddir=dist"] Component build order: library "C:\Program Files\Haskell Platform\8.6.3\bin\ghc-pkg.exe" "init" "dist\package.conf.inplace" creating dist\build creating dist\build\autogen creating dist\build\autogen Preprocessing library for fclabels-2.0.3.3.. Building library for fclabels-2.0.3.3.. creating dist\build "C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe" "--make" "-fbuilding-cabal-package" "-O" "-outputdir" "dist\build" "-odir" "dist\build" "-hidir" "dist\build" "-stubdir" "dist\build" "-i" "-idist\build" "-isrc" "-idist\build\autogen" "-idist\build\global-autogen" "-Idist\build\autogen" "-Idist\build\global-autogen" "-Idist\build" "-IC:\Program Files\Haskell Platform\8.6.3\mingw\include" "-optP-include" "-optPdist\build\autogen\cabal_macros.h" "-this-unit-id" "fclabels-2.0.3.3-18ed72f15871ca46bf977352c1abdc97eb0c6279" "-hide-all-packages" "-Wmissing-home-modules" "-no-user-package-db" "-package-db" "C:\Users\Graham\AppData\Roaming\cabal\store\ghc-8.6.3\package.db" "-package-db" "dist\package.conf.inplace" "-package-id" "base-4.12.0.0" "-package-id" "mtl-2.2.2" "-package-id" "template-haskell-2.14.0.0" "-package-id" "transformers-0.5.5.0" "-XHaskell98" "Data.Label" "Data.Label.Base" "Data.Label.Derive" "Data.Label.Failing" "Data.Label.Monadic" "Data.Label.Mono" "Data.Label.Partial" "Data.Label.Point" "Data.Label.Poly" "Data.Label.Total" "-Wall" "-hide-all-packages" [ 1 of 10] Compiling Data.Label.Point ( src\Data\Label\Point.hs, dist\build\Data\Label\Point.o ) [ 2 of 10] Compiling Data.Label.Poly ( src\Data\Label\Poly.hs, dist\build\Data\Label\Poly.o ) [ 3 of 10] Compiling Data.Label.Partial ( src\Data\Label\Partial.hs, dist\build\Data\Label\Partial.o ) [ 4 of 10] Compiling Data.Label.Mono ( src\Data\Label\Mono.hs, dist\build\Data\Label\Mono.o ) [ 5 of 10] Compiling Data.Label.Failing ( src\Data\Label\Failing.hs, dist\build\Data\Label\Failing.o ) [ 6 of 10] Compiling Data.Label.Derive ( src\Data\Label\Derive.hs, dist\build\Data\Label\Derive.o ) [ 7 of 10] Compiling Data.Label ( src\Data\Label.hs, dist\build\Data\Label.o ) [ 8 of 10] Compiling Data.Label.Base ( src\Data\Label\Base.hs, dist\build\Data\Label\Base.o )