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: Parsing (Mike Houghton) 2. Re: haskell + python numpy (Daniel Bergey) 3. better way: contains one of a string from list in a string (Miro Karpis) 4. Re: better way: contains one of a string from list in a string (Lyndon Maydwell) 5. How to call popCnt64#? (John Ky) ---------------------------------------------------------------------- Message: 1 Date: Sat, 19 Mar 2016 13:19:36 +0000 From: Mike Houghton <mike_k_hough...@yahoo.co.uk> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Parsing Message-ID: <dc7a36f6-213e-4bca-85f0-0bfa63ef6...@yahoo.co.uk> Content-Type: text/plain; charset=utf-8 Hi, Just to recap I wanted to parse name:value pairs where some pairs are mandatory and some are not. eg //these are mandatory location : /user/local target : /x/y //these are optional copyTo : /a/b trace : bla blah ,,, undo : etc etc so I made data Item = Item (Name, Value) deriving (Show) where Name, Value are strings and made a parser for it. -- KeyWordItemParser kwip :: String -> Parser Item kwip keyWord = do spaces name <- string keyWord spaces char ':' spaces val <- itemValue spaces return $ Item (name, val) I made the mandatory of fixed order and hence easy to parse. For the optional I ended up defining a fixed order in which they can appear if indeed they do appear. So, for example, ?copyTo' has to come before ?trace? This allowed code like many $ kwip ?copyTo" many $ kwip ?trace" many $ kwip ?undo" which of course may result in duplicates that are later flagged as errors in post parsing validation. This validation step was needed anyway for other checking so a bit more was sort of ok. Pragmatically speaking It works ok but I?m not really happy with it. I?d really like to not have to enforce order. What I have been considering but have not yet been able to articulate in Haskell is, for parsing the optionals in any order, is to create a list of parsers and apply whilst removing parsers from the list. i.e. in pseudo code? Try to parse A : w B : x C : y D : z in any order parserList = [kwip A, kwip B, kwip C, kwip D] parse list text = do parserList empty? then done try a parser from parserList until one works - if none work then done (or error) if one worked accumulate result remove succesful parser from parserList then call again Any advice on how to write this in Haskell would be appreciated. Many thanks Mike > On 6 Mar 2016, at 10:17, Francesco Ariis <fa...@ariis.it> wrote: > > On Sun, Mar 06, 2016 at 09:54:34AM +0000, Mike Houghton wrote: >> Hi Francesco, >> Quick response! Thanks. >> >> I see, so would it reduce to something like? >> many itemValue >> >> and originally I was thinking the data structure that it would parse >> into would be >> >> data Module = Module {? some record structure?} >> >> but now it would be roughly like? >> >> type Entry = (String, String) >> >> data Module = Module [Entry] >> >> Thanks > > Yes, it would lead to some kind of (YourType, String) association list. > If you are more interested in a datatype with records I see two > ways of achieving it: > > a. a function `[(YrType, String)] -> RecordsData` (not so > pretty but doable, also you can check for well-formedness here) > (Using a sum type YrType is in my opinion better than plain > Strings as it catches some more errors at compile time). > > b. directly via parsing, using `optionMaybe` and glue. > Depending on how your input is structured this may or may not be > more hairy (can name and source appear after an optional tag? > What about duplicated tags? etc.). > In its simplest form you can use a succinct applicative-style, > but the castle crumbles if want more. > > > See which fits better (I suspect a.), play with it and report > back; parsing has never been an elegant business! > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Message: 2 Date: Sat, 19 Mar 2016 09:58:32 -0400 From: Daniel Bergey <ber...@alum.mit.edu> To: PICCA Frederic-Emmanuel <frederic-emmanuel.pi...@synchrotron-soleil.fr>, "beginners\@haskell.org" <beginners@haskell.org> Subject: Re: [Haskell-beginners] haskell + python numpy Message-ID: <874mc2lgc7.fsf@chladni.i-did-not-set--mail-host-address--so-tickle-me> Content-Type: text/plain I've seen a couple of blog posts (with code) about calling Python from Haskell. I haven't tried any of this code myself, and I can't recall seeing anything specifically about Numpy types. circa 2010: https://john-millikin.com/articles/ride-the-snake/ 2014: http://www.lunaryorn.com/2014/04/15/calling-python-from-haskell.html 2014-2015: https://github.com/Russell91/pyfi bergey On 2016-03-19 at 07:47, PICCA Frederic-Emmanuel <frederic-emmanuel.pi...@synchrotron-soleil.fr> wrote: > Hello, > > I would like to use some python code in order to do my computation with > haskell. > The idea is to use python and all it's numrical stack in some places, until I > find the time to replace the python code by some haskell code. > > what I will do is > > read the data from hdf5 with bindings-hdf5 in haskell > obtain a Storable for all my data images > then I would like to create a python object which will use these data in > order to generate in return another array. > > get back this array and put it into another hdf5 file. > > Indeed I want to do this with the pipes library. > > I would like to know if someone have some code examples for this kind of use > case. > > interfacing haskell with python numpy object back and forth. > > thanks for your help > > Frederic > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Message: 3 Date: Sun, 20 Mar 2016 08:02:07 +0100 From: Miro Karpis <miroslav.kar...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <Beginners@haskell.org> Subject: [Haskell-beginners] better way: contains one of a string from list in a string Message-ID: <CAJnnbxG0ZM3KFW7no=q7dcbepp7wonqxjfj+v_pck_f__mu...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hi, I needed a function that returns True/False if a list of strings are in a given string. I made one function below (works fine),..but I was wondering whether there is a shorter way? -- |Returns True if one of given strings are contained in given string contains :: [String] -> String -> Bool contains elements seach_elem | trueListCount == 0 = False | otherwise = True where isInStringList = [isInfixOf elem seach_elem | elem <- elements] onlyTrueList = [elem | elem <- isInStringList, elem == True] trueListCount = length onlyTrueList Cheers, -m -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160320/85498e7c/attachment-0001.html> ------------------------------ Message: 4 Date: Sun, 20 Mar 2016 18:11:24 +1100 From: Lyndon Maydwell <maydw...@gmail.com> To: miroslav.kar...@gmail.com, The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] better way: contains one of a string from list in a string Message-ID: <CAM5QZtwtT+ifJ68L3DkWZUdyXeCGtw-3kcs=skpj8nbtvwj...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" You can get that one quite easily using 'any'. E.g. [Prelude Data.List] ? let contains xs x = any (`isInfixOf` x) xs contains :: (Eq a, Foldable t) => t [a] -> [a] -> Bool [Prelude Data.List] ? contains (words "a b c d efg") "refgood" True it :: Bool [Prelude Data.List] ? contains (words "a b c d efg") "ref" False it :: Bool On Sun, Mar 20, 2016 at 6:02 PM, Miro Karpis <miroslav.kar...@gmail.com> wrote: > Hi, > > I needed a function that returns True/False if a list of strings are in a > given string. I made one function below (works fine),..but I was wondering > whether there is a shorter way? > > > -- |Returns True if one of given strings are contained in given string > contains :: [String] -> String -> Bool > contains elements seach_elem > | trueListCount == 0 = False > | otherwise = True > where > isInStringList = [isInfixOf elem seach_elem | elem <- elements] > onlyTrueList = [elem | elem <- isInStringList, elem == True] > trueListCount = length onlyTrueList > > > Cheers, > -m > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160320/641c9f67/attachment-0001.html> ------------------------------ Message: 5 Date: Sun, 20 Mar 2016 10:19:50 +0000 From: John Ky <newho...@gmail.com> To: "Beginners@haskell.org" <Beginners@haskell.org> Subject: [Haskell-beginners] How to call popCnt64#? Message-ID: <CAMB4o-Cxs0vWdR2a3i-yALVSfU=njvcfz9k9tublanzod4v...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello Haskellers, Does anyone know how to call popCnt64# from the GHC.Prim module? This was my failed attempt: ?> popCnt64# 1 <interactive>:14:11: Couldn't match kind ?*? with ?#? When matching types a0 :: * Word# :: # Expected type: Integer -> Word# Actual type: Integer -> a0 In the first argument of ?popCnt64#?, namely ?1? In the expression: popCnt64# 1 In an equation for ?it?: it = popCnt64# 1 -John -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160320/0a573cbe/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 93, Issue 13 *****************************************