Re: [Haskell-cafe] For class Monoid; better names than mempty mappend might have been: mid (mident) mbinop
Hi Café, Thomas I think () is fairly uncontroversial because: Thomas (...) Thomas 2. It's abstract. i.e., no intended pronunciation How can that be an advantage ? A text flow with unnamed (or unpronounceable) symbols makes reading, understanding and remembering harder, don't you think ? I really think any operator or symbol should be intended (and even designed !) for pronunciation. Some references state that the monoid binary operation is often named dot or times in english. That does not mean the operator must be `dot`, `times`, (.) or (x) but at least the doc should provide a single, consistent and pronounceable name for it, whatever its spelling. Thomas For this reason, I think a larger change would have to come with Thomas a larger library re-organization. Johan Tibell suggested Thomas something like that a while ago: instead of lots of little cuts Thomas (backwards incompatible changes), a working group of activists Thomas should redesign a whole new (incompatible) alternative set of Thomas core libraries. This would be a great initiative, really ! -- Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] For class Monoid; better names than mempty mappend might have been: mid (mident) mbinop
On 25 July 2011 08:22, Paul R paul.r...@gmail.com wrote: Hi Café, Thomas I think () is fairly uncontroversial because: Thomas (...) Thomas 2. It's abstract. i.e., no intended pronunciation How can that be an advantage ? A text flow with unnamed (or unpronounceable) symbols makes reading, understanding and remembering harder, don't you think ? I really think any operator or symbol should be intended (and even designed !) for pronunciation. Some references state that the monoid binary operation is often named dot or times in english. That does not mean the operator must be `dot`, `times`, (.) or (x) but at least the doc should provide a single, consistent and pronounceable name for it, whatever its spelling. Well, in this case I think it can be beneficial because the pronunciation depends on the underlying monoid. E.g., sometimes it would be append or plus, other times dot or times. It can, of course, be useful to also have a good name for the generic operator. In this case I'd call it diamond. -- Push the envelope. Watch it bend. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] For class Monoid; better names than mempty mappend might have been: mid (mident) mbinop
On Mon, Jul 25, 2011 at 9:35 AM, Thomas Schilling nomin...@googlemail.com wrote: On 25 July 2011 08:22, Paul R paul.r...@gmail.com wrote: Hi Café, Thomas I think () is fairly uncontroversial because: Thomas (...) Thomas 2. It's abstract. i.e., no intended pronunciation How can that be an advantage ? A text flow with unnamed (or unpronounceable) symbols makes reading, understanding and remembering harder, don't you think ? I really think any operator or symbol should be intended (and even designed !) for pronunciation. Some references state that the monoid binary operation is often named dot or times in english. That does not mean the operator must be `dot`, `times`, (.) or (x) but at least the doc should provide a single, consistent and pronounceable name for it, whatever its spelling. Well, in this case I think it can be beneficial because the pronunciation depends on the underlying monoid. E.g., sometimes it would be append or plus, other times dot or times. It can, of course, be useful to also have a good name for the generic operator. In this case I'd call it diamond. After a big, backwards-incompatible library overhaul it would be nice if it ended up being (++) or (+). -- Push the envelope. Watch it bend. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Work is punishment for failing to procrastinate effectively. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] file splitter with enumerator package
Sorry, I'm only beginning to understand iteratees, but then how do you access each line of text output by the enumeratee lines within an iteratee? 2011/7/24 Felipe Almeida Lessa felipe.le...@gmail.com On Sun, Jul 24, 2011 at 12:28 PM, Yves Parès limestr...@gmail.com wrote: If you used Data.Enumerator.Text, you would maybe benefit the lines function: lines :: Monad m = Enumeratee Text Text m b It gets arbitrary blocks of text and outputs lines of text. But there is something I don't get with that signature: why isn't it: lines :: Monad m = Enumeratee Text [Text] m b ?? Lists of lines of text? Cheers, =) -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] For class Monoid; better names than mempty mappend might have been: mid (mident) mbinop
2011/7/25 Paul R paul.r...@gmail.com Some references state that the monoid binary operation is often named dot or times in english. That does not mean the operator must be `dot`, `times`, (.) or (x) but at least the doc should provide a single, consistent and pronounceable name for it, whatever its spelling. That is the problem when changing a function into an operator: the pronunciation. There should be a page somewhere that sums up how to pronounce the most common operators. = is bind, ok, but how do you pronounce or *, for instance? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] For class Monoid; better names than mempty mappend might have been: mid (mident) mbinop
2011/7/25 Yves Parès limestr...@gmail.com: 2011/7/25 Paul R paul.r...@gmail.com Some references state that the monoid binary operation is often named dot or times in english. That does not mean the operator must be `dot`, `times`, (.) or (x) but at least the doc should provide a single, consistent and pronounceable name for it, whatever its spelling. That is the problem when changing a function into an operator: the pronunciation. There should be a page somewhere that sums up how to pronounce the most common operators. = is bind, ok, but how do you pronounce or *, for instance? * is apply, I believe. could perhaps be then, though I haven't seen this anywhere. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Work is punishment for failing to procrastinate effectively. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] file splitter with enumerator package
blah = do fp - openFile file ReadMode run_ $ (ET.enumHandle fp $= ET.lines) $$ printChunks True printChunks is super duper simple: printChunks printEmpty = continue loop where loop (Chunks xs) = do let hide = null xs not printEmpty CM.unless hide (liftIO (print xs)) continue loop loop EOF = do liftIO (putStrLn EOF) yield () EOF Just replace print with whatever IO action you wanted to perform. On Mon, Jul 25, 2011 at 4:31 AM, Yves Parès limestr...@gmail.com wrote: Sorry, I'm only beginning to understand iteratees, but then how do you access each line of text output by the enumeratee lines within an iteratee? 2011/7/24 Felipe Almeida Lessa felipe.le...@gmail.com On Sun, Jul 24, 2011 at 12:28 PM, Yves Parès limestr...@gmail.com wrote: If you used Data.Enumerator.Text, you would maybe benefit the lines function: lines :: Monad m = Enumeratee Text Text m b It gets arbitrary blocks of text and outputs lines of text. But there is something I don't get with that signature: why isn't it: lines :: Monad m = Enumeratee Text [Text] m b ?? Lists of lines of text? Cheers, =) -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] More QuickCheck Questions
Hi all, I still don't understand exactly how the QuickCheck sized function is meant to work, and what it's useful for. Please explain! Also, I think that class CoArbitrary can help to generate random *functions *(as opposed to values; but tell me if I'm wrong) but I don't see how this could be useful. Also what does shrink do? Example code of these would be tremendously helpful understanding these concepts. Thanks in advance, Mark Spezzano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] file splitter with enumerator package
Okay, so there, the chunks (xs) will be lines of Text, and not just random blocks. Isn't there a primitive like printChunks in the enumerator library, or are we forced to handle Chunks and EOF by hand? 2011/7/25 David McBride dmcbr...@neondsl.com blah = do fp - openFile file ReadMode run_ $ (ET.enumHandle fp $= ET.lines) $$ printChunks True printChunks is super duper simple: printChunks printEmpty = continue loop where loop (Chunks xs) = do let hide = null xs not printEmpty CM.unless hide (liftIO (print xs)) continue loop loop EOF = do liftIO (putStrLn EOF) yield () EOF Just replace print with whatever IO action you wanted to perform. On Mon, Jul 25, 2011 at 4:31 AM, Yves Parès limestr...@gmail.com wrote: Sorry, I'm only beginning to understand iteratees, but then how do you access each line of text output by the enumeratee lines within an iteratee? 2011/7/24 Felipe Almeida Lessa felipe.le...@gmail.com On Sun, Jul 24, 2011 at 12:28 PM, Yves Parès limestr...@gmail.com wrote: If you used Data.Enumerator.Text, you would maybe benefit the lines function: lines :: Monad m = Enumeratee Text Text m b It gets arbitrary blocks of text and outputs lines of text. But there is something I don't get with that signature: why isn't it: lines :: Monad m = Enumeratee Text [Text] m b ?? Lists of lines of text? Cheers, =) -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] file splitter with enumerator package
Well I was going to say: import Data.Text.IO as T import Data.Enumerator.List as EL import Data.Enumerator.Text as ET run_ $ (ET.enumHandle fp $= ET.lines) $$ EL.mapM_ T.putStrLn for example. But it turns out this actually concatenates the lines together and prints one single string at the end. The reason is because it turns out that ET.enumHandle already gets lines one by one without you asking and it doesn't add newlines to the end, so ET.lines looks at each chunk and never sees any newlines so it returns the entire thing concatenated together figuring that was an entire line. I'm kind of surprised that enumHandle fetches linewise rather than to let you handle it. But if you were to make your own enumHandle that wasn't linewise that would work. On Mon, Jul 25, 2011 at 6:26 AM, Yves Parès limestr...@gmail.com wrote: Okay, so there, the chunks (xs) will be lines of Text, and not just random blocks. Isn't there a primitive like printChunks in the enumerator library, or are we forced to handle Chunks and EOF by hand? 2011/7/25 David McBride dmcbr...@neondsl.com blah = do fp - openFile file ReadMode run_ $ (ET.enumHandle fp $= ET.lines) $$ printChunks True printChunks is super duper simple: printChunks printEmpty = continue loop where loop (Chunks xs) = do let hide = null xs not printEmpty CM.unless hide (liftIO (print xs)) continue loop loop EOF = do liftIO (putStrLn EOF) yield () EOF Just replace print with whatever IO action you wanted to perform. On Mon, Jul 25, 2011 at 4:31 AM, Yves Parès limestr...@gmail.com wrote: Sorry, I'm only beginning to understand iteratees, but then how do you access each line of text output by the enumeratee lines within an iteratee? 2011/7/24 Felipe Almeida Lessa felipe.le...@gmail.com On Sun, Jul 24, 2011 at 12:28 PM, Yves Parès limestr...@gmail.com wrote: If you used Data.Enumerator.Text, you would maybe benefit the lines function: lines :: Monad m = Enumeratee Text Text m b It gets arbitrary blocks of text and outputs lines of text. But there is something I don't get with that signature: why isn't it: lines :: Monad m = Enumeratee Text [Text] m b ?? Lists of lines of text? Cheers, =) -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Web application design advice
Hello, Café. I am really not fond of web development, but being able to do it in my favorite language is interesting, so I've been spending some time taking a look at happstack. I decided to start a concrete project so that I could work towards some goal in my learning process, and I have decided on writing an inventory management system for this small computer workshop I work in as a volunteer. We probably have several metric tonnes of various computer equipment; interntal hardware(RAM, hard drives, graphics card, processors and so on) to peripherals and even non-computer related stuff, and it would be good to be able to catalog it and know what exactly we have and so on. Anyway, my question is about the design itself. My original idea for the database was to create a data type, something like data Hardware = Ram { ramType :: RamType , ramSize :: Int ... } data RamType = SDRAM | DDR | DDR2 | DDR3 .. The obvious advantage to this is type safety and thus having an ORM database, so to speak(Please forgive me if my web dev lingo is off here, this is *really *not my forté). However, a big disadvantage is that we might want to add new 'type' of hardware to the database and this would require me to stop the server, modify the haskell code to add a new type constructor and so on. On top of that, since a graphics card has different attributes than RAM, I will need to dynamically generate the forms required to add new hardware to the database or to search for hardware in the database. Due to this, I had another idea. I would create a state type that would merely represent groups of items using a map of some kind, where the group name would be a string. Maybe something like this: data HardwareGroup = HardwareGroup { groupName :: String -- Valid key values for the map , groupValues :: [String] , groupItems :: [Data.Map String String] } Which means I can create a new group like this: type Hardware = [HardwareGroups] hardwareDatabase :: Hardware hardwareDatabase = [] newGroup = HardwareGroup RAM [ramSize, ramSpeed, ramType, ramName] Data.Map.empty -- Nothing if some value in map isn't a valid part of addToGroup :: HardwareGroup - Data.Map String String - Maybe HardwareGroup addToGroup (HardwareGroup name values items) m = case (any (flip notElem values) $ keys m) of True - return Nothing _ - return $ HardwareGroup name values (m : items) addToGroup newGroup (fromList [(ramSize, 512), (ramSpeed, 400 Mhz), (ramType, DDR), (ramName, Kingston)]) The code may not be correct. I wrote it in this email and didn't test it, but I assume you guys get what I'm going for here. This will enable me to dynamically generate forms in an easy manner and add to / search in the database, without having to think about some types being strings and some types being ints or something entirely different. The reason I've come here asking this question and not some web design mailing list is because I'm writing this in Haskell, and I was wondering if you guys could see some disadvantages to either design that I may not have foreseen, or even come up with other suggestions. I would just really appreciate any hints, tips, pros or cons to either design. Am I losing something big by sacrificing type safety? Or is the first idea unwieldy enough to justify the sacrifices? Thanks a lot in advance guys. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] For class Monoid; better names than mempty mappend might have been: mid (mident) mbinop
I like to take a leaf out of Prince's book and refer to it as the function formerly known as mappend August Sodora aug...@gmail.com (201) 280-8138 On Mon, Jul 25, 2011 at 3:22 AM, Paul R paul.r...@gmail.com wrote: Hi Café, Thomas I think () is fairly uncontroversial because: Thomas (...) Thomas 2. It's abstract. i.e., no intended pronunciation How can that be an advantage ? A text flow with unnamed (or unpronounceable) symbols makes reading, understanding and remembering harder, don't you think ? I really think any operator or symbol should be intended (and even designed !) for pronunciation. Some references state that the monoid binary operation is often named dot or times in english. That does not mean the operator must be `dot`, `times`, (.) or (x) but at least the doc should provide a single, consistent and pronounceable name for it, whatever its spelling. Thomas For this reason, I think a larger change would have to come with Thomas a larger library re-organization. Johan Tibell suggested Thomas something like that a while ago: instead of lots of little cuts Thomas (backwards incompatible changes), a working group of activists Thomas should redesign a whole new (incompatible) alternative set of Thomas core libraries. This would be a great initiative, really ! -- Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to select last inserted record from Table Using Database.HSQL.MySQL
Hi, everyone! trycon - connect mysql bigtables vasya *** stmt' - query trycon INSERT INTO mytable (user,time,host,) VALUES (Vasya,2011.07.30 11.59,foo) I am beginner to use HSQL and I have a problem. I need to know row ID after INSERT into table. fetch stmt' returned False What should I do? Cheers! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] More QuickCheck Questions
On 07/25/11 06:01, Mark Spezzano wrote: Hi all, I still don't understand exactly how the QuickCheck sized function is meant to work, and what it's useful for. Please explain! Also, I think that class CoArbitrary can help to generate random *functions *(as opposed to values; but tell me if I'm wrong) but I don't see how this could be useful. Also what does shrink do? Example code of these would be tremendously helpful understanding these concepts. If there are canonical examples of some QuickCheck2 functions, I will gladly submit them as patches to the Haddock docs. I've banged my head against them more than once, and examples would have saved me a few hours. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Slightly tangential topic about functional programming (specifically, Lambda-Calculus)
On Sat, Jul 23, 2011 at 01:07:24PM -0500, Haskell Lippy wrote: My question - does anybody here belong to a forum, mailing list, or any other medium through which I might be able to engage some knowledgeable sources on Lambda-Calculus, and functional programming in general? This is such a mailing list! -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] file splitter with enumerator package
I just found another solution that seems to work, although I don't fully understand why. In my original function where I used EB.take to strictly read in a Lazy ByteString and then L.hPut to write it out to a handle, I now use this instead (full code in the annotation here: http://hpaste.org/49366): EB.isolate bytes =$ EB.iterHandle handle It now runs at the same speed but in constant memory, which is exactly what I was looking for. Is it recommended to nest iteratees within iteratees like this? I'm surprised that it worked, but I can't see a cleaner way to do it because of the other parts of the program that complicate matters. At this point I've achieved my original goals, unusual as they are, but since this has been an interesting learning experience I don't want it to stop there if there are more idiomatic ways to write code with the enumerator package. On Mon, Jul 25, 2011 at 4:06 AM, David McBride dmcbr...@neondsl.com wrote: Well I was going to say: import Data.Text.IO as T import Data.Enumerator.List as EL import Data.Enumerator.Text as ET run_ $ (ET.enumHandle fp $= ET.lines) $$ EL.mapM_ T.putStrLn for example. But it turns out this actually concatenates the lines together and prints one single string at the end. The reason is because it turns out that ET.enumHandle already gets lines one by one without you asking and it doesn't add newlines to the end, so ET.lines looks at each chunk and never sees any newlines so it returns the entire thing concatenated together figuring that was an entire line. I'm kind of surprised that enumHandle fetches linewise rather than to let you handle it. But if you were to make your own enumHandle that wasn't linewise that would work. On Mon, Jul 25, 2011 at 6:26 AM, Yves Parès limestr...@gmail.com wrote: Okay, so there, the chunks (xs) will be lines of Text, and not just random blocks. Isn't there a primitive like printChunks in the enumerator library, or are we forced to handle Chunks and EOF by hand? 2011/7/25 David McBride dmcbr...@neondsl.com blah = do fp - openFile file ReadMode run_ $ (ET.enumHandle fp $= ET.lines) $$ printChunks True printChunks is super duper simple: printChunks printEmpty = continue loop where loop (Chunks xs) = do let hide = null xs not printEmpty CM.unless hide (liftIO (print xs)) continue loop loop EOF = do liftIO (putStrLn EOF) yield () EOF Just replace print with whatever IO action you wanted to perform. On Mon, Jul 25, 2011 at 4:31 AM, Yves Parès limestr...@gmail.com wrote: Sorry, I'm only beginning to understand iteratees, but then how do you access each line of text output by the enumeratee lines within an iteratee? 2011/7/24 Felipe Almeida Lessa felipe.le...@gmail.com On Sun, Jul 24, 2011 at 12:28 PM, Yves Parès limestr...@gmail.com wrote: If you used Data.Enumerator.Text, you would maybe benefit the lines function: lines :: Monad m = Enumeratee Text Text m b It gets arbitrary blocks of text and outputs lines of text. But there is something I don't get with that signature: why isn't it: lines :: Monad m = Enumeratee Text [Text] m b ?? Lists of lines of text? Cheers, =) -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] deriving ListLike instance
Hi, all, newtype Stream a = Stream [a] I wanna derive ListLike [a] a automatically, but did not find a solution, I tried deriving instance ListLile (Stream a) a -- does not work Thank you. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to select last inserted record from Table Using Database.HSQL.MySQL
Hello Sergiy, On 07/25/2011 04:54 PM, Sergiy Nazarenko wrote: Hi, everyone! trycon - connect mysql bigtables vasya *** stmt' - query trycon INSERT INTO mytable (user,time,host,) VALUES (Vasya,2011.07.30 11.59,foo) I am beginner to use HSQL and I have a problem. I need to know row ID after INSERT into table. fetch stmt' returned False What should I do? This does not seem to be HSQL specific. For mysql, Google gave me LAST_INSERT_ID(): http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id There probably exist similar functions for other sql databases. -- Steffen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Stack space overflow in HaskellNet
Hi there, If I take example imap.hs import System.IO import Network.HaskellNet.IMAP import Text.Mime import qualified Data.ByteString.Char8 as BS import Control.Monad -- the next lines were changed to fit to my local imap server imapServer = imap.mail.org user = pass = main = do con - connectIMAP imapServer login con user pass mboxes - list con mapM print mboxes select con INBOX msgs - search con [ALLs] mapM_ (\x - print x) (take 4 msgs) forM_ (take 4msgs) (\x - fetch con x = print) and change the last line (in order to print all messages of the mailbox) into: forM_ msgs (\x - fetch con x = print) I get Stack space overflow: current size 8388608 bytes. Use `+RTS -Ksize -RTS' to increase it. Is this something to be fixed in the HaskellNet code, or in the example code? -- Manfred ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why the reluctance to introduce the Functor requirement on Monad?
My guess is that nobody has put forward a clear enough design that solves all the problems. In particular, orphan instances are tricky. Here's an example: module Prelude where class (Functor m, Applicative m) = Monad m where return :: a - m a (=) :: m a - (a - m b) - m b () :: m a - m b - m b a b = a = const b pure = return (*) = ap fmap = liftM module X where data X a = ... module Y where instance Functor X where fmap = ... module Z where instance Monad X where return = ... (=) = ... -- default implementation of fmap brought in from Monad definition module Main where import X import Z foo :: X Int foo = ... bar :: X Int bar = fmap (+1) foo -- which implementation of fmap is used? The one from Y? -- ryan On Sun, Jul 24, 2011 at 8:55 PM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: On 25 July 2011 13:50, Sebastien Zany sebast...@chaoticresearch.com wrote: I was thinking the reverse. We can already give default implementations of class operations that can be overridden by giving them explicitly when we declare instances, so why shouldn't we be able to give default implementations of operations of more general classes, which could be overridden by a separate instance declaration for these? Then I could say something like a monad is also automatically a functor with fmap by default given by... and if I wanted to give a more efficient fmap for a particular monad I would just instantiate it as a functor explicitly. I believe this has been proposed before, but a major problem is that you cannot do such overriding. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] More QuickCheck Questions
On 25 July 2011 20:01, Mark Spezzano mark.spezz...@chariot.net.au wrote: Hi all, I still don't understand exactly how the QuickCheck sized function is meant to work, and what it's useful for. Please explain! The size parameter indicates how large a value can be generated (e.g. how big an Int can be, how long a list should be, etc.). As I understand it, by default the size is passed around by QuickCheck in how it uses the Gen Monad and used automatically, increasing as more and more tests are done. Sometimes you want to explicitly use this value to get an upper bound when defining your own Arbitrary instances (e.g. see the Int instance for Arbitrary). Other times, you may wish to explicitly _limit_ the size to a pre-defined value (to stop recursion or the like; I have a couple of instances which use something like: \ s - liftM Foo $ resize (min 2 s) arbitrary). Either way, you define a function of type foo :: Int - Gen a and then your arbitrary instance becomes arbitrary = sized foo. Also, I think that class CoArbitrary can help to generate random *functions *(as opposed to values; but tell me if I'm wrong) but I don't see how this could be useful. Can't really help you there as I've never used it. Also what does shrink do? Oh no, QuickCheck has found an Arbitrary value that breaks your property! But it's absolutely _huge_: the output from show for it takes up an entire page, and it will take _forever_ to track down the specific little thing that caused the problem! But if you implemented the shrink method, QC will use it to find a minimal case: it shrinks the broken value, and then tests the property on every possible shrinked value, recursing until it finds one where every shrunken value satisfies the property (if there are any); at which case it will return that minimal broken case to you. Example code of these would be tremendously helpful understanding these concepts. Real World Haskell has a chapter on QC. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] deriving ListLike instance
On 26 July 2011 04:30, bob zhang bobzhang1...@gmail.com wrote: Hi, all, newtype Stream a = Stream [a] I wanna derive ListLike [a] a automatically, but did not find a solution, I tried deriving instance ListLile (Stream a) a -- does not work You can only derive certain in-built classes (Eq, Ord, Show, etc.) and - with extensions - some other classes (e.g. Functor). You _cannot_ derive ListLike. That said, it may be possible to extend either derive [1] or DrIFT [2] to be able to generate these instances for you. [1]: http://hackage.haskell.org/package/derive [2]: http://hackage.haskell.org/package/DrIFT-cabalized -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] deriving ListLike instance
Thanks. I know we can only derive built-in classes. Since Stream is just a newtype and ListLike [a] a is an instance, so I hope ListLike (Stream a) a would work given extensions. Unforturnately, newtype derivation requires the _last_ type variable to be newtype Thank you 于 11-7-25 下午6:14, Ivan Lazar Miljenovic 写道: On 26 July 2011 04:30, bob zhangbobzhang1...@gmail.com wrote: Hi, all, newtype Stream a = Stream [a] I wanna derive ListLike [a] a automatically, but did not find a solution, I tried deriving instance ListLile (Stream a) a -- does not work You can only derive certain in-built classes (Eq, Ord, Show, etc.) and - with extensions - some other classes (e.g. Functor). You _cannot_ derive ListLike. That said, it may be possible to extend either derive [1] or DrIFT [2] to be able to generate these instances for you. [1]: http://hackage.haskell.org/package/derive [2]: http://hackage.haskell.org/package/DrIFT-cabalized ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] More QuickCheck Questions
On Mon, Jul 25, 2011 at 3:01 AM, Mark Spezzano mark.spezz...@chariot.net.au wrote: Also, I think that class CoArbitrary can help to generate random *functions *(as opposed to values; but tell me if I'm wrong) but I don't see how this could be useful. How would you test that a function with the type endo :: Functor f = (a - a) - f a - f a satisfies some property? You pass in random functions which satisfy some property, and pass in random (f a)'s to try it on. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why the reluctance to introduce the Functor requirement on Monad?
On Mon, 2011-07-25 at 00:11 -0400, August Sodora wrote: Out of (perhaps naive) curiosity, what difficulties does allowing such overriding introduce? Wouldn't the module system prevent the ambiguity of which implementation to use? August Sodora aug...@gmail.com (201) 280-8138 class A a where a :: a class A a = B b where b :: b a = b class A a = C c where c :: c a = c data BC = B | C deriving Show instance B BC where b = B instance C BC where c = C show (a :: BC) == ??? Regards signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] file splitter with enumerator package
I feel like there is a little bit better way to code this by splitting the file outputting part from the part that counts and checks for newlines like so: run_ $ (EB.enumFile file.txt $= toChunksnl 4096) $$ toFiles filelist toFiles [] = error expected infinite file list toFiles (f:fs) = do next - EL.head case next of Nothing - return () Just next' - do liftIO $ L.writeFile f next' toFiles fs toChunksnl n = EL.concatMapAccum (somefunc n) L.empty where somefunc :: Int - L.ByteString - B.ByteString - (L.ByteString, [L.ByteString]) somefunc = undefined Where it has an accumulator that starts empty, gets a new bytestring, then parses the concatenation of those two that into as many full chunks that end with a newline as it can and stores that in the second part of the pair and then whatever remains unterminated ends up as the first part. I tried to write it myself, but I can't seem to hit all the edge cases necessary, but it seems like it should be doable for someone who wants to. It would be trivial with strings, but with bytestrings it requires a little elbow grease. However as to your question on whether you should use iteratees inside other iteratees, yes of course. It is all composeable. On Mon, Jul 25, 2011 at 1:38 PM, Eric Rasmussen ericrasmus...@gmail.com wrote: I just found another solution that seems to work, although I don't fully understand why. In my original function where I used EB.take to strictly read in a Lazy ByteString and then L.hPut to write it out to a handle, I now use this instead (full code in the annotation here: http://hpaste.org/49366): EB.isolate bytes =$ EB.iterHandle handle It now runs at the same speed but in constant memory, which is exactly what I was looking for. Is it recommended to nest iteratees within iteratees like this? I'm surprised that it worked, but I can't see a cleaner way to do it because of the other parts of the program that complicate matters. At this point I've achieved my original goals, unusual as they are, but since this has been an interesting learning experience I don't want it to stop there if there are more idiomatic ways to write code with the enumerator package. On Mon, Jul 25, 2011 at 4:06 AM, David McBride dmcbr...@neondsl.com wrote: Well I was going to say: import Data.Text.IO as T import Data.Enumerator.List as EL import Data.Enumerator.Text as ET run_ $ (ET.enumHandle fp $= ET.lines) $$ EL.mapM_ T.putStrLn for example. But it turns out this actually concatenates the lines together and prints one single string at the end. The reason is because it turns out that ET.enumHandle already gets lines one by one without you asking and it doesn't add newlines to the end, so ET.lines looks at each chunk and never sees any newlines so it returns the entire thing concatenated together figuring that was an entire line. I'm kind of surprised that enumHandle fetches linewise rather than to let you handle it. But if you were to make your own enumHandle that wasn't linewise that would work. On Mon, Jul 25, 2011 at 6:26 AM, Yves Parès limestr...@gmail.com wrote: Okay, so there, the chunks (xs) will be lines of Text, and not just random blocks. Isn't there a primitive like printChunks in the enumerator library, or are we forced to handle Chunks and EOF by hand? 2011/7/25 David McBride dmcbr...@neondsl.com blah = do fp - openFile file ReadMode run_ $ (ET.enumHandle fp $= ET.lines) $$ printChunks True printChunks is super duper simple: printChunks printEmpty = continue loop where loop (Chunks xs) = do let hide = null xs not printEmpty CM.unless hide (liftIO (print xs)) continue loop loop EOF = do liftIO (putStrLn EOF) yield () EOF Just replace print with whatever IO action you wanted to perform. On Mon, Jul 25, 2011 at 4:31 AM, Yves Parès limestr...@gmail.com wrote: Sorry, I'm only beginning to understand iteratees, but then how do you access each line of text output by the enumeratee lines within an iteratee? 2011/7/24 Felipe Almeida Lessa felipe.le...@gmail.com On Sun, Jul 24, 2011 at 12:28 PM, Yves Parès limestr...@gmail.com wrote: If you used Data.Enumerator.Text, you would maybe benefit the lines function: lines :: Monad m = Enumeratee Text Text m b It gets arbitrary blocks of text and outputs lines of text. But there is something I don't get with that signature: why isn't it: lines :: Monad m = Enumeratee Text [Text] m b ?? Lists of lines of text? Cheers, =) -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] file splitter with enumerator package
Actually, i'm wondering how to do exception handling and resource cleanup in iteratee, e.g. your `writer` iteratee, i found it difficult, because iteratee is designed to let enumerator manage resources. On Sat, Jul 23, 2011 at 2:41 AM, Eric Rasmussen ericrasmus...@gmail.comwrote: Hi everyone, A friend of mine recently asked if I knew of a utility to split a large file (4gb in his case) into arbitrarily-sized files on Windows. Although there are a number of file-splitting utilities, the catch was it couldn't break in the middle of a line. When the standard why don't you use Linux? response proved unhelpful, I took this as an opportunity to write my first program using the enumerator package. If anyone has time, I'm really interested in knowing if there's a better way to take the incoming stream and output it directly to a file. The basic steps I'm taking are: 1) Data.Enumerator.Binary.take -- grabs the user-specified number of bytes, then (because it returns a lazy ByteString) I use Data.ByteString.Lazy.hPut to output the chunk 2) Data.Enumerator.Binary.head -- after using take for the big chunk, it inspects and outputs individual characters and stops after it outputs the next newline character 3) I close the handle that steps 12 used to output the data and then repeat 12 with the next handle (an infinite lazy list of filepaths like part1.csv, part2.csv, and so on) The full code is pasted here: http://hpaste.org/49366, and while I'd like to get any other feedback on how to make it better, I want to note that I'm not planning to release this as a utility so I wouldn't want anyone to spend extra time performing a full code review. Thanks! Eric ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe