Re: [Haskell-cafe] Optimization problem

2006-09-15 Thread Ross Paterson
On Fri, Sep 15, 2006 at 05:13:29AM +0200, Bertram Felgenhauer wrote: > Just to prove the point, here's the same code with balancing: How embarrassing. Still, your code is quite subtle. As penance, here's my explanation, separating the main idea from the knot-tying. The ingredients are a map typ

Re: [Haskell-cafe] Why am I not allowed to use CStringLen inforeignexport?

2006-09-15 Thread Brian Hulley
Brian Hulley wrote: I assume that this means that on 32 bit Windows, the format of a BSTR is: Word16 -- low word of length Word16 -- high word of length Word16 -- first char of string ... The above is not quite correct. It appears from http://www.oreilly.com/catalog/win32api/c

Re: [Haskell-cafe] Why am I not allowed to use CStringLen in foreignexport?

2006-09-15 Thread Brian Hulley
Andreas Marth wrote: Hi! I try to export a Haskell function to VBA. (At the moment without COM.) Because VBA seems to expect a String with length information I tried to return a CStringLen as defined in Foreign.C.String. But if I try to compile it I get an "unacceptable argument type in foreign

[Haskell-cafe] Re[2]: [Haskell] Re: compiler-independent core libraries infrastructure

2006-09-15 Thread Bulat Ziganshin
Hello Neil, Friday, September 15, 2006, 8:12:34 PM, you wrote: > [Moving to cafe for follow up discussions] i should be started this discussion in libraries... :( > Yhc.Core, Hugs.Core, GHC.Core > With a different version for each compiler version. Tied intimately to > the compiler. > Th

[Haskell-cafe] Re: [Haskell] Re: compiler-independent core libraries infrastructure

2006-09-15 Thread Neil Mitchell
[Moving to cafe for follow up discussions] Hi Bulat, So, just to confirm in my mind what you are proposing: Compiler/Version specific Core: Yhc.Core, Hugs.Core, GHC.Core With a different version for each compiler version. Tied intimately to the compiler. The leveler: Core - which abstr

[Haskell-cafe] Why am I not allowed to use CStringLen in foreign export?

2006-09-15 Thread Andreas Marth
Hi! I try to export a Haskell function to VBA. (At the moment without COM.) Because VBA seems to expect a String with length information I tried to return a CStringLen as defined in Foreign.C.String. But if I try to compile it I get an "unacceptable argument type in foreign declaration: CStringLen

Re: [Haskell-cafe] Re: ambiguous partially defined type problem

2006-09-15 Thread Brian Hulley
Brian Hulley wrote: -- this change is not strictly necessary update :: a -> (a -> a) -> a Sorry - I just looked again at the instance decl for Node, so the above change should not be made. Apologies for the multiple posts, I must try to think more before clicking "send" ;-) Regards,

Re: [Haskell-cafe] Why is type 'b' forced to be type 'm a' and not possibly 'm a -> m a'

