[Haskell-cafe] HGL window update problem

2009-02-06 Thread Rodrigo Queiro
In this program, the HGL window only updates when I mouseover it. Can someone tell me why this is / how I should avoid it? Thanks! Rodrigo module Main where import Graphics.HGL import Control.Concurrent import Control.Concurrent.MVar import Control.Monad main = do stringMVar -

Re: [Haskell-cafe] IO () and IO [()]

2008-03-10 Thread Rodrigo Queiro
You're looking for mapM_ mapM_ :: (Monad m) = (a - m b) - [a] - m () (see also sequence_ :: (Monad m) = [m a] - m () ) I don't think that it is possible to have a 1-tuples, just 2 and up. () is a unit rather than a 0-tuple, apparently: http://www.haskell.org/onlinereport/basic.html#sect6.1.4 On

Re: [Haskell-cafe] haskellwiki and Project Euler

2008-02-24 Thread Rodrigo Queiro
The only time I have found the solutions page useful is when I was working on problem 100, which I'd been thinking about on and off for several months. Eventually, I gave up and looked at the solution there, and was absolutely none the wiser as to how it was solved! I thought about it more over

Re: [Haskell-cafe] haskellwiki and Project Euler

2008-02-24 Thread Rodrigo Queiro
OEIS, 'solved'. I really don't understand why someone would do that. On 24/02/2008, Chaddaï Fouché [EMAIL PROTECTED] wrote: 2008/2/24, Rodrigo Queiro [EMAIL PROTECTED]: The only time I have found the solutions page useful is when I was working on problem 100, which I'd been thinking about

Re: [Haskell-cafe] Mutable arrays

2008-02-02 Thread Rodrigo Queiro
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) =

Re: [Haskell-cafe] Mutable arrays

2008-02-02 Thread Rodrigo Queiro
Sorry, I was lazy. New maximum': maximum' = foldl1' max On 02/02/2008, Rodrigo Queiro [EMAIL PROTECTED] 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

Re: [Haskell-cafe] Newbie question related to list evaluation

2008-01-06 Thread Rodrigo Queiro
You have used the name 'pos' twice, for both the parameter and the returned value of the recursive call. The reason this results in an infinite loop is that in code like let x = x + 1 Haskell treats both xs to be references to the same thing, so evaluates: x = x + 1 = (x + 1) + 1 = ((x + 1) + 1)

Re: [Haskell-cafe] Re: Why can't Haskell be faster?

2007-11-01 Thread Rodrigo Queiro
I assume the reason the switched away from LOC is to prevent programmers artificially reducing their LOC count, e.g. by using a = 5; b = 6; rather than a = 5; b = 6; in languages where newlines aren't syntactically significant. When gzipped, I guess that the ;\n string will be represented about

Re: [Haskell-cafe] Re: newbie optimization question

2007-10-29 Thread Rodrigo Queiro
rem is faster because it has slightly different behaviour to mod, and there happens to be an intel instruction that maps more directly to rem than to mod, thus making it much faster on intel processors. Why do you expose perfect and divisors? Maybe if you just expose main, perfect and divisors

Re: [Haskell-cafe] more functions to evaluate

2007-10-13 Thread Rodrigo Queiro
Dan: Sorry, I forgot to Reply to All. On 12/10/2007, Dan Weston [EMAIL PROTECTED] wrote: ... We don't want to make an intermediate list of zeroes and append, since that could be wasteful. Just keep adding a zero to the head of our list until it gets big enough. Our list is not copied (i.e. it

Re: [Haskell-cafe] int to bin, bin to int

2007-09-27 Thread Rodrigo Queiro
If you don't like explicit recursion (or points): intToBin = map (`mod` 2) . takeWhile (0) . iterate (`div` 2) binToInt = foldl' (\n d - n*2+d) 0 or even: binToInt = foldl' ((+).(*2)) 0 On 27/09/2007, PR Stanley [EMAIL PROTECTED] wrote: Hi intToBin :: Int - [Int] intToBin 1 = [1] intToBin n

Re: [Haskell-cafe] reverse with foldl

2007-09-21 Thread Rodrigo Queiro
Prelude :t foldl (\x - \xs - xs:x) [] foldl (\x - \xs - xs:x) [] :: [b] - [b] Strange choice of names, though, since x is a list, and xs is an element. I would have gone for: foldl (\xs x - x:xs) [] although the library opts for: foldl (flip (:)) [] On 21/09/2007, Miguel Mitrofanov [EMAIL

Re: [Haskell-cafe] Missing Symbol (2)

2007-09-19 Thread Rodrigo Queiro
This looks like foldr, specifically: f = foldr (.) v so really, there's no way of telling what the operator could be, other than that: (.) :: a - b - b where f :: [a] - b v :: b BTW, I find that most of your emails are in a very large font size. Do other people notice this? It's not very nice to

Re: [Haskell-cafe] How can I stop GHCi from calling show for IO actions?

2007-09-16 Thread Rodrigo Queiro
I've always wondered if ghc(i) --help should be a bit more instructive, or perhaps if there were a man page that lay somewhere between the --help message and the manual in terms of comprehensiveness. It's a pretty major jump from a short description of 4 command line options (only one of which I

Re: [Haskell-cafe] turning an imperative loop to Haskell

2007-09-06 Thread Rodrigo Queiro
When you get to more than two arguments, it will probably be nicer to do something like this: fibs = map (\(a,b) - a) $ iterate (\(a,b) - (b, a+b)) (0,1) or fibs = unfoldr (\(a,b) - Just (a, (b, a+b))) (0,1) -- this uses unfoldr to get rid of the map This is essentially a translation of the

Re: [Haskell-cafe] GHC optimisations

2007-08-22 Thread Rodrigo Queiro
Using the fromInteger (and fromRational) axioms should only *increase* precission, I don't see how that is such a bad thing. I think it's bad if the behaviour of your program depends on the optimisation level. On 22/08/07, Twan van Laarhoven [EMAIL PROTECTED] wrote: Stefan O'Rear wrote: On

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Rodrigo Queiro
On my system, the C version runs about 9x faster than the haskell version (with -O3 and -O2 -fvia-c -optc-O3 respectively). However, GCC seems to produce about 70 lines of assembly for the main loop, compared to about 10 from GHC. I suspect the speed difference is the result of some heavy

Re: [Haskell-cafe] defining last using foldr

2007-08-14 Thread Rodrigo Queiro
I've found a way to do it, but it's not pretty. Hint: The function in the foldr first get the last value, and will need to keep it the whole way through. How can it tell if it is being given the last item or an earlier item? I'm generally not too good at the Socratic method, so feel free to

Re: [Haskell-cafe] defining last using foldr

2007-08-14 Thread Rodrigo Queiro
You can consider foldr to be continual modification of a state. The initial state is given as an argument, and then the (a - b - b) function is passed the next element of the list and the current state, and it returns the new state. foldr will then return the final state, from which the result can

Re: [Haskell-cafe] Cartesian product of a Set

2007-08-01 Thread Rodrigo Queiro
toList generates a sorted list since it is implemented as toList = toAscList, but it's probably bad form to rely on that. On 01/08/07, Andy Gimblett [EMAIL PROTECTED] wrote: On Wed, Aug 01, 2007 at 01:42:52PM -0700, Dan Weston wrote: Andy Gimblett wrote: cartesian :: Ord a = S.Set a -

Re: [Haskell-cafe] Re: OK, so this VIM thing -- how do I make it actually work?

2007-06-05 Thread Rodrigo Queiro
Perhaps you could just highlight the small subset of LaTeX that is common in .lhs files? This seems like it would be satisfactory in most cases. On 05/06/07, Paul Moore [EMAIL PROTECTED] wrote: On 05/06/07, Michael T. Richter [EMAIL PROTECTED] wrote: Oops. I spoke too soon. It works ...

Re: [Haskell-cafe] Implementing Mathematica

2007-05-31 Thread Rodrigo Queiro
http://hackage.haskell.org/trac/ghc/ticket/106 It got changed to Won't Fix. Consider this a yell! On 31/05/07, Simon Peyton-Jones [EMAIL PROTECTED] wrote: | Incidentally, when I try to recompile with optimizations turned on, GHC | refuses to work: | | $ ghc htrace.hs -o htrace | $ ghc -O2

Re: [Haskell-cafe] Curiose types

2007-05-28 Thread Rodrigo Queiro
After a little too long trying, I managed to get code from which the type system will infer that type, without using 'undefined': *Main :t map map :: ((a - a1) - [a]) - [a1] import System.IO.Unsafe import Data.IORef import Prelude hiding (map) import qualified Prelude as P coerce a =

Re: [Haskell-cafe] Memoization

2007-05-27 Thread Rodrigo Queiro
sorear pointed me to this paper a while ago: http://citeseer.ist.psu.edu/peytonjones99stretching.html I never tried any of the code in the end, but it will probably be useful? On 27/05/07, Mark Engelberg [EMAIL PROTECTED] wrote: I'd like to write a memoization utility. Ideally, it would look

Re: [Haskell-cafe] More on the random idea

2007-05-26 Thread Rodrigo Queiro
As far as I know, hs-plugins works by taking an expression, writing it to a file, calling GHC to parse it, transform it to Core, optimise it, transform it to STG, optimise it, transform it to C--, optimise it, transform it to ANSI C, optimise it, pass it to GCC, compile it, link it, and *then*

Re: [Haskell-cafe] Editor

2007-05-21 Thread Rodrigo Queiro
My friend read your email and remarked: How is this guy not embarrassed posting on the internet about not liking vim because he doesn't like editing config files? On 21/05/07, Michael T. Richter [EMAIL PROTECTED] wrote: On Mon, 2007-21-05 at 11:47 +0100, Jules Bean wrote: Michael T. Richter

Re: [Haskell-cafe] Editor

2007-05-21 Thread Rodrigo Queiro
With a slightly less flippant response, have you ever tried TextMate? I haven't, but I've heard many wax lyrical about its combination of the UNIXy power of Vim et al with the intuitive and simple UI that OS X has a reputation for. Unfortunately, it's not free and is only for Mac OS X, but it

Re: [Haskell-cafe] Random idea

2007-05-20 Thread Rodrigo Queiro
http://lambdabot.codersbase.com/ Still, an interface like the fancy Web 2.0 ones that Ruby has could be nice. On 20/05/07, Andrew Coppin [EMAIL PROTECTED] wrote: Greetings. I was thinking... we already have Lambdabot sitting in an IRC channel. How hard would it be to mangle Lambdabot to the

Re: [Haskell-cafe] Who lives in a heap like this?

2007-05-19 Thread Rodrigo Queiro
I think (although I am far from an expert) that it is a skew heap, based on this: http://www.palgrave.com/pdfs/0333992857.pdf On 19/05/07, Andrew Coppin [EMAIL PROTECTED] wrote: Greetings. I have just implemented a heap. But... um... I can't acutally figure out *which kind* of heap it is!

Re: [Haskell-cafe] Short and sweet

2007-05-18 Thread Rodrigo Queiro
group collects equal elements in sublists. Thus, unique can be implemented as: unique = map head . group i.e. taking the first of each group of equal elements. (Yet) another way of doing this, is a modified quicksort: qsort [] = [] qsort (x:xs) = qsort (filter (x) xs) ++ [x] ++ qsort (filter

Re: [Haskell-cafe] Limits of deduction

2007-05-11 Thread Rodrigo Queiro
I think it might be impossible. For the function: sumFirst n = sum . take n then for any finite list, we can choose an n large enough that it will examine the whole list, even though the function is able to stop. This means the only way to check is to call it with an infinite list and see if it