[Haskell-cafe] how unsafe is this?
I've defined a helper function to let me do regexps in functional style: sed exp str = unsafePerformIO $ do regexp - regcomp exp 0 regexec regexp str Is this always safe? or where is it not? (I'm using any one regexp more than once so it doesn't bother me that it compiles each time) -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how unsafe is this?
benc: I've defined a helper function to let me do regexps in functional style: sed exp str = unsafePerformIO $ do regexp - regcomp exp 0 regexec regexp str Is this always safe? or where is it not? (I'm using any one regexp more than once so it doesn't bother me that it compiles each time) Hopefully regex(3) is referentially transparent, so this should be fine :) -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Idiomatic Haskell equivalent of keyword arguments to functions
Neil Mitchell [EMAIL PROTECTED] writes: To make things concrete, the example I'm really thinking of is a send an email function, which would take a subject, a body, a list of recipients, optional lists of cc and bcc recipients, an optional mailserver (default localhost), an optional port (default 25), and possibly optional authentication details. Records are your friend. data Email = Email {subject :: String, body :: String, to :: [Address], cc = [Address], bcc = [Address], mailserver :: String, port :: Int} defaultEmail = Email{subject = No subject, body = , to = [], cc = [], bcc = [], mailserver = localhost, port = 25} The user can then go: sendEmail defaultEmail{subject=Subject here, body = body here, to = [haskell-cafe], mailserver = server.haskell.org} Now things which are't specified (port) keep their default value. If you do this for more than one function (and consequently more than one datatype) there's a case for a class -- something like: class Defaultable t where defaults:: t instance Defaultable Email where defaults = Email{subject = No subject, body = , to = [], cc = [], bcc = [], mailserver = localhost, port = 25} which would save having a defaultFoo for every Foo (at the possible expense of occasional explicit types). -- Jón Fairbairn [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[4]: [Haskell-cafe] Strange type behavior in GHCi 6.4.2
Hello Kirsten, Friday, December 29, 2006, 6:30:22 PM, you wrote: I suggest *not* using these pragmas unless a combination of profiling and reading intermediate code dumps suggests that foo -- and its un-specialized nature -- is truly a bottleneck. it's a matter of taste - and experience. may be it's simpler to add a huge number of INLINE pragmas than to profile and especially read code dumps? -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[4]: [Haskell-cafe] Re: Seeking advice on a style question
Hello Steve, Friday, December 29, 2006, 8:10:29 PM, you wrote: it force you to give names to intermediate results which is considered as good programing style - program becomes more documented. But that would imply that function composition and in-line function definition are also Bad Style. and omitting type signatures too :) yes, to some degree. balance between naked code and comments is your choice -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[4]: [Haskell-cafe] Strange type behavior in GHCi 6.4.2
Hello Grady, Friday, December 29, 2006, 11:00:42 PM, you wrote: I've performed some experiments in GHCi, and it looks like even for a get essentially the same execution times no matter which of the definitions below I use you should compare ghc -O2 times, ghci is very different beast. and even such test don't show actual results - as i already said, ghc automatically inlines only small functions -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[4]: [Haskell-cafe] Strange type behavior in GHCi 6.4.2
Maybe it's simpler to add a lot of INLINE, but that can make a program slower as well as faster. It's much better to profile and add them where they are needed. -- Lennart On Dec 30, 2006, at 08:42 , Bulat Ziganshin wrote: Hello Kirsten, Friday, December 29, 2006, 6:30:22 PM, you wrote: I suggest *not* using these pragmas unless a combination of profiling and reading intermediate code dumps suggests that foo -- and its un-specialized nature -- is truly a bottleneck. it's a matter of taste - and experience. may be it's simpler to add a huge number of INLINE pragmas than to profile and especially read code dumps? -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ 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] Mo' comprehensions
I was solving some programming puzzles today[1], and found myself pining for Map comprehensions. Maybe there should be a Comprehensible class that's automatically mapped to comprehension syntax. It's rather odd to have them only for lists. That would be both more general and more elegant than just bringing back monad comprehensions. Is there any obvious reason why this wouldn't work? [1] www.projecteuler.net -- fun stuff! -- -- Diego Navarro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[4]: [Haskell-cafe] Strange type behavior in GHCi 6.4.2
On 12/30/06, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello Kirsten, Friday, December 29, 2006, 6:30:22 PM, you wrote: I suggest *not* using these pragmas unless a combination of profiling and reading intermediate code dumps suggests that foo -- and its un-specialized nature -- is truly a bottleneck. it's a matter of taste - and experience. may be it's simpler to add a huge number of INLINE pragmas than to profile and especially read code dumps? I agree that profiling and reading code dumps can be daunting, but in my opinion, it's better to learn these skills once and for all (and unfortunately, these skills are still necessary given the current level of Haskell technology) and gain insight into how to use the compiler to get the code you want than to practice cargo-cult programming in the form of wanton pragmas. Cheers, Kirsten -- Kirsten Chevalier* [EMAIL PROTECTED] *Often in error, never in doubt Religion is just a fancy word for the Stockholm Syndrome. -- lj user=pure_agnostic ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Literate Haskell source files. How do I turn them into something I can read?
On 12/29/06, Michael T. Richter [EMAIL PROTECTED] wrote: I'm trying to wrap my mind around the darcs source code as a preliminary to looking into GHC's guts. All of darcs is written as .lhs files which have bizarre mark-up in them which distracts me from the actual Haskell source I'm trying to figure out and get used to. Apparently the GHC compiler can take .lhs files, strip them with unlit (a utility which I finally found buried deep in the GHC installation -- off-path) and then compile them normally. The problem I have is that unlit leaves behind instead these huge gaping (and highly distracting) stretches of whitespace while it takes out the markup. Speaking of bizarre markup, I gently suggest using plaintext rather than HTML, and wrapping your lines, when you post to this list. In any case, I'm surprised that you find the Literate Haskell aspect of it to be the *most* bizarre thing about darcs's sources, but anyway, I really do suggest turning the code into PDFs as Cale suggested rather than trying to strip out the literate markup. Sometimes, documentation really does help one understand code, and the entire point of literate programming is to make code more readable. A little effort spent learning now could save you a whole lot of effort later. Cheers, Kirsten -- Kirsten Chevalier* [EMAIL PROTECTED] *Often in error, never in doubt Dare to be naive.--R. Buckminster Fuller ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mo' comprehensions
What would the Comprehensible class have? And how would it be different from Monad(Zero)? -- Lennart On Dec 30, 2006, at 10:05 , Diego Navarro wrote: I was solving some programming puzzles today[1], and found myself pining for Map comprehensions. Maybe there should be a Comprehensible class that's automatically mapped to comprehension syntax. It's rather odd to have them only for lists. That would be both more general and more elegant than just bringing back monad comprehensions. Is there any obvious reason why this wouldn't work? [1] www.projecteuler.net -- fun stuff! -- -- Diego Navarro ___ 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] Mo' comprehensions
Hi I was solving some programming puzzles today[1], and found myself pining for Map comprehensions. [ ... (key,val) - fromList map, ... ] It isn't really that much more than a straight comprehension would be on a map. By default should a map comprehension let you inspect the values, or the keys, or both? Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[4]: [Haskell-cafe] Strange type behavior in GHCi 6.4.2
I tried compiling, but I got a linker error: /usr/lib/ghc-6.4.2/libHSrts.a(Main.o): In function `main': (.text+0x2): undefined reference to `__stginit_ZCMain' /usr/lib/ghc-6.4.2/libHSrts.a(Main.o): In function `main': (.text+0x16): undefined reference to `ZCMain_main_closure' collect2: ld returned 1 exit status --Grady On 12/30/06, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello Grady, Friday, December 29, 2006, 11:00:42 PM, you wrote: I've performed some experiments in GHCi, and it looks like even for a get essentially the same execution times no matter which of the definitions below I use you should compare ghc -O2 times, ghci is very different beast. and even such test don't show actual results - as i already said, ghc automatically inlines only small functions -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[4]: [Haskell-cafe] Strange type behavior in GHCi 6.4.2
On 12/30/06, Grady Lemoine [EMAIL PROTECTED] wrote: I tried compiling, but I got a linker error: /usr/lib/ghc-6.4.2/libHSrts.a(Main.o): In function `main': (.text+0x2): undefined reference to `__stginit_ZCMain' /usr/lib/ghc-6.4.2/libHSrts.a(Main.o): In function `main': (.text+0x16): undefined reference to `ZCMain_main_closure' collect2: ld returned 1 exit status You need to either define a main function in your module (e.g., main = putStrLn Hello world!) or add -c to your compile flags. Cheers, Kirsten -- Kirsten Chevalier* [EMAIL PROTECTED] *Often in error, never in doubt I wanna live for life and no other / cause I don't ever wanna be like my mother I wanna learn to walk on the water / cause I don't wanna be like my father -- Noe Venable ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Seeking advice on a style question
On Fri, 29 Dec 2006 18:39:04 +0100, you wrote: Why not generate Haskell code from such a graph? Well, that would indeed be a workable solution. But I don't have quite the resources to design Yet Another Visual Programming Language. And a textual representation of the graph would have exactly the same kinds of problems that the textual Haskell has Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HaXML - creating a simple document
Hello, I don't know why my simple example will not render a simple HTML document. For the moment, I simply want to render this: html /html or whatever, the simplest document is. When I run my source code, it simply hangs (as the transcript below shows) {- SOURCE CODE -} import Text.XML.HaXml.Html.Generate import Text.XML.HaXml.Combinators import Text.XML.HaXml.Wrappers main = processXmlWith go go = html [] {- EXECUTION TRANSCRIPT !-- ~/Documents/Haskell/haxml/mkElem tbrannon -- ghci mk.hs ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.6, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \/\/ /_/\/|_| Type :? for help. Loading package base ... linking ... done. [1 of 1] Compiling Main ( mk.hs, interpreted ) Ok, modules loaded: Main. *Main main Loading package haskell98 ... linking ... done. Loading package HaXml-1.17 ... linking ... done. -} ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaXML - creating a simple document
Hello, According to this page: http://www.cs.york.ac.uk/fp/HaXml/HaXml/Text-XML-HaXml-Wrappers.html processXmlWith is used to apply a filter to an existing XML document. By default, it will try to read the input document from stdin. So, I am imagine that is what it is doing -- sitting their waiting for you to input the document on stdin. It sounds like what you want to do is create a new html document from scratch -- not filter an existing document. I have never been very clear on how you are supposed to do this with HaXml... Also, creating html or xhtml documents with HaXml may be a bit tricky, because HaXml will try to use short tags whenever there is no content in the body. But, html does not always allow this. For example, an empty textarea in html must have distinct open and close tags: textarea/textarea But HaXml will try to use the short tag: textarea/ However, it looks like there is now a function, htmlprint :: [Content] - Doc http://www.cs.york.ac.uk/fp/HaXml/HaXml/Text-XML-HaXml-Html-Generate.html So may something like this would work: main = print $ htmlprint $ go (CString False ) go :: CFilter go = html [] I don't have HaXml install at the moment, so that may not type-check... j. At Sat, 30 Dec 2006 21:38:50 + (UTC), Terrence Brannon wrote: Hello, I don't know why my simple example will not render a simple HTML document. For the moment, I simply want to render this: html /html or whatever, the simplest document is. When I run my source code, it simply hangs (as the transcript below shows) {- SOURCE CODE -} import Text.XML.HaXml.Html.Generate import Text.XML.HaXml.Combinators import Text.XML.HaXml.Wrappers main = processXmlWith go go = html [] {- EXECUTION TRANSCRIPT !-- ~/Documents/Haskell/haxml/mkElem tbrannon -- ghci mk.hs ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.6, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \/\/ /_/\/|_| Type :? for help. Loading package base ... linking ... done. [1 of 1] Compiling Main ( mk.hs, interpreted ) Ok, modules loaded: Main. *Main main Loading package haskell98 ... linking ... done. Loading package HaXml-1.17 ... linking ... done. -} ___ 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] Re: HaXML - creating a simple document
On 12/30/06, Jeremy Shaw [EMAIL PROTECTED] wrote: So may something like this would work: main = print $ htmlprint $ go (CString False ) mk.hs:6:33: Couldn't match expected type `Content i' against inferred type `i1 - Content i1' In the first argument of `go', namely `(CString False )' In the second argument of `($)', namely `go (CString False )' In the second argument of `($)', namely `htmlprint $ (go (CString False ))' --- I modified it like this and got the error included in the comment: The type check error for your version is below. I include my modified source and associated error jeopardy style. Thanks for your efforts on this. import Text.XML.HaXml.Html.Generate import Text.XML.HaXml.Combinators import Text.XML.HaXml.XmlContent import Text.XML.HaXml.Wrappers main = print $ htmlprint $ go $ (CString False ) {- mk.hs:6:34: Couldn't match expected type `Content i' against inferred type `i1 - Content i1' In the second argument of `($)', namely `(CString False )' In the second argument of `($)', namely `go $ (CString False )' In the second argument of `($)', namely `htmlprint $ (go $ (CString False ))' -} go = html [] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: HaXML - creating a simple document
Actually, the examples directory in the distro for the development release has a nice program to create an element and print it to stdout called SimpleTestBool.hs: module Main where import List (isPrefixOf) import Text.XML.HaXml.XmlContent import Text.XML.HaXml.Types import Text.PrettyPrint.HughesPJ (render) import Text.XML.HaXml.Pretty (document) -- Test stuff --value1 :: ([(Bool,Int)],(String,Maybe Char)) value1 = True --main = do (putStrLn . render . document . toXml) value2 main = fWriteXml /dev/tty value1 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Socket Programming
I am trying to write a toy echo server that can handle multiple connections. I would like to be able to test and see if there are any connections waiting to be accepted on a socket. In C and related languages I would use something like select or poll to be nice to the OS, what would I use with the current haskell libs given that I can't seem to find a function to test if accept would block or not? -mdg -- Our problems are mostly behind us, now all we have to do is fight the solutions. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe