Re: [Haskell-cafe] Re: Generate 50 random coordinates
Henning Thielemann wrote: On Sat, 2 Dec 2006 [EMAIL PROTECTED] wrote: -- The IO -- Who rides so late through the bits and the bytes? It's Haskell with his child Hank; He has the boy type safe in his arm, He holds him pure, he holds him warm. I vote for an art/lyrics section on HaskellWiki. Haskell-café: karaoke every Saturday! -k ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] RE: Safe forking question
[ duh, hit send by mistake, message continues... ] Chris Kuklewicz wrote: forkInheritIO :: IO () - IO ThreadId -- inherits parent's block or unblock status forkBlockedIO :: IO () - IO ThreadId -- starts the action in block mode. Must manually unblock Either of these is certainly possible, and I agree that forkBlockedIO is more generally useful than my forkCatchIO. One tantalising possibility is that we could make forkIO have the forkInheritIO behaviour without breaking much code, since I bet forkIO is almost never called inside block. Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Draft MissingH Reorg Plan
John Goerzen [EMAIL PROTECTED] wrote: About Text.ParserCombinators.Parsec.RFC2234 and the like. ... ... you do not in fact define any new combinators for parsing. What you have there is a parser This module provides parsers for the grammar defined in RFC2234, alpha :: CharParser st Char bit :: CharParser st Char character :: CharParser st Char cr :: CharParser st Char Yes, I do see the point that these are rather generic and basic parsers. (But they are not combinators as such, just alternative primitives of the domain-specific parsing language.) I guess they could easily live with Parsec after all, unless there is an obviously better place for them in the hierarchy. Does the above suggest a single good place for them to you? You mean, for the constructed parsers, as well as the basics? I suppose I would go for much the same suggestions as before, apart from RFC2234: Text.ParserCombinators.Parsec.RFC2234 Network.SMTP.RFC2821.Parse Network.Email.RFC2822.Parse Conceivably, you might want to drop the RFC part of the latter two names, and merely refer users to the relevant RFC in the Haddock docs? Network.SMTP.Parse Network.Email.Parse Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Safe forking question
On Mon, Dec 04, 2006 at 12:43:00PM +, Simon Marlow wrote: Chris Kuklewicz wrote: forkInheritIO :: IO () - IO ThreadId -- inherits parent's block or unblock status forkBlockedIO :: IO () - IO ThreadId -- starts the action in block mode. Must manually unblock Either of these is certainly possible, and I agree that forkBlockedIO is more generally useful than my forkCatchIO. One tantalising possibility is that we could make forkIO have the forkInheritIO behaviour without breaking much code, since I bet forkIO is almost never called inside block. This would indeed be tantalizing (speaking as someone who hasn't used concurrent Haskell in five or so years, and spelling as an american), but mightn't it lead to hard-to-find bugs where people happen to be calling forkIO when they're in blocked mode? Both block and asynchronous exceptions are relatively rare, but they do occur together, and where they occur, programmers must have carefully thought out how they interact. -- David Roundy Department of Physics Oregon State University ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: help with threadDelay
On Wed, Nov 29, 2006 at 10:57:52AM +, Neil Davies wrote: In order to get low jitter you have to deliberately wake up early and spin - hey what are all these extra cores for! - knowing the quantisation of the RTS is useful in calibration loop for how much to wake up early. Ah, I see. Timing how long a threadDelay 1 takes and subtracting that from future threadDelays is probably the best answer. Thanks Ian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] known, I know: class contexts and mutual recursion
On Wed, Nov 29, 2006 at 06:14:56PM +, Conor McBride wrote: Mmm.lhs:15:1: Contexts differ in length When matching the contexts of the signatures for foo :: forall (m :: * - *). (Monad m) = Thing - m Int goo :: Thing - (Maybe Int - Int) - Int The signature contexts in a mutually recursive group should all be identical Poking about on the web, I got the impression that this was a known infelicity in ghc 6.4 (which I'm using), due to be ironed out. However, an early-adopting colleague with 6.6 alleges that foo-goo is still poisonous. You can compile it with 6.6 if you use -fglasgow-exts. It's not clear to me whether this will always work, e.g. if you have higher rank types floating around, but if it does then we should add a hint to the error; Simon? I'm wondering what the story is. I mean, is there some nasty problem lurking here which prevents the lifting of this peculiar restriction? I don't know either, but this sounds like a good thing to bring up for Haskell' if no-one has already. Thanks Ian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Four Fours problem in Haskell
Hi, This might be interesting for some of you (I hope): http://www.joachim-breitner.de/blog/archives/210-FourFours-in-Haskell.html Preview: An interesting programming puzzle appeard in the Blogosphere: To describe every integer from 1 to 100 as a calculation involving only and exactly four fours, and standard operations. There are solutions in C# (code) and in python (code), so I tried to do mine in Haskell. This seems to be meant for Haskell. The Type system makes the program really great to read. Functional programming allows me to conveniently create all possible associations of four operands with three binary operations. (I found five. Why are the other two sources using four?) And, in this program particular, the use of the list monad to quickly generate a list of all possible combination is really a programming-time-saver. The program is not too slow either: $ time ./fourfour/dev/null real0m0.917s user0m0.852s sys 0m0.040s And it could probably be sped up by using some kind of hashing or similar stuffs. Note that the program has only 73 mostly quite short lines, while the python code has 119 and the C# code has 138 of relatively long lines (comments and empty lines not counted). I think this is impressive (unless you have worked with haskell a bit, then you are used to these kind of results). Comments welcome! Thanks, Joachim -- Joachim nomeata Breitner mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/ Debian Developer: [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] File locked unnecessarily
On Sun, Dec 03, 2006 at 08:13:37PM +0100, Arie Peterson wrote: Does anyone know what could cause this locking and/or how to prevent it? Nothing else springs to mind. Are you able to send an example that shows the problem? (obviously the smaller the example, the better). Thanks Ian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] known, I know: class contexts and mutual recursion
Hello, I just tripped over the Contexts differ in length error message. I know it's not a new problem, but I thought I'd enquire as to its status. I have run into that a number of times. There aren't any technical issues with solving it, in fact, depending on how one implements the type checker, it is more work to implement this extra restriction (Hugs and THIH don't impose this restriction). The basic idea is that we check values with explicit signatures after we have finished type inference. While we do type inference we may simply assume that the values have their specified types. It is proposed for fixing in Haskell' but I was surprised that it did not seem to appear on the definitely in list (as far as I can recall---I might be wrong). Hopefully the report will be fixed though. Otherwise, as Ian mentioned, it works in GHC 6.6 with -fglasgow-exts. Also, there should be no problems with higher-ranked types etc. -Iavor On 11/29/06, Conor McBride [EMAIL PROTECTED] wrote: For those of you who haven't seen it, here's an example, contrived but compact. data Thing = Val Int | Grok Thing (Maybe Int - Int) eval :: Monad m = Thing - m Int eval (Val i) = return i eval (Grok t f) = return (f (eval t)) My eval function compiles ok. See? The recursive call to eval targets the Maybe monad, so I get *Mmm eval (Grok (Val 5) (maybe 0 (1 +))) :: Maybe Int Just 6 However, when I try to decompose eval as a pair of mutually recursive functions, namely foo :: Monad m = Thing - m Int foo (Val i) = return i foo (Grok t f) = return (goo t f) goo :: Thing - (Maybe Int - Int) - Int goo t f = f (foo t) I get Mmm.lhs:15:1: Contexts differ in length When matching the contexts of the signatures for foo :: forall (m :: * - *). (Monad m) = Thing - m Int goo :: Thing - (Maybe Int - Int) - Int The signature contexts in a mutually recursive group should all be identical Poking about on the web, I got the impression that this was a known infelicity in ghc 6.4 (which I'm using), due to be ironed out. However, an early-adopting colleague with 6.6 alleges that foo-goo is still poisonous. I'm wondering what the story is. I mean, is there some nasty problem lurking here which prevents the lifting of this peculiar restriction? I'm not in a panic about this. I have a workaround for the problem as I encountered it in practice. Mind you, it's the sort of thing that's likely to happen more often, the more you localise the effects you tend to use. In the above, goo doesn't throw exceptions; rather, because goo has a handler, it can offer a /local/ exception-throwing capability to foo. Curious Conor ___ 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] known, I know: class contexts and mutual recursion
On Mon, Dec 04, 2006 at 05:21:15PM +, Ian Lynagh wrote: On Wed, Nov 29, 2006 at 06:14:56PM +, Conor McBride wrote: Mmm.lhs:15:1: Contexts differ in length When matching the contexts of the signatures for foo :: forall (m :: * - *). (Monad m) = Thing - m Int goo :: Thing - (Maybe Int - Int) - Int The signature contexts in a mutually recursive group should all be identical Poking about on the web, I got the impression that this was a known infelicity in ghc 6.4 (which I'm using), due to be ironed out. However, an early-adopting colleague with 6.6 alleges that foo-goo is still poisonous. You can compile it with 6.6 if you use -fglasgow-exts. It's not clear to me whether this will always work, e.g. if you have higher rank types floating around, but if it does then we should add a hint to the error; Simon? I'm wondering what the story is. I mean, is there some nasty problem lurking here which prevents the lifting of this peculiar restriction? I don't know either, but this sounds like a good thing to bring up for Haskell' if no-one has already. Haskell 98 mandates this behaviour: s4.5.2 says the types of all functions in a dependency group must have the same context, even if they have explicit signatures. Haskell' ticket #65 (RelaxedDependencyAnalysis) proposes that dependencies on variables with explicit signatures should be ignored by the dependency analysis. With that change, if you provided signatures for foo or goo, or both, they'd be in different dependency groups and not required to have the same context. One could argue that this change should have been made when polymorphic recursion was permitted. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] known, I know: class contexts and mutual recursion
Hi Iavor Diatchki wrote: Hello, I just tripped over the Contexts differ in length error message. I know it's not a new problem, but I thought I'd enquire as to its status. I have run into that a number of times. There aren't any technical issues with solving it, in fact, depending on how one implements the type checker, it is more work to implement this extra restriction Yes, that's what I would expect. It's an inevitable but not threatening consequence of polymorphic recursion. It rather surprised me that just telling the machine what my plan was (something I always do anyway) produced such an objection. It is proposed for fixing in Haskell' but I was surprised that it did not seem to appear on the definitely in list (as far as I can recall---I might be wrong). From what I can tell, it's probably in. Strikes me as fairly essential. I don't expect artificial restrictions to be placed on the types of my programs when I am willing to make those types explicit. Hopefully the report will be fixed though. Otherwise, as Ian mentioned, it works in GHC 6.6 with -fglasgow-exts. Also, there should be no problems with higher-ranked types etc. Thanks for the tip, Ian. I guess I shouldn't put off installing 6.6 any longer. All the best Conor ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] (a - [b]) - [a - b] ?
On 12/4/06, Joachim Breitner [EMAIL PROTECTED] wrote: \g - map (\n a - g a !! n) [1..] I think that's about as good as it gets. -- Taral [EMAIL PROTECTED] You can't prove anything. -- Gödel's Incompetence Theorem ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] (a - [b]) - [a - b] ?
It seems there's an assumption about the range of the parameter function and the range of the entire function. That is, I think we're assuming that the length of the final result is the same as the length of the result of the first function? If I'm correct in presuming that constraint, then I think this indicates that a more elegant solution might involve using the lightweight-dependently-typed vectors approach. Though I can't promise it will actually be nicer! Nick On 12/4/06, Joachim Breitner [EMAIL PROTECTED] wrote: Hi, while pondering over the four fours problem, I wondered: Is there a function of type (a - [b]) - [a - b] It looks a bit like sequence when applied in the ((-) a) Monad: sequence :: [a - b] - a - [b] but I was looking for the other direction. I came up with: \g - map (\n a - g a !! n) [1..] which has the desired type and functionality, but it looks rather inelegant and messy. Any better ideas? Thanks, Joachim -- Joachim nomeata Breitner mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/ Debian Developer: [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
Re: [Haskell-cafe] (a - [b]) - [a - b] ?
Hi, Am Montag, den 04.12.2006, 13:12 -0600 schrieb Nicolas Frisby: It seems there's an assumption about the range of the parameter function and the range of the entire function. That is, I think we're assuming that the length of the final result is the same as the length of the result of the first function? Ah, of course, I forgot to mention to say what the function should do :-) If we call in unsequence, the following should be true for f::(a - [b]) and v::a f v == map (\g - g v) (unsequence f) Let’s see if I can prove that my suggested solution is correct: f v == map (\g - g v) (map (\n a - f a !! n) [1..]) == map ((\g - g v) . (\n a - f a !! n)) [1..] == map ((\n - (f v !! n)) [1..] * here I use that map (\n - l !!n ) [1..] == l. I hope that is valid == f v Ok, looks good. But still, I don’t like this solution with (!!) for some reason. Thanks, Joachim On 12/4/06, Joachim Breitner [EMAIL PROTECTED] wrote: Hi, while pondering over the four fours problem, I wondered: Is there a function of type (a - [b]) - [a - b] It looks a bit like sequence when applied in the ((-) a) Monad: sequence :: [a - b] - a - [b] but I was looking for the other direction. I came up with: \g - map (\n a - g a !! n) [1..] which has the desired type and functionality, but it looks rather inelegant and messy. Any better ideas? Thanks, Joachim -- Joachim nomeata Breitner mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/ Debian Developer: [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Joachim nomeata Breitner mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/ Debian Developer: [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] (a - [b]) - [a - b] ?
On Mon, Dec 04, 2006 at 07:00:23PM +, Joachim Breitner wrote: I came up with: \g - map (\n a - g a !! n) [1..] which has the desired type and functionality, but it looks rather inelegant and messy. Any better ideas? I like sequence a2bs = (head . a2bs) : sequence (tail . a2bs) This also makes it explicit that by golly your function had better return an infinite list, or we're in trouble. -- David Roundy Department of Physics Oregon State University ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] (a - [b]) - [a - b] ?
Joachim Breitner: here I use that map (\n - l !!n ) [1..] == l. I hope that is valid map (\n - l !! n) [1..] is more like (tail l). Did you mean to use [0..]? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] (a - [b]) - [a - b] ?
Hi, Am Dienstag, den 05.12.2006, 05:59 +1000 schrieb Matthew Brecknell: Joachim Breitner: here I use that map (\n - l !!n ) [1..] == l. I hope that is valid map (\n - l !! n) [1..] is more like (tail l). Did you mean to use [0..]? Probably. I hardly use (!!), so I did not remember if it starts with 0 or 1. Thanks for the hint, Joachim -- Joachim Breitner e-Mail: [EMAIL PROTECTED] Homepage: http://www.joachim-breitner.de ICQ#: 74513189 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] using greencard to write COM in haskell
One of the goals for greencard ( http://www.cs.york.ac.uk/fp/nhc13/greencard.html#SEC2 ) is: A convenient way to write COM software components in Haskell, and to call COM components from Haskell. Are there any examples of the first goal. I would like to be able to write COM components in Haskell, so far I found this example of calling haskell form C: http://www.cs.york.ac.uk/fp/nhc13/CcallingHaskell.html From what i understand form that example is that you register a bunch of haskell functions with your C program. So is there a way to start haskell form C? Ideally i would like something thats as easy to use as a dll, that the end use wouldn't be aware that they are using a component written in haskell. Also, I would like to have my haskell programs use my implementation of realloc which takes a context, is there an easy way to change ghc to use it? I guess I should start looking at the ghc source. Thanks, Anatoly ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] '+++' and 'interleave'
Could ReadP's '+++' (symmetric choice) operator be implemented for all Monads with the 'interleave' function mentioned in Backtracking, Interleaving, and Terminating Monad Transformershttp://portal.acm.org/ft_gateway.cfm?id=1086390type=pdfcoll=GUIDEdl=GUIDECFID=5430836CFTOKEN=76321932? This paper was a tough read for me, but it looks like they solve the same problem, but one interleaves computations within a monad and the other does it from the outside. Or am I just confused? Thanks, Greg ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Beginner: IORef constructor?
Bernie Pope wrote: If you want a global variable then you can use something like: import System.IO.Unsafe (unsafePerformIO) global = unsafePerformIO (newIORef []) But this is often regarded as bad programming style (depends who you talk to). Besides, isn't this example /really/ unsafe? I thought, at least the IORef has to be monomorphic or else type safety is lost? Cheers Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] using greencard to write COM in haskell
On 12/4/06, Anatoly Yakovenko [EMAIL PROTECTED] wrote: So is there a way to start haskell form C? Ideally i would like something thats as easy to use as a dll, that the end use wouldn't be aware that they are using a component written in haskell. The things described at this URL have worked for me when it comes to DLLs and starting GHC's RTS: http://www.haskell.org/ghc/docs/latest/html/users_guide/win32-dlls.html HTH, Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] SYB, ext1Q, and deriving custom Typeable and Data instances
Hi, I'm trying to use SYB to implement some basic relational persistance. I define a PKey datatype to represent primary keys like this: newtype PKey a = PKey a deriving (Show, Typeable, Data) I then define a sample data type like this: data User = User { id :: PKey Int, firstName :: String, lastName :: String, } deriving (Show, Typeable, Data) Finally, I try to iterate over the structure like this: test = gmapQ (gshow `ext1Q` aux) where aux :: PKey a - String aux _ = test The problem is that for id gmapQ calls gshow instead of my customized version (aux). I've seen a discussion on this on haskell cafe at the following URL: http://www.opensubscriber.com/message/haskell-cafe@haskell.org/2167871.html I couldn't understand the following details: 1. Do I need to derive both Typeable and Data instances? 2. Do I need to derive them for both PKey and User or just PKey? 3. Where can I find sample code to derive these instances? Documentation shows a sample of how GHC derives Data, is that a good template to use? Also, what's a good example to derive Typeable (if in fact it needs to be done manually)? Thanks, - Slava. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] using greencard to write COM in haskell
Thanks, this is exactly what i was looking for. On 12/4/06, Jason Dagit [EMAIL PROTECTED] wrote: On 12/4/06, Anatoly Yakovenko [EMAIL PROTECTED] wrote: So is there a way to start haskell form C? Ideally i would like something thats as easy to use as a dll, that the end use wouldn't be aware that they are using a component written in haskell. The things described at this URL have worked for me when it comes to DLLs and starting GHC's RTS: http://www.haskell.org/ghc/docs/latest/html/users_guide/win32-dlls.html HTH, Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe