Re: [Haskell-cafe] Fast sorting with Bytestring
On Wed, Jun 18, 2008 at 08:19:10PM +0200, Georg Sauthoff wrote: Hi, I played a bit around with the nice bytestring package. At some point I implemented a simple sorting program, because I needed line-sorting a file with a custom line-compare function. I was a bit surprised, that the resulting code is very fast. A lot of faster than sorting via GNU sort (with the standard line-compare function). Then I got suspicious and tested standard GNU sort against a trivial standard sort implementation in Haskell using bytestring. The Haskell implementation looks like: [snip] Ok, strane ... Well, let's test with some 'normal' text: time ./sort bible /dev/null # ~ 0.4 s time sort bible /dev/null # ~ 0.56 s Ok, not that different. But with Haskell you often expect to get very slow code compared to an implementation in C. And I am surprised, that the Haskell is fast _and_ nice to read - because for example the ultra fast 'wc -l' Haskell implementation from the Haskell-Wiki uses some insider-knowledge about bytestring, and looks to a beginner not that intuitive, I guess. ./sort is the shown Haskell implementation. I used ghc 6.8.2, installed bytestring 0.9.1.0 as a user-local package (don't now I this superseeds the global bytestring package), compiled via ghc -O2. The tests are run at a Pentium M 1.3 GHz computer. As GNU sort I tested the version from coreutils 6.9. You can get the test files from: http://www.techfak.uni-bielefeld.de/~gsauthof/stuff/brackets.gz http://www.techfak.uni-bielefeld.de/~gsauthof/stuff/bible.gz (obviously, you have to gunzip them after downloading ...) Of course, the naive Haskell implementation doesn't care about locales (i.e. collating locale sequences), but this shouldn't explain the observed differences sorting the brackets file. GNU 'sort' uses an external sort algorithm. You can, with 200M of memory, give it a 50G input file, and it will work. This might explain the difference.. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Glome.hs-0.3 and other things
On Mon, Apr 21, 2008 at 07:54:24PM +0100, Andrew Coppin wrote: Jim Snow wrote: Useful references: What Every Programmer Needs to Know About Memory http://lwn.net/Articles/250967/ After studying all this material, I do find myself feeling slightly concerned. The article shows how in C / C++ / assembly you can arrange your data and order your computations to make maximum use of the various caches and avoid certain bottlenecks in the system. And the *vast* performance difference it can yield. But what happens if you happen to be writing your program in Smalltalk or Java or... Haskell. Up here, you're so far from the hardware that it would seem that you have *no hope* of using the CPU caches effectively. Think about it - data scattered all over the heap in an essentially random pattern, getting moved around periodically by the GC. [Oh, the GC! That sounds like it must nail the hell out of the cache. And even if it doesn't, it more or less negates its usefulness because all the hot data is now at a different address.] Just think about trying to process a Haskell list - all those multiple levels of pointer indirection! The CPU has no hope of prefetching that stuff... Damn, it seems as if there's simply no way of ever making Haskell fast. :-( You're assuming the hardware is constant. Modern CPUs were designed back when everyone was using C++; this is changing now, and I for one am still optimistic that CPU designs will follow suit. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] The range operator
On Fri, Apr 04, 2008 at 08:58:06PM +0100, PR Stanley wrote: Hi folks [x, y..z] What's the role of x? Cheers, Paul First number in the output; also all pairs differ as much as the first two numbers do. Try e.g [1, 2 .. 10] and [0, 2 .. 10] Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] compilation succeeds -- execution fails
On Sat, Mar 29, 2008 at 10:21:32PM -0700, Jason Dusek wrote: Stefan O'Rear [EMAIL PROTECTED] wrote: The only type that you are allowed to assume corresponds to a C int is CInt, in the Foreign.C.Types module. This probably isn't the problem, but it could make problems of its own on a 64-bit or otherwise weird system. So say I turn everything back to pointers to CInt, what is the accepted way to convert from CInt to Int Same as any other pair of whole-number types - fromIntegral. and CInt to Char? fromIntegral and toEnum Is relying on the fact that CInt always wraps a Haskell integer an okay way to go? What do you mean by wraps? It's an opaque type... Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] compilation succeeds -- execution fails
On Fri, Mar 28, 2008 at 11:33:52AM -0700, Jason Dusek wrote: Thomas Schilling [EMAIL PROTECTED] wrote: Did you try removing all .hi and .o files? Yes. I tried it again this morning, and I've got the same error -- same unknown symbol, c. I don't have trouble with most Haskell programs on my Mac, so I assume it's the way I'm connecting to C that is the problem. I've pasted in the relevant code below my signature -- it seems plain enough to me, but I've not done much with foreign declarations. The `Ptr Char` declarations, for example, point to things which are actually C ints -- they are all valid Unicode code points, so I figure there's no harm done. The only type that you are allowed to assume corresponds to a C int is CInt, in the Foreign.C.Types module. This probably isn't the problem, but it could make problems of its own on a 64-bit or otherwise weird system. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Termination of substitution
On Wed, Mar 12, 2008 at 09:05:03PM +, Neil Mitchell wrote: Hi I'm trying to show that a system of rules for manipulating Haskell expressions is terminating. The rules can be applied in any order, to any subexpression - and there is a problem if there is any possible infinite sequence. The rule that is giving me particular problems is: (\v - x) y = x[v/y] (I realise this rule may duplicate the computation of y, but that is not relevant for this purpose.) In particular, given the expression (\x - x x) (\x - x x) we can keep applying this rule infinitely. However, I don't believe this expression is type safe in Haskell. Are any such expressions that would cause this to non-terminate not type safe? I think you mean all, and the answer is no, but. (Very interesting topic here, for me at least.) Haskell's core type system (let, lambda, and application) can be mapped into the simply-typed lambda calculus by macro-expanding lets, and (by the construction of the Hindley-Milner type system) this mapping is typability-preserving. The simply-typed lambda calculus is not only terminating, it is strongly normalizing - ALL possible reduction sequences stop eventually. (There is a very elegant proof of this). The addition of data types in full generality breaks this: newtype Curry o = Curry { unCurry :: Curry o - o } loop :: o loop = (\c - unCurry c c) (Curry (\c - unCurry c c)) Systems like Coq, which need to preserve strong normalization for logical soundness, adopt a variety of syntactic restrictions. Coq specifically forbids contravariant recursion in types. What are the necessary conditions for this to be safe? Does GHC perform lambda reduction, probably by introducing a let binding? Does the combination of reducing lambdas and creating let bindings give similar problems, particularly if bindings are inlined? Yes. If you feed that example into GHC, GHC will crash (even with the optimizer off). Works fine in Hugs/Yhc. http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs.html#bugs-ghc I'm wondering if this rule is genuinely unsafe in Haskell. If it is, why isn't it an issue in real simplifiers. If it isn't, what makes it safe. Nobody but us logic fans actually writes encodings of Curry's Paradox. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Termination of substitution
On Wed, Mar 12, 2008 at 02:30:41PM -0700, Taral wrote: On 3/12/08, Neil Mitchell [EMAIL PROTECTED] wrote: However, I don't believe this expression is type safe in Haskell. Using higher-order polymorphism: f (x :: forall a. a - a) = x x Interestingly, this doesn't work - f is a self-application function, but it does not have a type that can be made to look like forall a. a - a. Indeed, higher-order polymorphism as implemented in GHC can be implemented in System F-omega, a strongly normalizing calculus. (The usual datatype caveats apply). Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Assembly decoding help?
On Tue, Mar 04, 2008 at 05:07:03PM -0800, Justin Bailey wrote: I'm trying to get a feel for the assembly output by GHC on my platform. Below is a module containing one function and the associated assembly. I've put in comments what I think is going on, but I'd appreciate it if anyone could give me some pointers. I'd really like to know three things: * Why does _Add_unsafeShiftR_info check if (%esi) is 3? * What's going on in _s86_info? * At the end of _s87_info, 8 is added to %ebp and then jumped to. Is that a jump to the I# constructor and, if so, how did it's address get to that offset from %ebp? Thanks in advance for any assistance! It would be more helpful if you didn't try to go from Haskell to assembly in one step - it's a lot easier to understand each big step of the GHC pipeline individually. Haskell | \- Core (ghc -ddump-simpl Foo.hs Foo.core; or -fext-core if you want something ugly but parsable; an unrestricted but simple expression-functional language) | \- STG (ghc -ddump-stg ...) (Much more regular than Core; more like functional C) | \- C-- (ghc -ddump-cmm) (just what it says: Simplified C for compiler writers. The universal assembly language for the 21st century) | \- assembly Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] fast integer base-2 log function?
On Tue, Feb 26, 2008 at 09:33:57PM +, Jens Blanck wrote: {-# LANGUAGE MagicHash #-} import GHC.Exts import Data.Bits -- experiment with using a LUT here (hint: FFI + static arrays in C) ilog2i0, ilog2i1, ilog2i2, ilog2i3, ilog2i4 :: Int - Int - Int ilog2i0 k x | x .. 0x /= 0 = ilog2i1 (k + 16) (x `shiftR` 16) | otherwise = ilog2i1 k x ilog2i1 k x | x .. 0xFF00 /= 0 = ilog2i2 (k + 8) (x `shiftR` 8) | otherwise = ilog2i2 k x ilog2i2 k x | x .. 0xF0 /= 0 = ilog2i3 (k + 4) (x `shiftR` 4) | otherwise = ilog2i3 k x ilog2i3 k x | x .. 0xC /= 0= ilog2i4 (k + 2) (x `shiftR` 2) | otherwise = ilog2i4 k x ilog2i4 k x | x .. 0x2 /= 0= k + 1 + (x `shiftR` 1) | otherwise = k + x log2i :: Integer - Int -- actually returns bit length, and returns garbage on negatives, but do you care? log2i (J# len adr) = ilog2i0 0 (I# (indexIntArray# adr (len -# 1#))) + I# (32# *# (len -# 1#)) log2i (S# sml) = ilog2i0 0 (I# sml) I tried the above but I got wrong results on 2^31..2^32-1 because in the additions in ilog2i4, the number x was -1 because of sign extension performed by the shifts all the way (thanks for the ghci debugger). (So, yes, I do care somewhat about garbage on negatives :) This is what you get for only testing on 100 and 2^34, I guess :) If you change all the Int to Word (unsigned) it should work. Should. I modified to the following hoping also to use both on 32 and 64 bit machines. Have I shot myself in the foot anyway? For example, is there a guarantee that the most significant limb is non-zero? Is there any possibility of this or some related function being added to Data.Bits? [snip code] It's still not going to be portable because I'm hardwiring the GMP nail count parameter to 0. As for going standard - if you want this, propose it! I can't think of a sane implementation of Integer that doesn't support some kind of approximate logarithm. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Binary IEEE floating point format for AMQP
On Sun, Feb 24, 2008 at 12:21:00PM +, Paul Johnson wrote: I'm working on an implementation of the framing layer for AMQP (www.amqp.org). I almost had 0.9 finished when I found they had released the spec for 0.10, so I have to redo quite a lot of work. Amongst the new features of 0.10 are wire formats for floating point. These are the 4 and 8 byte IEEE formats. * Is there a principled way of converting a Haskell Float or Double (or Rational, for that matter) to and from IEEE format? * Since many computers use IEEE format natively, is there a quicker way of doing this on those architectures? {-# LANGUAGE MagicHash #-} import Data.Int import GHC.Exts foo :: Double - Int64 --ghc only foo (D# x) = I64# (unsafeCoerce# x) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Where does ~ come from?
On Wed, Feb 20, 2008 at 07:18:42PM -0500, Steve Lihn wrote: If ~ does not have any special meaning and it could be ### or xyz, then how does GHC know to print a ~ b, but not ~ a b a ### b, but not ### a b xyz a b, but not a `xyz` b Simply because xyz is alphanumeric? Yes. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: a help for install
On Mon, Feb 18, 2008 at 12:46:19PM -0600, Carlos Gomez A. wrote: hi, my name is carlos I need information for correct installor what are dependencies on ghc ? I have a Debian System. I have this message error to install the ghc: Debian-System/haskell/ghc-6.8.2# ./configure checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking target system type... i686-pc-linux-gnu Canonicalised to: i386-unknown-linux checking for ghc... no checking for ghc-pkg matching ... no checking for ghc-pkg... no checking whether ghc has readline package... no checking for nhc... no checking for nhc98... no checking for hbc... no checking for ld... /usr/bin/ld configure: error: GHC is required unless bootstrapping from .hc files. Debian-System/haskell/ghc-6.8.2# As the message indicatied, you need GHC if you want to install from source. If you don't have GHC, get a binary (there is one in apt). Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: ghci feature request: partially read modules
On Sat, Feb 16, 2008 at 04:53:24PM +0100, Johannes Waldmann wrote: Hello. Here is one ghci feature that I find mildly annoying: If ghci (re-)reads a module that contains some error, then it considers the module loading as a complete failure, and at the prompt I get the Prelude environment. I'd like to have at least the import statements executed, and possibly the declarations that were error-free. That would help me in interactively debugging the erraneous part of the module. (Often the error is some type error, related to some imported entity; but when my module contains the error, then the imports are gone.) Perhaps I'm doing something wrong, then please educate me; or perhaps there's an easy way to implement partial reading and typechecking. (It'd be enough to have this for the current module, of course.) Thanks - Johannes Waldmann. This is fairly easy for type errors - just have the 'type of expression' function return errors using Either etc, and at the top level drop all expressions with error type. As for parse errors - good luck. Haskell is incredibly difficult to parse even if you ignore several of its less-friendly features. If you allow them... for a long time I said it had never even been proven possible, but then I found a workable algorithm exponential in the file size. Now, how do you propose handling parse errors? Here's an example of why it's hardly trivial: foo = x + y + z where { x = 2; y = 3; z = 4; } Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: ghci feature request: partially read modules
On Sat, Feb 16, 2008 at 06:58:29PM +0100, Johannes Waldmann wrote: Sure. Syntax errors are usually easy to spot and fix (for the programmer who uses some reasonable code layout); the motivation for my proposal was type errors. I think it would be perfectly acceptable if ghci rejects modules with parse errors (as it does now) but handles modules with type errors more gracefully. Since type checking a group of declarations (= a module) often considers all declarations at the same time, there may be no sensible way to proceed after a type error. Then it would even be OK to not bind any of the identifiers of the module, as long as the import declarations are available at ghci prompt. (This would still be an improvement over the present situation.) Implementing Haskell polymorphism requires that the functions be sorted into dependancy groups, so that undepended definitions can be generalized. Example: foo x = 2 bar = foo 'a' + foo True If this were typechecked all at once (using the standard Damas-Milner algorithm) you would get a cannot match Bool to Char type error. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] GHC strange behavior
On Sun, Feb 17, 2008 at 03:07:15AM +0300, Ruslan Evdokimov wrote: 2008/2/17, Jonathan Cast [EMAIL PROTECTED]: Wild guess? If you leave o as a thunk, to be evaluated once the program has e, then it has numbers, so you keep the entire 10-million entry list in memory. Evaluating e and o in parallel allows the system to start garbage collecting cons cells from numbers much earlier, which reduces residency (I'd've been unsuprised at more than two orders of magnitude). Managing the smaller heap (and especially not having to copy numbers on each GC) then makes the garbage collector go much faster, so you get a smaller run time. But I also tested it on P-IV 3.0 with HT and 1GB (single core) running Windows-XP (ghc 6.8.2), and it works fine (fast low GC) in all three cases without significant difference. Sure it didn't runs faster with -N2 'cause it's not dual-core. This makes perfect sense - -N2 tells GHC to use two threads, and if you run two threads on a single-processor system it's implemented by running the threads alternatingly (around 100/s for modern Linux, probably similar for other systems). Thus, the two evaluations never get more than a hundreth of a second out of step, and memory usage is still low. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC strange behavior
On Sun, Feb 17, 2008 at 03:41:52AM +0300, Ruslan Evdokimov wrote: 2008/2/17, Stefan O'Rear [EMAIL PROTECTED]: This makes perfect sense - -N2 tells GHC to use two threads, and if you run two threads on a single-processor system it's implemented by running the threads alternatingly (around 100/s for modern Linux, probably similar for other systems). Thus, the two evaluations never get more than a hundreth of a second out of step, and memory usage is still low. Stefan Test on windows XP AthlonX2 4200+ 2Gb: C:\imptest 1 12328 ms C:\imptest +RTS -N2 1 5234 ms C:\imptest +RTS -N2 1 3515 ms 1st - 1 thread 2nd - 2 threads on single core (one core disabled through Task Manager) 3rd - 2 threads on different cores As far as I can tell, that confirms my explanation. If you see it differently - say how. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Doubting Haskell
On Sat, Feb 16, 2008 at 05:11:59PM -0800, Bryan O'Sullivan wrote: Donn Cave wrote: But in Haskell, you cannot read a file line by line without writing an exception handler, because end of file is an exception! Ah, yet another person who has never found System.IO.hIsEOF :-) Whereas in C or Python you would check the return value of read against zero or an empty string, in Haskell you call hIsEOF *before* a read. I'll bet that breaks horribly in the not-so-corner case of /dev/tty. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Doubting Haskell
On Sat, Feb 16, 2008 at 06:23:54PM -0800, Bryan O'Sullivan wrote: Stefan O'Rear wrote: I'll bet that breaks horribly in the not-so-corner case of /dev/tty. Actually, it doesn't. It seems to do a read behind the scenes if the buffer is empty, so it blocks until you type something. Well... that's what I meant by break horribly. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] fast integer base-2 log function?
On Thu, Feb 14, 2008 at 08:23:29PM -0800, Uwe Hollerbach wrote: Stefan's routine is, as expected, much much faster still: I tested the first two routines on numbers with 5 million or so bits and they took ~20 seconds of CPU time, whereas I tested Stefan's routine with numbers with 50 million bits, and it took ~11 seconds of CPU time. The limitation of Stefan's routine is of course that it's limited to base 2 -- it is truly a bit-length routine -- and I guess another potential limitation is that it uses GHC extensions, not pure Haskell (at least I had to compile it with -fglasgow-exts). But it's the speed king if those limitations aren't a problem! At the risk of stating the obvious, it also hard-codes 32 bit words and certain configurable (but nobody bothers) details of the GMP data representation (big endian, 0 nails). Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A question about monad laws
On Mon, Feb 11, 2008 at 01:59:09PM +, Neil Mitchell wrote: Hi (x = f) = g == x = (\v - f v = g) Or stated another way: (x = f) = g == x = (f = g) Which is totally wrong, woops. See this page for lots of details about the Monad Laws and quite a nice explanation of where you use them: http://www.haskell.org/haskellwiki/Monad_Laws My favorite presentation of the monad laws is associativity of Kliesli composition: (a1 = a2) x = a1 x = a2 -- predefined in 6.8 control.monad -- The laws return = a= a a = return= a a = (b = c) = (a = b) = c Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proper exception handling
On Sun, Feb 10, 2008 at 02:49:39PM -0500, Thomas DuBuisson wrote: Cafe, Fact 1: ghc{,i} does not crash when executing this code. Fact 2: I do not want this to crash. Question: Is there some theoretical window between the 'catchDyn' exception handling and the recursive call to 'catchThatDamnError' that could result in an unhandled exception? (of type 'DynError', of coarse) I suppose I am looking for an answer to this question from a language standpoint as well as a compiler pov. As an aside: I see at least one way to be certain of the safty by wrapping the call to forkIO in 'catchDyn', reforking if an exception is caught, and passing the new ThreadId to throwConstantly via shared mutable state - I'd like to avoid all this if my current example is safe. Thomas Asynchronous exceptions are blocked in handlers, so there is no window - infact all exceptions after the first won't be delivered at all. However, you could be unlucky enough to throw the first error before the first catchDyn, so more synchronisation might be needed. Stefan import Control.Exception (catchDyn, throwDynTo) import Control.Concurrent (forkIO, threadDelay) import Control.Monad (forever) import Data.Dynamic main = do tid - forkIO catchThatDamnError forever $ throwConstantly tid catchThatDamnError = catchDyn start (\DynError - catchThatDamnError) start = do threadDelay 5000 start throwConstantly tid = do throwDynTo tid DynError data DynError = DynError deriving (Eq, Ord, Show, Typeable) signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Slightly Offtopic in Part
On Fri, Feb 08, 2008 at 06:47:51PM -0800, Ryan Ingram wrote: I'm assuming you mean the rule described in http://en.wikibooks.org/wiki/Formal_Logic/Sentential_Logic/Inference_Rules type Disj a b = Either a b disj_elim :: Disj a b - (a - c) - (b - c) - c disj_elim (Left a) a2c b2c = a2c a disj_elim (Right b) a2c b2c = b2c b If you know either a is true, or b is true and you know from a, I can prove c, and you know from b, I can prove c, then you can prove c. aka: import Data.Either type Disj = Either disj_elim = either Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mutable arrays
On Wed, Feb 06, 2008 at 08:57:43PM +, Andrew Butterfield wrote: In Clean, we not only have explicit access to the world, but we can partition it. Simplifying somewhat, we could open up pairs of file-handle (f1.in,f1.out), (f2.in,f2,out) ... (fn.in,fn.out), which does have to be done sequentially, since each file opening modifies the (global) filesystem. However, once this is done, we could, in principle, execute the fn in any order, and indeed in such a way that the implementation could choose to do them in parallel - this potential for (admittedly limited) deterministic parallel execution of I/O actions is possible with uniqueness types, but not epxressible in the monadic world as currently formulated. What if f1.out is a symlink to f2.out? I don't think Clean satisfies the evaluation order independance that is so treasured here. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mutable arrays
On Tue, Feb 05, 2008 at 06:00:38PM -0600, John Lato wrote: -- let ary_max = foldl1' max $ elems $ unsafeFreeze myArray If you use a boxed array type (IOArray or STArray) for myArray, and compiled with GHC, no copying is necessary (you may need to use type annotations to guarantee this). Then use the foldl' function to get array_max, and map it onto the original mutable array. I think it would be safe provided that you calculate ary_max before you start to modify the array, which is true for normalization. Eek! unsafeFreeze isn't a type cast, it actually modifies flags in the heap object which are used by the generational garbage collector. It's quite concievable that you could get segfaults by modifying a boxed array after passing it to unsafeFreeze. This, I believe, would work: let ary_max = foldl1' max [ inlinePerformIO (readArray myArray ix) | ix - range (inlinePerformIO (getBounds myArray)) ] But it's equally untested. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell maximum stack depth
On Mon, Feb 04, 2008 at 10:13:12PM +, Adrian Hey wrote: Also remember that this behaviour never wastes more than 50% of the stack, which is a relatively small amount. Only if the stack is relatively small. Would you say the same about heap, or about a stack that only needed 50% of heap space but ended up using all of it? Or money? Using twice as much as you need of anything is bad IMO. Apparently you don't realize that GHC normally uses twice as much heap as is needed, due to the decision to use a two-space copying collector by default for the oldest generation. :) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: GHC lazy eval optimization bug
On Sun, Feb 03, 2008 at 02:37:42PM -0500, Adam P Jenkins wrote: The haskell program below demonstrates an optimization bug with the GHC compiler. I have tried this with ghc 6.8.1 on my MacBook Pro and on a Linux i686 machine. This email should build as a literate haskell program. Build the program as While this may be unfortunate, it is a consequence of document behavior; thus I would not consider it a bug per-se. Try with -fno-state-hack; the documentation for this option, I believe, should explain what is going on. (Hint: IO a ~ State# - (State#, a)) Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] Mutable arrays
On Sat, Feb 02, 2008 at 12:57:47PM +, Rodrigo Queiro wrote: This is my attempt at some nicer code: maximum' (x:xs) = foldl' max x xs maximum' _ = undefined modifyArray :: (MArray a e m, Ix i) = (e - e) - a i e - m () modifyArray fn arr = do bounds - getBounds arr forM_ (range bounds) (modifyElement fn arr) modifyElement :: (MArray a e m, Ix i) = (e - e) - a i e - i - m () modifyElement fn arr i = do x - readArray arr i writeArray arr i (fn x) normalizeArray :: (MArray a e m, Ix i, Fractional e, Ord e) = a i e - m () normalizeArray arr = do arr_elems - getElems arr let max_elem = maximum' arr_elems modifyArray (/max_elem) arr Note that by using getElems, you are throwing away most of the advantages of arrays, since it is strict (it has to be, since it's effectively an IO function and lazy IO is unsound wrt Haskell's normal semantics) and converts the whole thing into a list. If I just had this one bit of code to do, I'd use explicit loop: normalizeArray arr = do b - getBounds arr ; m - findMax b forM_ (range b) (edit m) where findMax (i:is)= findMax' is = readArray arr i findMax' (i:is) !v = findMax' is . max v = readArray arr i findMax' [] !v = return v edit mx i = writeArray arr i . (/mx) = readArray arr i With a little more, I'd probably set the scene with a few array-modifying combinators, inspired by Oleg's left-fold idea: -- yes, I'm passing four arguments to foldr. this is not a mistake. foldA fn ac arr = getBounds arr = \b - foldr (\ i ct acc - ct = fn i ac = readArray arr i) (\_ - return ac) (range b) ac foldAp fn = foldA (\i a b - return (fn a b)) maxA = foldAp max minBound mapA fn ar = foldA (\i _ v - writeArray ar i (fn v)) () ar normalize arr = maxA arr = \ m - mapA (/m) arr Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] derive Pretty?
On Thu, Jan 31, 2008 at 03:00:15PM -0800, Greg Fitzgerald wrote: Is it possible to automatically derive instances of Prettyhttp://haskell.org/ghc/docs/latest/html/libraries/haskell-src/Language-Haskell-Pretty.html? If no, what do most do when it comes to pretty-printing large data types? It should be pretty trivial to do with my and ndm's Data.Derive library. I'm not sure anymore if it has a prettyprinter; I remember doing the groundwork and finding it fairly easy. I *think* I got distracted trying to write a fast prettyprinter. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell maximum stack depth
On Tue, Jan 29, 2008 at 07:38:24PM +, Neil Mitchell wrote: A lot also depends on compiler (and associated rts), such as whether or not it translates to CPS, thereby in effect building a stack (in all but name) on the heap. If you burn a lot of heap, for not much gain, that's still a bug, albeit one which large limits might be able to paper over for a short amount of time. Is the GHC stack not stored on the heap? I thought it was. I know the Hugs stack is stored on the stack, and the Yhc one isn't. GHC's stacks are stored in the heap, but as large continuous objects. GHC does not use the linked lists typical of CPS implementations, and (as of the Great RTS Cleanout of 4.00) does not even have a chunked stack. (In case it proves relevant the stack is not pinned - GHC's GC has special code to fix up relocated stacks) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell maximum stack depth
On Tue, Jan 29, 2008 at 09:28:56AM +, Neil Mitchell wrote: Hi Adrian, The bug is in ghc stack management. Why is it so important that the stack size is arbitrarily limited? It's not, but it makes some things easier and faster. A better question is why is it important for the stack to grow dynamically. The answer is that its not. No, it is. A single thread running a recursion-intensive program can use many 10's of K's of stack; and 10's of K's per thread is not cheap threads. GHC has had a dynamically growing stack for many years, starting at 4k and redoubling when exhaused; the stack size limit is a bug checker and nothing else. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Irrefutable pattern love and new regex engine.
On Tue, Jan 22, 2008 at 02:09:05PM -0800, Ryan Ingram wrote: On Tue, 2008-01-22 at 11:55 -0500, Michael Speer wrote: rexn ns pps = let ( ~( xs , rps ) , ~( ~( nxs ) , ~( rxs , rrps ) ) ) = ( exn nxs pps , Not one of the lazy marks was required in the current version. Pattern bindings via let are always irrefutable; the ~s here are all redundant. False; let's irrefutability only applies at the topmost level. Prelude let (a,b) = undefined in 2 2 Prelude let (a,(b,c)) = (2,undefined) in a *** Exception: Prelude.undefined Prelude let (a,~(b,c)) = (2,undefined) in a 2 Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell] Should the following program be accepted by ghc?
On Wed, Jan 16, 2008 at 01:02:43PM +0800, Martin Sulzmann wrote: Bruno Oliveira writes: I have been playing with ghc6.8.1 and type families and the following program is accepted without any type-checking error: data a :=: b where Eq :: a :=: a ... Ofcourse, that before ghc6.8, we add no type-level functions so maybe it was ok to consider the program above. ... type family K a Type families are unsupported, and their intersection with GADTs are unimplemented. Don't expect any program which uses both to do anything sane until 6.10. Stefan signature.asc Description: Digital signature ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell-cafe] where is the FFI glue code for STM?
On Fri, Jan 11, 2008 at 06:15:52PM -0600, Galchin Vasili wrote: Hello, I see where the top level code (written in Haskell)for STM. I have found STM.c;however, I can't seem to find the FFI glue code.? Thanks, Vasili There isn't any. readTVar# etc are primops. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell?
On Tue, Jan 08, 2008 at 09:10:59PM +0100, Achim Schneider wrote: Don Stewart [EMAIL PROTECTED] wrote: jules: Achim Schneider wrote: things like data State = State { winSize :: IORef Size , t :: IORef Int , fps :: IORef Float , showFPS :: IORef Bool , showHelp :: IORef Bool , grabMouse :: IORef Bool , mousePos :: IORef (Maybe Position) , mouseDelta :: IORef Position , viewRot :: IORef Vec3 , angle':: IORef GLfloat , ballPos :: IORef Vec2 , ballVel :: IORef Vec2 } Yuck! I'm not sure whether this is a real example or not, but if it's real, get rid of all those IORefs. Make State a simple type, and use (IORef State) as needed for callbacks, and hide that fact in other code. I agree, this is very-unHaskelly :) The State type should be a simple purely functional structured, threaded through your code via a StateT or some such. Not a bunch of pointers in IO. See xmonad for examples of this in highly effectful programs, http://code.haskell.org/xmonad/XMonad/Core.hs newtype X a = X (ReaderT XConf (StateT XState IO) a) (Carries read-only and updatable state components) Yes, you see, that was my first Haskell program bigger than 20 lines, there's no possibility to get the state out of the IO Monad, at least without writing a high-level interface to glut and gl, and then there's this thing that _every_ game works with input callbacks, one, global, state update function (where it doesn't _really_ matter whether you're passing and returning a state or updating a state) and one function that translates the state into some graphics representation. That said, I think it's not very Haskell-like to do something elegantly in 1000 lines when you can do it in 100 lines and still have it look nicer than C. I would use IORef State. Making illegal states unrepresentable greatly helps with code prettiness; the original State allowed internal aliasing, which is quite definitely silly. I think this should be written somewhere as a general rule - when you have a mutable structure, use a reference to a record, not a record of references. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Displaying # of reductions after each computation in ghci?
On Tue, Jan 08, 2008 at 09:48:37PM +, Fernando Rodriguez wrote: Is there a way to configure ghci to display the number of reuctions after each compution (as in winhugs)? No. (rambling explanation snipped awaiting further request) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: there isn't any difference, is there, with unboxed tuples?
On Fri, Jan 04, 2008 at 09:36:33PM -0500, Isaac Dupree wrote: -- unboxed types in function results are automatically lifted... or what was the term meaning they could be _|_, failing to terminate, (because of the function-ness)? -- unboxed tuples are specially restricted to be only allowed, among useful places, in function results. Therefore (... - ( a, b, c ) ) and (... - (# a, b, c #)) are identical, assuming both are kind-correct (identical in terms of optimization and semantics, not type equality, of course). Is that right? If so, there's never an excuse to use unboxed tuples except to contain unboxed values (because then you don't have the choice of using boxed tuples, which can only contain boxed values of kind *). Semantically, you are absolutely correct. However, there is a very subtle difference in sharing. Consider these two functions: foo (a,b) = (a,b) bar tuple = tuple These two functions are denotationally identical, but at runtime one performs more allocations. If we use unboxed tuples, then the caller must always allocate if a tuple is needed; thus effectively we always get the allocation behavior of foo. That is, return unboxing is not always an optimization! However, it *is* always safe if the tuple is constructed in the function itself, for then it could not possibly be shared with anything. Having explicit unboxed tuples in the language allows this complexity to be moved out of the code generator, which is a Good Thing. (Incidentally, this is what the CPR analysis is all about - identifying places where a Constructed Product is Returned.) Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: whole program optimization
On Thu, Dec 27, 2007 at 01:47:44PM +0100, Wolfgang Jeltsch wrote: Am Sonntag, 23. Dezember 2007 13:35 schrieb Isaac Dupree: GHC optimizes less effectively when parts of a program are in different modules, or are exported from a module. By the way, does GHC do cross-package optimization (not just cross-module optimization within packages)? Yes. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] Trouble with types
On Tue, Dec 25, 2007 at 08:11:34AM +0300, Konstantin Vladimirov wrote: [haskell] module TypeTrouble where class FirstClass a where firstFunction :: (SecondClass b) = a - b class SecondClass a where secondFunction :: a - Double [/haskell] I need, the firstFunction of FirstClass types to return a value of a SecondClass type. For example SecondData for FirstData, but for some FirstClass ThirdData, some SecondClass FourthData, etc. The problem, as is often the case, is that that which is unwritten does not resolve in the way you expect and require it to. FirstClass' true signature is class FirstClass a where firstFunction :: a - forall b. SecondClass b = b That is to say, any implementation of firstFunction must work for ANY instance of SecondClass. But you want SOME, not ANY. And SOME (normally notated exists tvar. tspec) is not supported in any known dialect of Haskell. It's possible to get fairly close with GHC Haskell's fundeps / type families: -- fundep version class SecondClass b = FirstClass a b where firstFunction :: a - b -- type family version class SecondClass (Cod a) = FirstClass a where type Cod a :: * firstFunction :: a - Cod a It is almost certainly possible to accomplish your goals within standard Haskell, but the best approach is not obvious at the current level of detail. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: whole program optimization
On Sun, Dec 23, 2007 at 07:35:20AM -0500, Isaac Dupree wrote: GHC optimizes less effectively when parts of a program are in different modules, or are exported from a module. Therefore, merging all the code into one module Main (main) would help. Unfortunately, Haskell source syntax is ill-suited to this; for example: ... So it's more complicated than it seems on the surface, but it could be done; I only wonder how effective it would be on various programs. I assume GHC doesn't currently implement any optimizations that can _only_ be whole-program, so it would still not be quite like Jhc, though this basic support might allow some such optimizations to be implemented. It's been done. http://www.cs.utah.edu/~hal/HAllInOne/index.html Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] Importing Data.Char speeds up ghc around 70%
On Sat, Dec 22, 2007 at 06:00:29PM +, Joost Behrends wrote: Hi, while still working on optimizing (naively programmed) primefactors i watched a very strange behavior of ghc. The last version below takes 2.34 minutes on my system for computing 2^61+1 = 3*768614,336404,564651. Importing Data.Char without anywhere using it reduces this time to 1.34 minute - a remarkable speed up. System is WindowsXP on 2.2GHZ Intel, 512MB Ram. I give the complete code here - hopefully all tabs are (4) blanks. Can this be reproduced ? I compile just with --make -O2. If you can reproduce it on your machine (rm executable *.o *.hi between tests for maximum reliability), it's definitely a bug. http://hackage.haskell.org/trac/ghc/wiki/ReportABug Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is a type synonym declaration really a synonym ?
On Sat, Dec 22, 2007 at 10:22:46PM +0100, alpheccar wrote: Can someone confirm me that: type TA = A :+: B type TB = C :+: D type T = TA :+: TB is not equivalent to type T = A :+: B :+: C :+: D where I have defined infixr 6 :+: data (f :+: g) data A data B data C data D I have a computation at type level which is working with the later definition of T but not with the former (ghc 6.8.1) Type synonyms are implicitly parenthetized, and your :+: is non-associative. Compare: s +:+ t = concat[(,s,,,t,)] foo = a +:+ b bar = c +:+ d baz = (foo +:+ bar) == (a +:+ b +:+ c +:+ d) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Importing Data.Char speeds up ghc around 70%
On Sat, Dec 22, 2007 at 04:40:00PM -0500, Sterling Clover wrote: I'm curious if you get the same performance difference importing GHC.Listinstead of Data.Char? I chased some dependencies, and Data.Char imports GHC.Arr, which in turn imports GHC.List, which provides a bunch of fusion rules pragmas that would probably optimize your (++) usage. If this is the case, not sure if its a bug or not, but all this will have to be thought through as more stream fusion is rolled out anyway, I suspect? --S The Prelude imports GHC.List, iirc. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does this blow the stack?
On Fri, Dec 21, 2007 at 03:16:17PM -0800, David Benbennick wrote: On Dec 21, 2007 2:30 PM, Don Stewart [EMAIL PROTECTED] wrote: dbenbenn: Thanks for fixing this. But doesn't GHC have strictness analysis? Sure does! The problem here was an explicit recusive loop though, with just not enough for the strictness analyser to get going. The explicit loop you're talking about is: enumDeltaInteger :: Integer - Integer - [Integer] enumDeltaInteger x d = x : enumDeltaInteger (x+d) d That code isn't very complicated, and I would hope to be able to write code like that in my own programs without having to worry about strictness. Given that the compiler even has an explicit signature, why can't it transform that code to enumDeltaInteger x d = let s = x + d in x : (seq s $ enumDeltaInteger s d) since it knows that (Integer+Integer) is strict? Of course, improving the strictness analysis is harder, but it pays off more, too. Because they simply aren't the same. Try applying your functions to undefined undefined. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Smart Constructor Puzzle
On Thu, Dec 20, 2007 at 11:39:42PM -0500, Ronald Guida wrote: data PZero = PZero deriving (Show) data PSucc a = PSucc a deriving (Show) type P1 = PSucc PZero type P2 = PSucc P1 type P3 = PSucc P2 -- etc ... Now here's the puzzle. I want to create a function vecLength that accepts a vector and returns its length. The catch is that I want to calculate the length based on the /type/ of the vector, without looking at the number of elements in the list. So I started by defining a class that allows me to convert a Peano number to an integer. I couldn't figure out how to define a function that converts the type directly to an integer, so I am using a two-step process. Given a Peano type /t/, I would use the expression pToInt (pGetValue :: t). class Peano t where pGetValue :: t pToInt :: t - Int instance Peano PZero where pGetValue = PZero pToInt _ = 0 instance (Peano t) = Peano (PSucc t) where pGetValue = PSucc pGetValue pToInt (PSucc a) = 1 + pToInt a Finally, I tried to define vecLength, but I am getting an error. vecLength :: (Peano s) = Vec s t - Int vecLength _ = pToInt (pGetValue :: s) 1. pGetValue is unneccessary, undefined :: s will work just as well. This is a fairly standard approach; the precision values in Floating, bitSize :: Bits a = a - Int, and sizeOf :: Storable a = a - Int all work this way. Some Haskeller, notably Alex Jacobson, prefer to use a 'proxy' type to make this value irrelevance explicit: data Proxy s -- for H98, data Proxy s = Proxy_ !(Proxy s) 2. The reason this doesn't work is that the scope of s in the type signature is the type signature, and the scope of s in the other type signature is the other type signature. They are very different type variables, and you cannot assign the type forall s. s to pGetValue - it has class constraints. The effect you are trying to achieve cannot be directly achieved in H98 (this is considered one of H98's few major flaws)... 2a: Use GHC extentions (ScopedTypeVariables). This extends the scope of type variables to include the definition. For backwards compatibility, it only applies to new-style explicit quantification: vecLength :: forall s. Peano s = Vec s t - Int 2b: Use functions with type constraints to force relations between types: vecLength v = pToInt (vToPeano v) where vToPeano = undefined :: Vec s t - s Figuring out why this works should be enlightening, and it seems hard to explain, so I'm leaving it as an excersize. :) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: ForeignPtr performance
On Mon, Dec 17, 2007 at 02:12:31PM +0300, Bulat Ziganshin wrote: Hello Simon, Monday, December 17, 2007, 1:33:19 PM, you wrote: My question is: what exactly does GHC.Prim.touch# do? This appears to it's a no-op (for ghc 6.6+ at least). its only task is to notify ghc optimizer that data were accessed so it doesn't free the memory Yes, exactly. touch# generates no code, but it is vitally important because if the ForeignPtr is referencing data in the heap (like mallocForeignPtrBytes does), it prevents the data from being GC'd before the operation completes. a bit more details for Scott: generated code is like this: ptr - unsafeForeignPtrToPtr fptr yourAction ptr touch# fptr without touch, the *last* action where fptr involved is its conversion to ptr. GHC Runtime (not optimizer as i said) have no idea that ptr and fptr is the same object, so after conversion it feels free to dispose object pointed by fptr if GC occurs. this means that during execution of your action data pointed by fptr/ptr may be suddenly freed, allocated by other object, bang! I'd like to elaborate that ptr, as far as the GC is concerned is *not a pointer at all*, it is an integer memory address. So it doesn't keep anything alive, you need to hold on to fptr if you want the value to exist. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: newtypes and optimization
On Wed, Dec 12, 2007 at 11:02:15AM -0700, Scott Dillard wrote: with strictness annotations and INLINEs for everything. I also tried automatic newtype deriving, with no luck. Why does a newtype defeat so much of the optimization? Thanks, Scott (Not a GHC developer, but someone fairly familiar with how the Simons work) What version of GHC are you using? The implementation of newtypes was completely redone in the 6.7.x period. Do you have a fairly small complete working example? If so, link to or attach a tarball - will make their jobs much easier. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] class default method proposal
On Tue, Dec 11, 2007 at 02:20:52PM +, Duncan Coutts wrote: I'd just like to float an idea that's related to the Class Alias proposal[1] but is perhaps somewhat simpler. We all know that Functor should have been a superclass of Monad, and indeed we now know that Applicative should be too. Making such a change would break lots of things however so the change does not happen. However in this case the Monad operations can be used to implement the Functor and Applicative class methods. So it would be nice if we could get them for free if the author did not choose to write the Functor and Applicative instances. So my suggestion is that we let classes declare default implementations of methods from super-classes. class Functor m = Monad m where {- the ordinary bits -} fmap f m= m = return . f So if there already is a Functor instance for m then the default implementation of fmap is not used. Does this proposal have any unintended consequences? I'm not sure. Please discuss :-) Duncan [1] http://repetae.net/recent/out/classalias.html This is almost exactly the http://haskell.org/haskellwiki/Class_system_extension_proposal; that page has some discussion of implementation issues. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] class default method proposal
On Tue, Dec 11, 2007 at 02:20:52PM +, Duncan Coutts wrote: I'd just like to float an idea that's related to the Class Alias proposal[1] but is perhaps somewhat simpler. We all know that Functor should have been a superclass of Monad, and indeed we now know that Applicative should be too. Making such a change would break lots of things however so the change does not happen. However in this case the Monad operations can be used to implement the Functor and Applicative class methods. So it would be nice if we could get them for free if the author did not choose to write the Functor and Applicative instances. So my suggestion is that we let classes declare default implementations of methods from super-classes. class Functor m = Monad m where {- the ordinary bits -} fmap f m= m = return . f So if there already is a Functor instance for m then the default implementation of fmap is not used. Does this proposal have any unintended consequences? I'm not sure. Please discuss :-) Duncan [1] http://repetae.net/recent/out/classalias.html This is almost exactly the http://haskell.org/haskellwiki/Class_system_extension_proposal; that page has some discussion of implementation issues. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ST Monad - what's wrong?
On Sun, Dec 09, 2007 at 12:11:42PM +0100, Nicu Ionita wrote: Hi, I'm trying to use the ST monad in order to turn an almost pure function into a pure one: reading a precalculated list of primes into a prime set. But the following code brings an error: primes :: Set Integer primes = runST $ getPrimes primes10h7.txt getPrimes :: String - (forall s. ST s (Set Integer)) getPrimes file = do cont - unsafeIOToST (readFile file) let set = fromList $ map read $ lines cont return set And here is the error: Couldn't match expected type `forall s. ST s a' against inferred type `ST s (Set Integer)' In the second argument of `($)', namely `getPrimes primes10h7.txt' In the expression: runST $ (getPrimes primes10h7.txt) In the definition of `primes': primes = runST $ (getPrimes primes10h7.txt) ST is far too big a hammer to use here. It gives you safety you're not using, at the cost of much more complicated typechecking. I'd just use unsafePerformIO. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problem with Gtk2hs
On Sat, Dec 08, 2007 at 08:33:36PM +, Andrew Coppin wrote: I just spent the evening writing a library that's a thin layer over Gtk2hs. It took an age to get it to compile, but eventually it worked. Yay! When I ran it, I got this: Test2: gtk/Graphics/UI/Gtk/Gdk/PixbufData.hs.pp:58:0: No instance nor default method for class operation Data.Array.Base.getNumElements Er... wow. OK, at this point, I am completely stumped. Any hints? That's pretty obviously a bug - Graphics.UI.Gtk.Gdk.PixbufData doesn't fully implement the (M)Array class. (Also, the documentation for Graphics.UI.Gtk.Misc.DrawingArea suggests that you may want to draw a Pixbuf using the pixbufRenderToDrawable function - but GHC complains that this function doesn't exist. I had to use drawPixbuf instead. Wow that has a lot of parameters... In particular, the final two don't seem to be documented. Interesting. They're both 0 in the fastdraw demo.) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Graph theory analysis of Haskell code
On Fri, Dec 07, 2007 at 10:16:43AM +1000, Ivan Miljenovic wrote: On 07/12/2007, Tommy McGuire [EMAIL PROTECTED] wrote: I was actually thinking that something like that would be more valuable for a language like C, where types are not represented in the control flow. By the way, in a completely different context I just ran across a couple of references: Concrete Architecture of the Linux Kernel. Ivan T. Bowman, Saheem Siddiqi, and Meyer C. Tanuan. Conceptual Architecture of the Linux Kernel, Ivan T. Bowman. (The first is available on CiteSeer; I haven't found the second.) OK, thanks. prof and gprof? That looks like them. Of course, us Haskellers have no need of such things, since our programs have profiling inbuilt into the RTS (at least when using GHC, anyway)! prof derives most of its utility from special hooks baked into gcc and libc. So gcc/prof is not really that different from ghc/hp2ps. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghc overlapping instances
On Tue, Dec 04, 2007 at 03:36:20PM +0100, Steffen Mazanek wrote: Hello, I want to quickcheck a property on a datatype representing programs (=[Stmt]) and need to define a specific instance instance Arbitrary [Stmt] (mainly to restrict the size of the list). In quickcheck an instance Arbitrary of lists is already defined. Which parameters do I have to give ghc such that it accepts such an instance? In hugs -98 +o is enough. I have tried -XOverlappingInstances, -XFlexibleInstances and also -XIncoherentInstances, however I still got an overlapping instances error for this declaration. You shouldn't use lists if you need to have special instance behavior - lists are for perfectly ordinary sequences of things. If a program is just a bunch of unrelated statements, then use [], otherwise use a custom (new)type. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] isSpace
On Tue, Dec 04, 2007 at 05:13:19PM +, Ryan Bloor wrote: hi I am having trouble with a function that is supposed to eliminate spaces from the start of a String and return the resulting string. I reckon a dropWhile could be used but the isSpace bit is causing me problems... words :: String - String words a = case dropWhile isSpace a of - s:ss - (s:word) : words rest where (word,rest) = break isSpace ss You might want to write the code for the first case; an expression is mandatory after -. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is this strict in its arguments?
On Tue, Dec 04, 2007 at 09:41:36PM +, Paulo J. Matos wrote: Hello all, As you might have possibly read in some previous blog posts: http://users.ecs.soton.ac.uk/pocm06r/fpsig/?p=10 http://users.ecs.soton.ac.uk/pocm06r/fpsig/?p=11 we (the FPSIG group) defined: data BTree a = Leaf a | Branch (BTree a) a (BTree a) and a function that returns a list of all the paths (which are lists of node values) where each path element makes the predicate true. findAllPath :: (a - Bool) - (BTree a) - Maybe [[a]] findAllPath pred (Leaf l) | pred l = Just [[l]] | otherwise = Nothing findAllPath pred (Branch lf r rt) | pred r = let lfpaths = findAllPath pred lf rtpaths = findAllPath pred rt in if isNothing lfpaths isNothing rtpaths then Nothing else if isNothing lfpaths then Just (map (r:) $ fromJust rtpaths) else if isNothing rtpaths then Just (map (r:) $ fromJust lfpaths) else Just (map (r:) $ fromJust rtpaths ++ fromJust lfpaths) | otherwise = Nothing Later on we noticed that this could be simply written as: findAllPath :: (a - Bool) - (BTree a) - [[a]] findAllPath pred = g where g (Leaf l) | pred l = [[l]] g (Branch lf r rt) | pred r = map (r:) $ (findAllPath pred lf) ++ (findAllPath pred rt) g _ = [] without even using maybe. However, 2 questions remained: 1 - why is the first version strict in its arguments? Because of the definition of strictness. A function is strict iff f undefined = undefined. findAllPath pred undefined - undefined because of the case analysis findAllPath undefined (Leaf _) - undefined because pred is applied in the guard findAllPath undefined Branch{} - undefined because pred is applied in the guard 2 - if it really is strict in its arguments, is there any automated way to know when a function is strict in its arguments? No, because this is in general equivalent to the halting problem: f _ = head [ i | i - [1,3.], i == sum [ k | k - [1..i-1], i `mod` k == 0 ] ] f is strict iff there do not exist odd perfect numbers. However, fairly good conservative approximations exist, for instance in the GHC optimizer - compile your code with -ddump-simpl to see (among other things) a dump of the strictness properties determined. (use -O, of course) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is this strict in its arguments?
On Tue, Dec 04, 2007 at 03:07:01PM -0800, Ryan Ingram wrote: Is there a reason why strictness is defined as f _|_ = _|_ instead of, for example, forall x :: Exception. f (throw x) = throw x where an exception thrown from pure code is observable in IO. In the second case we need to prove that the argument is evaluated at some point, which is also equivalent to the halting problem but more captures the notion of f evaluates its argument rather than either f evaluates its argument, or f _ is _|_ I suppose the first case allows us to do more eager evaluation; but are there a lot of cases where that matters? Is there a reason why 2 + 2 is defined as 4 instead of, for example, 5? Strictness is more useful in practice, simpler to define, and easier to approximate. What benefit does your notion offer? Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is this strict in its arguments?
On Tue, Dec 04, 2007 at 03:35:28PM -0800, Ryan Ingram wrote: On 12/4/07, Stefan O'Rear [EMAIL PROTECTED] wrote: Is there a reason why 2 + 2 is defined as 4 instead of, for example, 5? Wow. That wasn't really necessary. 4 has a clear meaning (the number after the number after the number after the number after zero) which is equivalent to 2 + 2. I'm not talking about naming issues; you could say that 5 was that number but then nobody would know what you are talking about. I am asking about the history motivation behind the original definition of strictness, not arguing for a redefinition. Oh. Sorry. Strictness is more useful in practice, simpler to define, and easier to approximate. Please elaborate; this is exactly why I asked. In particular, more useful in practice is the thing I am most curious about. When you see an expression of the form: f a you generally want to evaluate a before applying; but if a is _|_, this will only give the correct result if f a = _|_. Merely 'guaranteed to evaluate' misses out on some common cases, for instance ifac: ifac 0 a = a ifac n a = ifac (n - 1) (a * n) ifac is guaranteed to either evaluate a, or go into an infinite loop - so it can be found strict, and unboxed. Whereas 'ifac -1 (error moo)' is an infinite loop, so using a definition based on evaluation misses this case. What benefit does your notion offer? Well, one usually says something like f is strict in its 2nd argument which on casual reading tends to make me think that it has something to do with the argument. By the actual definition, however, f _ _ = undefined is strict in all of its arguments; but it's clear from the definition that the arguments are irrelevant. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is this strict in its arguments?
On Tue, Dec 04, 2007 at 07:43:36PM -0800, Ryan Ingram wrote: On 12/4/07, Stefan O'Rear [EMAIL PROTECTED] wrote: When you see an expression of the form: f a you generally want to evaluate a before applying; but if a is _|_, this will only give the correct result if f a = _|_. Merely 'guaranteed to evaluate' misses out on some common cases, for instance ifac: ifac 0 a = a ifac n a = ifac (n - 1) (a * n) ifac is guaranteed to either evaluate a, or go into an infinite loop - so it can be found strict, and unboxed. Whereas 'ifac -1 (error moo)' is an infinite loop, so using a definition based on evaluation misses this case. By this line: you generally want to evaluate a before applying; but if a is _|_, this will only give the correct result if f a = _|_ I assume you mean that it's generally more efficient to do things that way, because the calling function may have more information about a or how it is calculated, so you may be able to optimize better by doing eager evaluation whenever it is correct. Yes - if we know that a value is needed, eager evaluation is more efficient, because no time need be spent constructing and deconstructing expressions in memory. More significantly, strictness facilitates certain unboxing transformations. Since ifac is strict, (optimized) code will never call it with anything except a concrete number, so we can gainfully specialize it to the case of a pre-evaluated argument; so instead of passing pointer-to-Int-node, we can just pass a raw machine integer. With a few passes of standard compilation technology (inlining +, etc) we wind up with the moral equivalent of while (n--) { i *= n; }. Your ifac example makes perfect sense, thanks. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foild function for expressions
On Mon, Dec 03, 2007 at 09:27:45PM -0600, Derek Elkins wrote: On Mon, 2007-12-03 at 19:13 -0800, Stefan O'Rear wrote: On Mon, Dec 03, 2007 at 09:18:18AM -0800, Carlo Vivari wrote: Hi! I'm a begginer in haskell and I have a problem with an exercise, I expect someone could help me: In one hand I have a declaration of an algebra data, like this: data AlgExp a = AlgExp { litI :: Int - a, litB :: Bool - a, add :: a - a - a, and :: a - a - a, ifte :: a - a - a - a} (being ifte an 'ifthenelse' expresion...) What I want to do is to write a fold function for expressions, something like this: foldExp :: AlgExp a - Exp - a foldExp alg (LitI i) = litI alg i foldExp alg (LitB i) = litB alg i foldExp alg (add exp1 exp2) = ¿¿¿??? foldExp alg (and exp1 exp2) = ¿¿¿??? foldExp alg (ifte exp1 exp2 exp3) = ¿¿¿??? ..ETC the fact is that I have no idea of what to do with the other expresions (add, and, and ifte)... I really don' t understand how to do this... It's clear that a fold function should colapse in one valour, but how can I espress it in the terms of the exercise? For further information about the problem after this, it's suposed that I have to rewrite some functions for expresions but in terms of foldexp (the one I should write before) The problem is that AlgExp defines an arbitrary algebra, but in order to fold you need a universal algebra. So it makes the most sense to add foldExp to the reccord. This is an unusually poor post for you. Presuming you mean initial or free or term for universal then it does (presumably) have it with Exp. Assuming Exp is the expected thing (an AST) it is (combined with the constructors) the initial algebra. foldExp should quite definitely be the type it is and not be part of the record and the its implementation is so far correct (modulo syntactical errors that are potentially indicative of a deeper confusion). Oh right, I misread the foldExp sketch. I thought he was trying to go *from* a member of his algebra *to* Exp. Sorry. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foild function for expressions
On Mon, Dec 03, 2007 at 09:18:18AM -0800, Carlo Vivari wrote: Hi! I'm a begginer in haskell and I have a problem with an exercise, I expect someone could help me: In one hand I have a declaration of an algebra data, like this: data AlgExp a = AlgExp { litI :: Int - a, litB :: Bool - a, add :: a - a - a, and :: a - a - a, ifte :: a - a - a - a} (being ifte an 'ifthenelse' expresion...) What I want to do is to write a fold function for expressions, something like this: foldExp :: AlgExp a - Exp - a foldExp alg (LitI i) = litI alg i foldExp alg (LitB i) = litB alg i foldExp alg (add exp1 exp2) = ¿¿¿??? foldExp alg (and exp1 exp2) = ¿¿¿??? foldExp alg (ifte exp1 exp2 exp3) = ¿¿¿??? ..ETC the fact is that I have no idea of what to do with the other expresions (add, and, and ifte)... I really don' t understand how to do this... It's clear that a fold function should colapse in one valour, but how can I espress it in the terms of the exercise? For further information about the problem after this, it's suposed that I have to rewrite some functions for expresions but in terms of foldexp (the one I should write before) The problem is that AlgExp defines an arbitrary algebra, but in order to fold you need a universal algebra. So it makes the most sense to add foldExp to the reccord. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Advice for clean code.
On Mon, Dec 03, 2007 at 08:47:48PM -0600, David McBride wrote: I am still in the early stages learning haskell, which is my first foray into functional programming. Well there's no better way to learn than to write something, so I started writing a game. Mostly the thing looks good so far, far better than the C version did. However, my problem is that code like the following is showing up more often and it is becoming unwieldy. gameLoop :: World - IO () gameLoop w = do drawScreen w action - processInput let (result, w') = processAction action w case result of MoveOutOfBounds - putStrLn Sorry you can't move in that direction. MoveBadTerrain a - case a of Wall - putStrLn You walk into a wall. Tree - putStrLn There is a tree in the way. otherwise - putStrLn You can't move there. otherwise - return () let w'' = w' { window = updateWindowLocation (window w') (location $ player w')} unless (action == Quit) (gameLoop w'') Where world contains the entire game's state and so I end up with w's with multiple apostrophes at the end. But at the same time I can't really break these functions apart easily. This is error prone and seems pointless. I have been reading about control.monad.state and I have seen that I could run execstate over this and use modify but only if each function took a world and returned a world. That seems really limiting. I'm not even sure if this is what I should be looking at. I am probably just stuck in an imperative mindset, but I have no idea what to try to get rid of the mess and it is only going to get worse over time. Any suggestions on what I can do about it? I'd recommend using StateT World IO. You can always run other functions using 'lift'; for instance lift can be :: IO () - StateT World IO (). Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for smallest power of 2 = Integer
On Mon, Dec 03, 2007 at 11:40:14PM -0500, Brandon S. Allbery KF8NH wrote: On Dec 3, 2007, at 23:36 , Dan Piponi wrote: Is there anything in any of the interfaces to Integer that will allow me to quickly find the highest bit set in an Integer? If not, does Isn't Integer unlimited (well, limited by RAM)? Any *specific* integer has a finite number of 1-bits. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trees
On Mon, Dec 03, 2007 at 08:13:57AM +0100, Adrian Neumann wrote: Good morning, as an exercise for my Algorithms and Programming course I have to program a couple of simple functions over trees. Until now everything we did in Java could be done in Haskell (usually much nicer too) using the naive data Tree a = Leaf a | Node a [Tree a] But now the assignments require more than a simple top-down traversal. For example: given a tree t and two nodes u,v, find the first common ancestor. In Java this is really simple, because each node has a parent reference. That way I only need to follow those references until I find the first common ancestor. This should take something like O(log n) in the average case. In Haskell however the best way I've come up with so far is doing a BFS and looking for the last common node in the paths to u and v. This is neither fast, nor particularly elegant. So how would you smart guys do it? With a Zipper? It would be nice if there was an elegant solution without monads. It should be noted that this is a question of style, not language, and the Java solution translates to Haskell: data Tree a = Node { idn:: Int, val:: a, parent:: Maybe (Tree a), children:: [Tree a] } You can make this efficiently mutable, but only at the cost of making it ephemeral, a natural property of Java's data structures but frowned on in our culture. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Modelling a mutable variable store
On Sun, Dec 02, 2007 at 03:54:05AM +, Kannan Goundan wrote: On Sat, 01 Dec 2007 21:22:53 -0600, Derek Elkins wrote: Use ST. First-class state isn't too great unless you specifically want that. I did try using ST but ran into a problem because its type variable (s) ended up invading all of my types. That's just ST ugliness, the price you have to pay for a pure runST. If you're doing almost everything in ST, it can be cleaner just to use IORefs. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell interface file (.hi) format?
On Sun, Dec 02, 2007 at 05:45:48AM +0100, Tomasz Zielonka wrote: On Fri, Nov 30, 2007 at 08:55:51AM +, Neil Mitchell wrote: Hi Prelude :b Control.Concurrent.MVar module 'Control.Concurrent.MVar' is not interpreted :b now defaults to :breakpoint, you want :browse That's a questionable decision, IMO: - it changes behavior - I expect :browse to be used more often, so it deserves the sort :b version (:bro is not that short) On the other hand, this change can have an (unintended?) feature advertising effect ;-) It's not a decision at all. :b is the first command starting with b, which was browse yesterday, is breakpoint today, and tomorrow will be something you've never heard of. It's inherently fragile, and shouldn't be relied on in scripts - and if :b does anything funny, spell out the command! (There is a case to be made for explicitly defining short forms of commands - but that is not what :b is, and making this case should only be done in a new thread.) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A tale of Project Euler
On Thu, Nov 29, 2007 at 09:10:16PM +, Andrew Coppin wrote: Sebastian Sylvan wrote: On Nov 29, 2007 6:43 PM, Andrew Coppin [EMAIL PROTECTED] wrote: I don't understand the ST monad. There's not a whole lot to understand if you just want to use it (though it's all very cool from a theoretical standpoint too). From what I can tell, it's not definable without using strange language extensions. (I don't really like using things where it's unclear why it works.) You can't implement IO in H98 either. You just have to accept it as a given. (As far as ST goes, runST is unsafePerformIO renamed. The only tricky bit is proving safety.) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: New slogan for haskell.org
On Thu, Nov 29, 2007 at 09:48:22AM +0100, apfelmus wrote: Well, I only remember that it took _me_ a page of C code :D Basically due to a hand-coded intset and user interaction (no REPL for C, after all). In my C programming, I've taken to using gdb as a REPL: [EMAIL PROTECTED]:/tmp$ vi foo.c [EMAIL PROTECTED]:/tmp$ cat foo.c int foo(int x) { return x * x; } int main(){} [EMAIL PROTECTED]:/tmp$ gcc foo.c [EMAIL PROTECTED]:/tmp$ gdb -q ./a.out Using host libthread_db library /lib/i686/cmov/libthread_db.so.1. (gdb) b main Breakpoint 1 at 0x804835e (gdb) run Starting program: /tmp/a.out Failed to read a valid object file image from memory. Breakpoint 1, 0x0804835e in main () (gdb) p foo(2) $1 = 4 (gdb) p foo(10) $2 = 100 (gdb) p foo(-1) $3 = 1 (gdb) p foo(0) $4 = 0 (gdb) p foo(2)+foo(4) $5 = 20 (gdb) quit The program is running. Exit anyway? (y or n) y [EMAIL PROTECTED]:/tmp$ Makes most debugging tasks much easier. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: New slogan for haskell.org
On Thu, Nov 29, 2007 at 12:40:00PM +, Simon Marlow wrote: What I'd *really* like to see is a bunch of links on the front page leading to pages that describe the main differences between Haskell and some other language (C, Python, Java, C#, F#, ...). The easiest way to grasp what Haskell is all about is by reference to a known baseline, and programmers tend to have different baselines. e.g. the C page might start with Haskell is a functional language, whereas the Python page might start with Haskell is statically typed. I guess this is similar to Ian's suggestion. +1 Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: nhc vs ghc
On Sat, Nov 24, 2007 at 10:44:45AM +, Neil Mitchell wrote: Hi can anyone provide a concise list of the major differences between nhc98 and ghc? for example, can i build a cabal package with nhc98? i get that ghc and nhc98 are not interchangeable, otherwise i am not sure The other major differences: * nhc is unavailable on Windows * nhc programs run much slower * nhc has fewer users and fewer developers, meaning more bugs There are also a few advantages: * It was written on an Acorn A4000, an 80s-era PC with a whopping 3MB of memory; as such it is much more memory-friendly than GHC, which at the time wanted 16MB for normal use. * It's unrelated to GHC, which means that the set of bugs are uncorrelated. If you think GHC is doing something wrong, ask NHC for a second opinion. * It's much easier to port than GHC. (And an important disadvantage - The original author of NHC, Niklaus Röjemo, has disappeared off the face of the Internet, and the acting maintainer doesn't actually grok most of the code.) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Pretty-printing peg solitaire boards
On Sun, Nov 25, 2007 at 03:40:26AM -0200, Maurício wrote: Hi, I'm trying to pretty-print (with Text . PrettyPrint . HughesPJ) a set of peg solitaire boards. No matter what I try, I always get this: 00# 00# #00 000 000 000 000 : 00# 00# 000 000 000 000 000 but what I really want is this: 00# 00# 00# 00# #00 000 000 : 000 000 000 000 000 000 000 What I'm I doing wrong? When I have two boards a,b::Doc, I'm composing them with a + colon + b and rendering them with just 'render'. Should I try something else? Right; Text.PrettyPrint is designed for rendering code, where there is a natural 1D structure. For instance, stmt semi does the right thing for code - sticking the semicolon at the very end. For text graphics you want to do something else... Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: ghci changing 'm' to 'g'
On Wed, Nov 21, 2007 at 01:16:34PM -0500, Olivier Boudry wrote: On Nov 21, 2007 1:07 PM, Greg Fitzgerald [EMAIL PROTECTED] wrote: Running 6.8.1 on Windows XP, typing 'main' while :r is still processing causes the 'm' in 'main' to morph to a 'g'. :r [1 of 2] Compiling Language.QidlTypeLibrary.Parser ( Language/QidlTypeLibrary/Parser.hs, interpreted ) Ok, modules loaded: Main, Language.QidlTypeLibrary.Parser. main interactive:1:0: Not in scope: `gain' Thanks, Greg What a weird bug. It sounds like a joke but it isn't one. I just reproduced it (also works with :l). P:\5. Tools\Cleansing\CustomerMasterghci GHCi, version 6.8.1: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude :l CustomerMaster.hs [1 of 1] Compiling Main ( CustomerMaster.hs, interpreted ) Ok, modules loaded: Main. *Main main interactive:1:0: Not in scope: `gain' I wonder if it's a Windows only bug. It's very old. http://hackage.haskell.org/trac/ghc/ticket/831 Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: ghci changing 'm' to 'g'
On Thu, Nov 22, 2007 at 01:12:16AM +0200, Yitzchak Gale wrote: Greg Fitzgerald wrote: Running 6.8.1 on Windows XP, typing 'main' while :r is still processing causes the 'm' in 'main' to morph to a 'g'. Olivier Boudry wrote: it (also works with :l). Stefan O'Rear wrote: It's very old. http://hackage.haskell.org/trac/ghc/ticket/831 But these observations indicate several clues that do not yet appear in the Trac ticket: 1. Occurs on Windows (I can't reproduce it in on Mac OS X Intel or Debian Lenny) That *is* in the ticket - look at the Operating System field. 2. Occurs also with :r and :l, not just evaluating an expression. Personally I think that this is the least relatively suprising behavior, and it would be most noteworthy if it only affected expressions. But others may disagree. Perhaps someone with with a Trac login should make note of them. You have one! User 'guest', password 'guest'. In fact, it says this at the bottom of every page! (Spammers are smart enough to try and create accounts, but can't read page footers - go figure). Remember to sign your comment with contact info. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] Over-allocation
On Wed, Nov 21, 2007 at 01:31:35PM +, Gracjan Polak wrote: Hi, My program is eating too much memory: The source.txt is 800kb, and I expect files of size 100 times more, say 80MB, so using -H800M will not help here much. The profile -p says: COST CENTREMODULE %time %alloc xparse PdfModel 78.1 95.0 You're using the wrong type of profiling for this job. -p is intended for people who want their programs to go faster; and %alloc is raw allocations, showing how to divide the GC cost. Since you are allocating 100 times more data than is being retained, the %alloc figures are quite uncorrelated with leakiness. But you don't want to make your program faster - you want to make it leaner. You want one of the heap profiling flags, described in: http://haskell.org/ghc/dist/current/docs/users_guide/prof-heap.html Note that heap profiling is even more a black art than time profiling; you may need to do a lot of experimentation to find an enlightening profile. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Exposed module still hidden, why?
On Tue, Nov 20, 2007 at 12:18:57PM -0800, Greg Fitzgerald wrote: Using GHC 6.8.1 on Windows XP, after having used ghc-pkg to expose ' directory-1.0.0.0', I am getting an error when I build haddock that says the package is hidden. When I type ghc-pkg list, the package is not in parenthesis. Typing ghc -v says that it is using the file from C:\ghc\ghc-6.8.1\package.conf. That package.conf file has the 'exposed' set to True for that file. Why does GHC still think the package is hidden? ...\haddock-0.8runhaskell Setup.lhs configure Configuring haddock-0.8... ...\haddock-0.8runhaskell Setup.lhs build Preprocessing executables for haddock-0.8... shift/reduce conflicts: 5 Building haddock-0.8... src/Main.hs:49:7: Could not find module `System.Directory': it is a member of package directory-1.0.0.0, which is hidden ...\haddock-0.8ghc-pkg list C:/ghc/ghc-6.8.1\package.conf: Cabal-1.2.2.0, HUnit-1.2.0.0, OpenGL-2.2.1.1, QuickCheck-1.1.0.0, Win32-2.1.0.0, array-0.1.0.0, base-3.0.0.0, bytestring-0.9.0.1, cgi-3001.1.5.1, containers-0.1.0.0, directory-1.0.0.0, fgl-5.4.1.1, filepath-1.1.0.0, (ghc-6.8.1), haskell-src-1.0.1.1, haskell98-1.0.1.0, hpc-0.5.0.0, html-1.0.1.1, mtl-1.1.0.0, network-2.1.0.0, old-locale-1.0.0.0, old-time-1.0.0.0, packedstring-0.1.0.0, parallel-1.0.0.0, parsec-2.1.0.0, pretty-1.0.0.0, process-1.0.0.0, random-1.0.0.0, regex-base-0.72.0.1, regex-compat-0.71.0.1, regex-posix-0.72.0.1, rts-1.0, stm-2.1.1.0, template-haskell-2.2.0.0, time-1.1.2.0, xhtml-3000.0.2.1 This is a Cabal FAQ. Cabal passes -hide-all-packages to GHC to prevent undeclared dependancied from creeping in; so you have to explicitly depend on all used packages. (Would someone who is involved with the cabal web site PLEASE put this up somewhere? FAQs do no good if they have to be typed by humans!) Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] Tetris
On Tue, Nov 20, 2007 at 07:27:48PM +, Andrew Coppin wrote: (Nitpick: Don't you need Gtk2hs in order to *use* OpenGL? I mean, you have to open a window to render into somehow, and that's outside the OpenGL standard...) You need *something*, but it need not be Gtk. GLUT and GLX will also work, and at least the former has a Haskell binding. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] gtk2hs problem
On Tue, Nov 20, 2007 at 03:18:03PM -0800, Gregory Propf wrote: I've written a small program using the gtk2hs library and it crashes at unpredictable times with X windows errors like the one below. I looked for the messages online and found various people talking about buggy gtk libraries but no clear solutions. I don't know a lot about X windows or what these errors mean. Has anyone else had this problem or know what to do? The program is a simple implementation of the Conway Life game. It doesn't have very much going on except that the main window is an animation showing the evolution of the game. I tried running with the --sync option as it said and you get an almost immediate error like Xlib: unexpected async reply (sequence 0x1652)!. Even these are not predictable and often come after several screen updates. I'm using the Gtk.timeoutAddFull function to do the animation. Note that the error_code, request_code, etc.. changes with each crash. It's as though it picks a random error code each time. I've compiled with both ghc 6.4.2 and 6.6.1 and gtk2hs 0.9.12 and 0.9.12.1. I've tried various combinations of -O flags as well. Same problem every time. A typical crash message --- The program 'hlh' received an X Window System error. This probably reflects a bug in the program. The error was 'BadDrawable (invalid Pixmap or Window parameter)'. (Details: serial 236321 error_code 9 request_code 62 minor_code 0) (Note to programmers: normally, X errors are reported asynchronously; that is, you will receive the error a while after causing it. To debug your program, run it with the --sync command line option to change this behavior. You can then get a meaningful backtrace from your debugger if you break on the gdk_x_error() function.) What happens if you run 'gdb ./hlh', 'b gdk_x_error', 'run --sync' ? (Are the backtraces consistent?) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Translations and Haskell
On Mon, Nov 19, 2007 at 05:39:44PM -0800, Jeremy Shaw wrote: You might also allow: i18n (multine ++ string) provided that all the arguments of ++ are string literals. This is because, AFAIK, there is no other way to split a long string across multiple source lines in a portable way. multiline\ \string http://haskell.org/onlinereport/lexemes.html#sect2.6 Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Small optimisation question
On Sat, Nov 17, 2007 at 04:01:34PM +, Andrew Coppin wrote: Suppose I write something like this: foo :: [Int] foo = concat (replicate 4 [4,7,2,9]) The value of foo is completely determined at compile-time. So, will the compiler generate calls to concat and replicate, or will it just insert a large list constant here? Obviously, once somebody has completely examined the contents of foo, after that point it won't matter either way. I'm just curiose. Concatinating some strings is cheap; I sometimes write constructs like the above using much more expensive operations. (Expensive in time; the space taken up by the result isn't that great.) The compiler will generate calls to concat and replicate. Stefan, who is pretty sure he has a proposal for generalized folding pragmas Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Small optimisation question
On Sat, Nov 17, 2007 at 04:10:58PM +, Andrew Coppin wrote: Stefan O'Rear wrote: On Sat, Nov 17, 2007 at 04:01:34PM +, Andrew Coppin wrote: Suppose I write something like this: foo :: [Int] foo = concat (replicate 4 [4,7,2,9]) The value of foo is completely determined at compile-time. So, will the compiler generate calls to concat and replicate, or will it just insert a large list constant here? The compiler will generate calls to concat and replicate. OK. I presume this is due to the fact that the result of executing an expression at compile-time could be arbitrarily large? Yes, and it's not even guaranteed to terminate. Are there any buttons that can be twiddled to control this behaviour? Not that I'm aware of, though you can hack something with RULEs probably. For that matter, when I say [4,7,2,9], what does that compile into? Some data structures in memory? Or code to actually build said structures? Both. A curious feature of the STG machine is that constructor thunks and evaluated data are represented identically in memory. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Small optimisation question
On Sat, Nov 17, 2007 at 04:31:33PM +, Andrew Coppin wrote: Both. A curious feature of the STG machine is that constructor thunks and evaluated data are represented identically in memory. Ooo... As per the Lambdacats Boxed cat has a uniform representation? Well, presumably the guys who designed STG did it this way for a really good reason, and they know far more than me, so... ;-) The STG-machine was brilliant when it was designed, but times have changed. In particular, indirect jumps are no longer cheap. Pointer tagging has allowed STG to hobble into the 21st century, but really the air is ripe for a new abstract machine. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Small optimisation question
On Sat, Nov 17, 2007 at 12:39:14PM -0600, Jake McArthur wrote: On Nov 17, 2007, at 11:26 AM, Stefan O'Rear wrote: The STG-machine was brilliant when it was designed, but times have changed. In particular, indirect jumps are no longer cheap. Pointer tagging has allowed STG to hobble into the 21st century, but really the air is ripe for a new abstract machine. Do you know of any candidates? Hahaha - no. (Do ask John Meacham though - he keeps *saying* he has a new AM...) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [GHC] #1894: Add a total order on type constructors
On Fri, Nov 16, 2007 at 03:59:00PM +, Ian Lynagh wrote: On Thu, Nov 15, 2007 at 03:59:46PM -0800, Stefan O'Rear wrote: On Thu, Nov 15, 2007 at 11:52:31PM -, GHC wrote: * cc: sorear (added) * difficulty: = Unknown Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/1894#comment:2 Something is going crazy. I know there was one name in the CC before, That name is still there: trac is now cleverer and will report the minimal changes to the CC list rather than telling you the complete old and new lists, so it is telling you that it has added sorear to the list. and I know I didn't modify Difficulty. The guest account isn't allowed to set the difficulty. When you followed up difficulty was set to its default value. (it would be nicer if not allowed to set = set to default value, but sadly that's not how it works). Ah, it makes sense now. Thanks. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #1894: Add a total order on type constructors
On Thu, Nov 15, 2007 at 11:52:31PM -, GHC wrote: #1894: Add a total order on type constructors -+-- Reporter: guest| Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Type checker) |Version: 6.8.1 Severity: normal | Resolution: Keywords: | Difficulty: Unknown Testcase: | Architecture: Multiple Os: Multiple | -+-- Changes (by sorear): * cc: sorear (added) * difficulty: = Unknown Comment: I hate this proposal, but something like it is dearly needed, and I don't want to see yet another bikeshed war. Adding myself to the CC. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/1894#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler Something is going crazy. I know there was one name in the CC before, and I know I didn't modify Difficulty. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [Haskell-cafe] Using Data.Binary for compression
On Wed, Nov 14, 2007 at 10:03:52PM -0800, Chad Scherrer wrote: Hi, I'd like to be able to use Data.Binary (or similar) for compression. Say I have an abstract type Symbol, and for each value of Symbol I have a representation in terms of some number of bits. For compression to be efficient, commonly-used Symbols should have very short representations, while less common ones can be longer. ... (1) Am I reinventing the wheel? I haven't seen anything like this, but it would be nice to be a bit more certain. (2) This seems like it will work ok, but the feel is not as clean as the current Data.Binary interface. Is there something I'm missing that might make it easier to integrate this? (3) Right now this is just proof of concept, but eventually I'd like to do some performance tuning, and it would be nice to have a representation that's amenable to this. Any thoughts on speeding this up while keeping the interface reasonably clean would be much appreciated. Almost all 'real users' just use Codec.Compression.GZip. It's very fast, very compositional, and (perhaps suprisingly) almost as effective as application-specific schemes. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Performance help
On Tue, Nov 13, 2007 at 02:45:33PM -0800, Justin Bailey wrote: On Nov 13, 2007 2:21 PM, Ryan Ingram [EMAIL PROTECTED] wrote: Never mind, I realized this is a ring buffer with `mod` s. That's another slow operation when you're doing code as tight as this. If you can guarantee the ring is a power of 2 in size you can use a mask instead, or use my original suggestion of deriving rules from the previous rule and the new bit; the initial state is determined by the last bits in the buffer and you never wrap. I can't guarantee the ring is a power of 2 but do you feel like explaining the mask suggestion anyways? Thanks for the bits suggestion - I'll see if that helps performance at all. It looks like you have to be very careful in which concrete type you choose or you'll get a lot of conversion going on. About how wide are your rules usually? Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Extensible Records
On Sun, Nov 11, 2007 at 03:02:56PM +0300, Bulat Ziganshin wrote: Hello Barney, Sunday, November 11, 2007, 2:34:14 PM, you wrote: An important application which is made impossible by this approach is i propose to start Records project by composing list of requirements/applications to fulfill; we can keep it on Wiki page. this will create base for language theorists to investigate various solutions. i think they will be more motivated seeing our large interest in this extension +1 Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] Somewhat random history question - chicken and egg
On Sun, Nov 11, 2007 at 11:07:29AM +, Neil Mitchell wrote: Hi ...if GHC is written in Haskell, how the heck did they compile GHC in the first place? GHC was not the first Haskell compiler, hbc was the main compiler at some point, so I suspect they used hbc. There was also lazy ML which I suspect was used to bootstrap hbc - but I'm not sure of the details. Hbc didn't need to be bootstrapped because it isn't written in Haskell - it's written in Lazy ML. Lazy ML would need to be bootstrapped, but since it has (almost?) the same syntax as Standard ML, I suspect the first versions of lml were written in SML. (Can you clarify, L. Augustsson?) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Extensible Records
On Sat, Nov 10, 2007 at 06:35:34PM -0500, Seth Kurtzberg wrote: 6.10? I think that's a typo as the current version is 6.8.1. Or did I misunderstand what you were saying? 6.8.1 is released, there is abolutely no way new features are going to enter a published version. Hence, 6.10. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Extensible Records
On Sat, Nov 10, 2007 at 06:35:34PM -0500, Seth Kurtzberg wrote: Is there any chance of seeing extensible records in GHC 6.10? There seems to be widespread agreement that the current situation is unacceptable, but the official GHC policy is that there are too many good ideas to choose from - so nothing gets done! I hence humble propose that http://www.cs.uu.nl/~daan/download/papers/scopedlabels.pdf be adapted to GHC. In my naivete, I assume that porting an existing implementation would be much easier than starting from scratch. Is this reasonable? N.B. I am aware that GHC has limited resources - many thanks to Simon Simon and all other contributors either way. I second this request. Yes, I know you *could* do something in a library; but it's MUCH nicer as a built-in feature. Sadly. Stefan signature.asc Description: Digital signature ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] Trouble using unboxed arrays
On Sat, Nov 10, 2007 at 11:09:54AM -0800, Justin Bailey wrote: I would like to create a data structure that uses an unboxed array as one of its components. I would like the data structure to be parameterized over the type of the elements of the array. Further, I'd like to build the array using runSTUArray. I can't make the code work though. My naive approach: data Ring a = Ring (UArray Int a) and the code to make the array: makeArray :: [a] - Ring a makeArray ls = Ring (ST.runSTUArray (ST.newListArray (0, length ls - 1) ls)) But that doesn't work. I get from GHC (6.8.1): Could not deduce (MArray (STUArray s) a (ST s)) from the context () arising from a use of `newListArray' I am pretty sure I need to constrain 'a' to primitive types only, but how? Can I do it in the data definition? Thanks in advance for any help! What you're trying to do deliberately can't be done. Polymorphism has a runtime cost in GHC, and UArrays must specialize. That said, have you heard of Data.Array.IArray.listArray? Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] MD5?
On Fri, Nov 09, 2007 at 09:05:58PM +, Andrew Coppin wrote: The MD5SUM.EXE file I have chokes if you ask it to hash a file in another directory. It will hash from stdin, or from a file in the current directory, but point-blank refuses to hash anything else. So I'd have to write my Haskell code to open the file I want and *pipe* it to stdin on MD5SUM.EXE (making sure to not translate line ends or anything else that will alter the hash code). Then I have to parse the output and change it to actually match the UNIX md5sum program. [Because I want to make it compatible with that.] That also involves some fun with line ends... I'm drawing a blank on the windows API, but at least in DOS it was possible to redirect standard input from a file without involving your program. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Building Haskell stuff on Windows
On Fri, Nov 09, 2007 at 07:38:28PM +, Andrew Coppin wrote: ...there's a libraries list? (And a Cabal list??) http://haskell.org/mailman/listinfo/ Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell performance question
On Fri, Nov 09, 2007 at 01:39:55AM +0100, Thomas Schilling wrote: On Thu, 2007-11-08 at 16:24 -0800, Stefan O'Rear wrote: On Thu, Nov 08, 2007 at 07:57:23PM +0100, Thomas Schilling wrote: $ ghc --make -O2 ghc-bench.hs Even for GCC (/not/ G_H_C)? No, GCC implements -Ox properly. I know about the GHC bug, that's why I used -O2 for GHC/Haskell and -O3 for GCC/C. You just contradicted the line I quoted; was it in error? Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell performance question
On Thu, Nov 08, 2007 at 05:03:54PM -0800, Stefan O'Rear wrote: On Fri, Nov 09, 2007 at 01:39:55AM +0100, Thomas Schilling wrote: On Thu, 2007-11-08 at 16:24 -0800, Stefan O'Rear wrote: On Thu, Nov 08, 2007 at 07:57:23PM +0100, Thomas Schilling wrote: $ ghc --make -O2 ghc-bench.hs Even for GCC (/not/ G_H_C)? No, GCC implements -Ox properly. I know about the GHC bug, that's why I used -O2 for GHC/Haskell and -O3 for GCC/C. You just contradicted the line I quoted; was it in error? Nevermind, I'm just blind today. (thanks Shachaf for bringing this to my attention...) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell performance question
On Thu, Nov 08, 2007 at 07:57:23PM +0100, Thomas Schilling wrote: $ ghc --make -O2 ghc-bench.hs and got: $ time ./ghc-bench 2.0e7 real0m0.714s user0m0.576s sys 0m0.132s $ time ./ghcbC 2000.00 real0m0.305s user0m0.164s sys 0m0.132s This is on a first-gen Macbook running Ubuntu. 1GB RAM. 1.83Ghz Core Duo $ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.8.0.20071019 $ gcc --version gcc (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe $ gcc -O3 ghc-bench.c -o ghcbC ghc-bench.c: In function ‘main’: ghc-bench.c:16: warning: incompatible implicit declaration of built-in function ‘printf’ -O3 is worse than -O0, DO NOT USE IT. I reported the bug several months ago. In the meantime, use -O2. (there are no high optimizations, it's just that the option parser misparses -O3) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] MD5? (was: Haskell performance question)
On Thu, Nov 08, 2007 at 06:14:20PM -0500, Thomas M. DuBuisson wrote: Glad you asked! http://sequence.complete.org/node/367 I just posted that last night! Once I get a a community.haskell.org login I will put the code on darcs. The short of it it: 1) The code is still ugly, I haven't been modivated to clean. 2) Manually unrolled, it is ~ 6 times slower than C 3) When Rolled it is still much slower than that 4) There is some optimizer bug in GHC - this code could be 2x faster, I feel certain. 5) I benchmarked using a 200MB file, so I think it will handle whatever. Why did you put yourself through all this pain when you could have just copied the code from md5sum(1), removed the main function, and foreign imported its buffer accumulator wrapping it as a function over lazy bytestrings? We have the best foreign function interface in the world. Reinventing wheels is stupid, especially if the existing wheels are this easy to use. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Memory-mapped arrays? (IArray interfaces, slices, and so on)
On Wed, Nov 07, 2007 at 10:10:16PM +, Jules Bean wrote: Joel Reymont wrote: Is there such a thing as memory-mapped arrays in GHC? In principle, there could be an IArray instance to memory-mapped files. (There could also be a mutable version, but just the IArray version would be useful). I noticed just the other day that there are some 'obvious' IArray constructors missing. It ought, for example, be possible to build a new IArray from an old from a subset of the elements; a dimensional slice going from an (Int,Int,Int) indexed array to (Int,Int), or a stride taking 'one element in three' along each axis, etc. Annoyingly, it doesn't seem to be straightforward to make your own instances of IArray, since the important methods aren't exported. They are, from the undocumented module Data.Array.Base. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [OT] GHC uninstall on Linux
On Wed, Nov 07, 2007 at 10:41:53AM +0100, Dusan Kolar wrote: Hello all, I use tar.bz2 binary distribution of GHC compiler as my distro does not use any supported packaging system. Everything is fine, but... I want to install the new version of the GHC compiler. Is there any (easy) way, how to get information about what was copied and where during installation? (./configure; make install) There seems to be no uninstall target in the Makefile. :-( And I want to uninstall the previous version of the compiler. You don't need to uninstall GHC, ever, except for disk space reasons. You can easily have thirteen versions of GHC installed and happily coexisting: [EMAIL PROTECTED]:~$ ghci-6. ghci-6.4.2 ghci-6.7 ghci-6.7.20070223 ghci-6.7.20070402 ghci-6.7.20070502 ghci-6.7.20070601 ghci-6.7.20070712 ghci-6.7.20070829 ghci-6.6.1 ghci-6.7.20070213 ghci-6.7.20070323 ghci-6.7.20070413 ghci-6.7.20070518 ghci-6.7.20070612 ghci-6.7.20070826 Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Why can't Haskell be faster?
On Wed, Oct 31, 2007 at 03:37:12PM +, Neil Mitchell wrote: Hi I've been working on optimising Haskell for a little while (http://www-users.cs.york.ac.uk/~ndm/supero/), so here are my thoughts on this. The Clean and Haskell languages both reduce to pretty much the same Core language, with pretty much the same type system, once you get down to it - so I don't think the difference between the performance is a language thing, but it is a compiler thing. The uniqueness type stuff may give Clean a slight benefit, but I'm not sure how much they use that in their analyses. Both Clean and GHC do strictness analysis - I don't know which one does better, but both do quite well. I think Clean has some generalised fusion framework, while GHC relies on rules and short-cut deforestation. GHC goes through C-- to C or ASM, while Clean has been generating native code for a lot longer. GHC is based on the STG machine, while Clean is based on the ABC machine - not sure which is better, but there are differences there. My guess is that the native code generator in Clean beats GHC, which wouldn't be too surprising as GHC is currently rewriting its CPS and Register Allocator to produce better native code. I don't think the register allocater is being rewritten so much as it is being written: [EMAIL PROTECTED]:/tmp$ cat X.hs module X where import Foreign import Data.Int memset :: Ptr Int32 - Int32 - Int - IO () memset p v i = p `seq` v `seq` case i of 0 - return () _ - poke p v memset (p `plusPtr` sizeOf v) v (i - 1) [EMAIL PROTECTED]:/tmp$ ghc -fbang-patterns -O2 -c -fforce-recomp -ddump-asm X.hs ... X_zdwa_info: movl 8(%ebp),%eax testl %eax,%eax jne .LcH6 movl $base_GHCziBase_Z0T_closure+1,%esi addl $12,%ebp jmp *(%ebp) .LcH6: movl 4(%ebp),%ecx movl (%ebp),%edx movl %ecx,(%edx) movl (%ebp),%ecx addl $4,%ecx decl %eax movl %eax,8(%ebp) movl %ecx,(%ebp) jmp X_zdwa_info ... Admittedly that's better than it used to be (I recall 13 memory references last time I tested it), but still... the reason for your performance woes should be quite obvious in that snippet. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Why can't Haskell be faster?
On Thu, Nov 01, 2007 at 02:30:17AM +, Neil Mitchell wrote: Hi I don't think the register allocater is being rewritten so much as it is being written: From talking to Ben, who rewrote the register allocator over the summer, he said that the new graph based register allocator is pretty good. The thing that is holding it back is the CPS conversion bit, which was also being rewritten over the summer, but didn't get finished. I think these are both things which are likely to be done for 6.10. Oh, that's good news. I look forward to a massive increase in the performance of GHC-compiled programs, most specifically GHC itself. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie Question on Setting the GHC Search Path
On Mon, Oct 29, 2007 at 04:25:45AM -0700, Benjamin L. Russell wrote: One factor that is slightly unusual about this phenomenon is that it only occurs with GHC, but not with Hugs 98. Typing :cd D:\From C Drive\Documents and Settings\DekuDekuplex\Programming Practice\Haskell\GHC Are you sure it has anything to do with spaces? Exactly one of your test paths has backslashes, and it's not the working one. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe