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 -
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
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
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
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) =
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
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)
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
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
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
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
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
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
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
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
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
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
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
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
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 -
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 ...
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
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 =
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
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*
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
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
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
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!
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
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
31 matches
Mail list logo