2006-09-15 Thread Anatoly Zaretsky
On 9/15/06, Vivian McPhail <[EMAIL PROTECTED]> wrote: class Forkable a where fork :: String -> a -> a -> a ... {- instance (Monad m, Forkable (m a), Forkable b) => Forkable (m a -> b) where fork n a1 a2 a = do a' <- a fork n (a1 $ return a') (a2

Re: [Haskell-cafe] Re: ambiguous partially defined type problem

2006-09-15 Thread Brian Hulley
Maarten wrote: Only update (see code below) is a bit ugly (I have no idea why I need fixCastUpdate) class (Show a, Typeable a) => ICustom a where [snip] update :: a -> (forall b. (ICustom b) => b -> b) -> a update a f = f a instance ICustom Node where getVal (Node n) f = getVal n f

Re: [Haskell-cafe] Re: Optimization problem

2006-09-15 Thread Henning Thielemann
On Thu, 14 Sep 2006, Bertram Felgenhauer wrote: > Magnus Jonsson wrote: > > Thanks Bertran for your solution. I have difficulty understanding it so I > > can't comment on it right now but I'll try to have a look at it. Do you > > know of any article that explains this technique, starting from v

Re: [Haskell-cafe] Re: ambiguous partially defined type problem

2006-09-15 Thread Brian Hulley
Maarten wrote: Only update (see code below) is a bit ugly (I have no idea why I need fixCastUpdate) update :: a -> (forall b. (ICustom b) => b -> b) -> a update a f = f a If you changed the type signature to: update :: a -> (a -> a) -> a would the code compile without fixCastUpdat

Re: [Haskell-cafe] Re: ambiguous partially defined type problem

2006-09-15 Thread Maarten
Dear Brian, Maarten wrote: Brian Hulley wrote: Alternatively, you could wrap the custom part within the node as in: data Node = forall cust. ICustom cust => Node cust Common getCommon :: Node -> Common getCommon (Node cust com) = com Thanks. This really helped. The main thing (I thi

Re: [Haskell-cafe] parsing long numbers

2006-09-15 Thread Niklas Broberg
The problem is that, when I run it with strings containing a number more then 10 digit long, I get unexpected integers back: *Main> runP number1 "1234567890 and the rest" [(1234567890," and the rest")] *Main> runP number1 "12345678901 and the rest" [(-539222987," and the rest")] This has nothin

[Haskell-cafe] parsing long numbers

2006-09-15 Thread Andrea Rossato
Hello! I'm trying to learn parsing and parser combinations in Haskell, using, as usual, Wadler's Monads in Functional Programming as my text book. Everything works fine except for a small but annoying problem related to "read". I'm sure it must be something easy, some kind of stupid faq. Still I'

Re: [Haskell-cafe] Wiki contact

2006-09-15 Thread Bulat Ziganshin
Hello Neil, Friday, September 15, 2006, 3:31:30 PM, you wrote: > 2) How do you go about contacting the person responsible for the wiki? > Is there a wiki page to drop messages off on? An email address? An > email list? - it confused me! http://haskell.org/haskellwiki/Haskell.org says that Ashley

Re: [Haskell-cafe] Re: Numeric type classes

2006-09-15 Thread Henning Thielemann
On Thu, 14 Sep 2006, David Menendez wrote: > Ross Paterson writes: > > > On Thu, Sep 14, 2006 at 01:11:56AM -0400, David Menendez wrote: > > > Coincidentally, I spent some time last week thinking about a > > > replacement for the Num class. I think I managed to come up with > > > something that'

Re: [Haskell-cafe] Re: evaluate vs seq

2006-09-15 Thread Lennart Augustsson
Sorry, it is of course Jan-Willem's compiler that is called Eager Haskell, the Ghc version was called optimistic Haskell. There's also the old precursor to these, the Optimistic G-machine, that performs some non-lazy computations. (And it can even do them while garbage collecting!)

Re: [Haskell-cafe] Optimization problem

2006-09-15 Thread Lennart Augustsson
I agree, the function can be tricky to use. But that's not our problem, we are only to implement it. :) On Sep 15, 2006, at 05:28 , Brian Brunswick wrote: On 15/09/06, Lennart Augustsson <[EMAIL PROTECTED]> wrote: On Sep 14, 2006, at 03:05 , Rohan Drape wrote: >>> splitStreams [(3,x),(

Re: [Haskell-cafe] Re: evaluate vs seq

2006-09-15 Thread Lennart Augustsson
No, I wasn't suggesting that evaluate can tell the difference, just that you can add dubious "functions". You can evaluate with eager evaluation and some kind of threads+fair scheduler. Both pH and the (short lived) Eager Haskell version of ghc did this. (Well, I'm not sure pH ever got th

Re: [Haskell-cafe] Anonymous types

2006-09-15 Thread Henning Thielemann
On Fri, 15 Sep 2006, Thomas Conway wrote: > Is there any deep and meaningful reason why Haskell doesn't have > anonymous discriminated union types? > > I'm thinking of an example like: > > data Amount = Amount Integer (Mg|G|Kg|T) > > Now this particular case is perhaps unconvincing - a seperat

Re: [Haskell-cafe] Bit string

2006-09-15 Thread Henning Thielemann
On Fri, 15 Sep 2006, Thomas Conway wrote: > My question for all present is: Have I missed either a problem with > using Integer, or have I overlooked a better representation? With my Modula background, where a machine-oriented SET type is available, I consider using integers as bit sets (as in D

[Haskell-cafe] Wiki contact

2006-09-15 Thread Neil Mitchell
Hi, Two questions: 1) Is there any way to get ... to be syntax hilighted as dots (or just leaft as is) on the Haskell wiki in tags, having it as _._ looks ugly - see http://haskell.org/haskellwiki/Keywords#where - note that the first and last dots are underlined hyperlinks. 2) How do you go ab

Re: [Haskell-cafe] Optimization problem

2006-09-15 Thread Rohan Drape
> It makes good sense. Each list will of events will be evaluated > lazily, so thing will appear there as they appear in the input. Indeed, thankyou. On a closer inspection I can in fact see that although the first value, (chn,[msgs]), will never appear, one can nonetheless start reading the [

Re: [Haskell-cafe] Re: evaluate vs seq

2006-09-15 Thread Janis Voigtlaender
[EMAIL PROTECTED] wrote: And what alternatives (besides call by name without sharing) are there? http://doi.acm.org/10.1145/944705.944731 http://doi.acm.org/10.1145/581690.581694 I always think lazy evaluation is space and time optimal. Google for "optimal reduction" (Lamping, Asperti, Gue

Re: [Haskell-cafe] Optimization problem

2006-09-15 Thread Brian Brunswick
On 15/09/06, Lennart Augustsson <[EMAIL PROTECTED]> wrote: On Sep 14, 2006, at 03:05 , Rohan Drape wrote:>>> splitStreams [(3,x),(1,y),(3,z),(2,w)]>> [(3,[x,z]),(1,[y]),(2,[w])]>> [snip]>>> Furthermore it should work on infinite lists. It can't eat the whole >> list before producing any output.>> T

[Haskell-cafe] Re: Optimization problem

2006-09-15 Thread apfelmus
[EMAIL PROTECTED] wrote: > type BiMap a b = (Map.Map a b, Map.Map b a) Actually BiMap is not needed at all, it suffices to have > splitStreams :: Ord a => [(a,b)] -> [(a,[b])] > splitStreams xs = > takeWhile (not . null . snd) $ toList $ splitStreams' Map.empty xs > > splitStreams' :: Ord a =

[Haskell-cafe] Re: foreach

2006-09-15 Thread apfelmus
Bulat Ziganshin wrote: > because REAL code is somewhat larger than examples. try to rewrite the > following: > > directory_blocks <- (`mapM` splitBy (opt_group_dir command) > files_to_archive) > ( \filesInOneDirectory -> do > datablocks <- (`mapM` splitToSolidBlocks filesInOneDir

[Haskell-cafe] Re: evaluate vs seq

2006-09-15 Thread apfelmus
Lennart Augustsson wrote: > No, you were right the first time. :) The denotational semantics is the > important one. Haskell can be executed by other means than graph > reduction. (That's why the report says a "non-strict" rather than > "lazy" language.) Peculiar language constructs may allow y

[Haskell-cafe] Re: Optimization problem

2006-09-15 Thread apfelmus
Ross Paterson wrote: > On Thu, Sep 14, 2006 at 05:22:05PM +0200, Bertram Felgenhauer wrote: >> [much subtle code] >> We can now build the splitStream function, using the following helper >> function: >> >>> splitSeq' :: Ord a => Map a () -> [(a,b)] -> ([(a,[b])], Map a [b]) > > This works for infi