Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/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. Traverse tree with computing current level using Foldable instance. (Dmitriy Matrosov) 2. haskell for system administration (Ben) 3. Re: haskell for system administration (Mike Meyer) 4. Re: [x] and (x:_) for lists -- did you ever think that odd? (AntC) 5. Re: [x] and (x:_) for lists -- did you ever think that odd? (AntC) 6. Re: [x] and (x:_) for lists -- did you ever think that odd? (Ertugrul S?ylemez) 7. Re: [x] and (x:_) for lists -- did you ever think that odd? (Ertugrul S?ylemez) 8. Re: Traverse tree with computing current level using Foldable instance. (Brent Yorgey) ---------------------------------------------------------------------- Message: 1 Date: Mon, 21 May 2012 14:28:03 +0400 From: Dmitriy Matrosov <sgf....@gmail.com> Subject: [Haskell-beginners] Traverse tree with computing current level using Foldable instance. To: beginners@haskell.org Message-ID: <4fba18b3.8050...@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi. I can't figure out how should i properly solve the following problem. There is a tree defined like data Tape a = Tape a [Tape a] and i want to traverse it in some specific order, computing at the same time current level (depth). I.e. it should like fold, and folding function should have access to current level in the tree. Here is my implementation: import Data.Monoid import Control.Monad.State type TapeState a = State Int a foldMapS2 :: (Monoid m) => (a -> TapeState m) -> TapeState (Tape a) -> TapeState m foldMapS2 f tt = do t@(Tape name ts) <- tt foldr (go f) (f name) ts where go :: (Monoid m) => (a -> TapeState m) -> Tape a -> TapeState m -> TapeState m go f t mz = do cs <- get x <- foldMapS2 f (State (\s -> (t, s + 1))) put cs z <- mz put cs return (x `mappend` z) and here is example usage testTape = Tape "A" [ Tape "B" [ Tape "C" [] , Tape "F" [Tape "G" [Tape "H" []]] , Tape "E" [] ] , Tape "D" [ Tape "I" []] ] *Main> runState (foldMapS2 (\name -> get >>= \cs -> if cs == 0 then return [name] else return mempty) (return (testTape))) 0 (["A"],0) *Main> runState (foldMapS2 (\name -> get >>= \cs -> if cs == 1 then return [name] else return mempty) (return (testTape))) 0 (["B","D"],0) *Main> runState (foldMapS2 (\name -> get >>= \cs -> if cs == 2 then return [name] else return mempty) (return (testTape))) 0 (["C","F","E","I"],0) *Main> runState (foldMapS2 (\name -> get >>= \cs -> if cs == 3 then return [name] else return mempty) (return (testTape))) 0 (["G"],0) *Main> runState (foldMapS2 (\name -> get >>= \cs -> if cs == 4 then return [name] else return mempty) (return (testTape))) 0 (["H"],0) *Main> runState (foldMapS2 (\name -> get >>= \cs -> if cs == 5 then return [name] else return mempty) (return (testTape))) 0 ([],0) As you can see, this just selects all elements at particular tree level. So, my foldMapS2 looks similar to foldMap from Foldable, but i can't figure out, how should i define instances of Foldable (and Monoid?) to achieve the same functionality? ------------------------------ Message: 2 Date: Mon, 21 May 2012 19:43:47 +0530 From: Ben <benjo11...@gmail.com> Subject: [Haskell-beginners] haskell for system administration To: beginners@haskell.org Message-ID: <4fba4d9b.6010...@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi, I am new to HASKELL.Currently I am using shell scripting for Administration tasks and all.Kindly suggest me , does HASKELL usefull for Linux system administration and reporting purpose.? Do we use HASKELL for network programming and all? Regards, Ben ------------------------------ Message: 3 Date: Mon, 21 May 2012 10:28:45 -0400 From: Mike Meyer <m...@mired.org> Subject: Re: [Haskell-beginners] haskell for system administration To: Ben <benjo11...@gmail.com> Cc: beginners@haskell.org Message-ID: <20120521102845.6dc79...@bhuda.mired.org> Content-Type: text/plain; charset=US-ASCII On Mon, 21 May 2012 19:43:47 +0530 Ben <benjo11...@gmail.com> wrote: > I am new to HASKELL.Currently I am using shell scripting for > Administration tasks and all.Kindly suggest me , does HASKELL usefull > for Linux system administration and reporting purpose.? Yes, it is. I wrote "eddie" to let me leverage Haskell list processing from the command line. The standard Unix tools generally cover this kind of thing fairly well, so it's only marginally useful. Windows users seem to find more use for it. http://code.google.com/eddie. > Do we use HASKELL for network programming and all? Yup. You can find the code I wrote to extract statistical information on NCAA FBS seasons from the web at http://blog.mired.org/2012/01/analysis-of-fbs-controversies-part-i.html. While doing the fetch is a bit more complicated than using fetch (or curl, or whatever), the ease of analysis in Haskell and having the data already loaded when you want to start analysis makes up for that. <mike -- Mike Meyer <m...@mired.org> http://www.mired.org/ Independent Software developer/SCM consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org ------------------------------ Message: 4 Date: Tue, 22 May 2012 00:36:47 +0000 (UTC) From: AntC <anthony_clay...@clear.net.nz> Subject: Re: [Haskell-beginners] [x] and (x:_) for lists -- did you ever think that odd? To: beginners@haskell.org Message-ID: <loom.20120522t022222-...@post.gmane.org> Content-Type: text/plain; charset=us-ascii Brandon Allbery <allbery.b <at> gmail.com> writes: > You missed experienced Lispers, who are likewise entirely comfortable with cons-like notation. Good point Brandon, I should have asked what background and expectations people were coming from. From ALGOL, square brackets mean arrays, which are close-ish to lists(?) (For Lispers: does it seem odd using colon? Does it seem odd that dot is function composition, not cons pairing?) I was more getting at the oddness (or perhaps not) of having two different notations. > > I would want to very carefully check the implications of your suggestion: No, I wasn't anywhere near making a "suggestion" or "proposal". Just asking for people's impressions. > it might not integrate well with the rest of pattern matching syntax, ... FWIW, the double-dot notation is not currently valid in a pattern. I wanted to show something with square brackets. And to my mind, the double- dot could be taken as an unknown-length tail of the list, like an ellipsis. But others (it seems) think of it as enumFrom. AntC ------------------------------ Message: 5 Date: Tue, 22 May 2012 00:49:40 +0000 (UTC) From: AntC <anthony_clay...@clear.net.nz> Subject: Re: [Haskell-beginners] [x] and (x:_) for lists -- did you ever think that odd? To: beginners@haskell.org Message-ID: <loom.20120522t023859...@post.gmane.org> Content-Type: text/plain; charset=utf-8 Ertugrul S?ylemez <es <at> ertes.de> writes: [snip ..] > We have access to the two list constructors (:) and [] > directly and they are very convenient, So Ertugrul, as an experienced Haskeller which of these do you put in your code for a singleton list (whether appearing in a pattern or as an expression): [x] (x: []) Or perhaps you mix them, depending on whether you want to be more suggestive of an empty list [] or an unknown-length list (x: xs)? [.. snippety-snip] AntC ------------------------------ Message: 6 Date: Tue, 22 May 2012 03:02:10 +0200 From: Ertugrul S?ylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] [x] and (x:_) for lists -- did you ever think that odd? To: beginners@haskell.org Message-ID: <20120522030210.0c025...@tritium.streitmacht.eu> Content-Type: text/plain; charset="us-ascii" AntC <anthony_clay...@clear.net.nz> wrote: > So Ertugrul, as an experienced Haskeller which of these do you put in > your code for a singleton list (whether appearing in a pattern or as > an expression): [x] > (x: []) I tend to use bracket notation for fixed-length list patterns. > Or perhaps you mix them, depending on whether you want to be more > suggestive of an empty list [] or an unknown-length list (x: xs)? Yes. It's quite seldom that I use bracket notation, though. That's simply because it's seldom that I pattern-match against fixed-length lists. Greets, Ertugrul -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120522/6f172adf/attachment-0001.pgp> ------------------------------ Message: 7 Date: Tue, 22 May 2012 03:04:30 +0200 From: Ertugrul S?ylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] [x] and (x:_) for lists -- did you ever think that odd? To: beginners@haskell.org Message-ID: <20120522030430.78622...@tritium.streitmacht.eu> Content-Type: text/plain; charset="us-ascii" Tom Murphy <amin...@gmail.com> wrote: > I think it was just a joke. While a discussion is going on off the list, I would like to publicly apologize for my rough tone. I felt offended by the last remark. Of course I'm not taking back my statement, I just feel like it doesn't really apply to Anthony's original post. For questions like this I would recommend writing it in such a way that the intention is clear. It was somehow blurred by the rhetorical style. I also hope that people aren't offended by my mail signature, which indeed is a bit offensive. =) Greets, Ertugrul -- Key-ID: E5DD8D11 "Ertugrul Soeylemez <e...@ertes.de>" FPrint: BD28 3E3F BE63 BADD 4157 9134 D56A 37FA E5DD 8D11 Keysrv: hkp://subkeys.pgp.net/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120522/fb444773/attachment-0001.pgp> ------------------------------ Message: 8 Date: Mon, 21 May 2012 22:18:34 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Traverse tree with computing current level using Foldable instance. To: beginners@haskell.org Message-ID: <20120522021834.ga21...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii > > As you can see, this just selects all elements at particular tree level. > > So, my foldMapS2 looks similar to foldMap from Foldable, but i can't > figure out, how should i define instances of Foldable (and Monoid?) > to achieve the same functionality? You cannot. Foldable is not general enough; it does not allow you to define folds which can observe the *structure* of the container being folded over (such as the level in a tree, the number of children of a given node, etc.). It corresponds to simply "flattening" the structure into a list of elements, turning each of them into a value of some monoid, and then applying mconcat. However, you should be able to define a general fold for Tape, with type foldTape :: (a -> [b] -> b) -> Tape a -> b and then define foldMapS2 in terms of foldTape. -Brent ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 47, Issue 15 *****************************************