[Haskell-cafe] Re: Trees

2007-12-03 Thread apfelmus
Adrian Neumann wrote: 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. Well, this problem doesn't make much sense in Haskell. How do you specify

[Haskell-cafe] Re: Possible Improvements

2007-12-03 Thread apfelmus
PR Stanley wrote: data Tree = Leaf Int | Node Tree Int Tree occurs :: Int - Tree - Bool occurs m (Leaf n) = m == n occurs m (Node l n r) = m == n || occurs m l || occurs m r It works but I'd like to know if it can be improved in any way. That's entirely fine. The logical or || doesn't

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Johan Tibell
I agree that (in this context, beginning learning Haskell) it is a somewhat minor issue. But I disagree that this is something you should ignore until it becomes a problem and I do think that it should be part of learning Haskell. Properly using strictness is an important part of using

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread PR Stanley
That's a very good point. Yes, let's have some detailed explanations accompanied by some good examples. Cheers, Paul At 08:43 03/12/2007, you wrote: I agree that (in this context, beginning learning Haskell) it is a somewhat minor issue. But I disagree that this is something you should

[Haskell-cafe] Re: New slogan for haskell.org

2007-12-03 Thread apfelmus
Stefan O'Rear wrote: In my C programming, I've taken to using gdb as a REPL: Ah, that's a nice trick, thanks! I wish I there had been a gdb on MacOS 8.5 back then ;) Regards, apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Monads

2007-12-03 Thread Radosław Grzanka
Hi, 2007/12/3, PR Stanley [EMAIL PROTECTED]: Hi Does the list consider http://en.wikibooks.org/w/index.php?title=Haskell/Understanding_monadsoldid=933545 a reliable tutorial on monads and, if not, could you recommend an onlien alternative please? I really enjoyed All about Monads by Jeff

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Bulat Ziganshin
Hello PR, Monday, December 3, 2007, 8:20:35 AM, you wrote: occurs m (Node l n r) = m == n || occurs m l || occurs m r in terms of style, i can prefer occurs m (Node l n r) = or [m==n, occurs m l, occurs m r] -- Best regards, Bulatmailto:[EMAIL PROTECTED]

[Haskell-cafe] Monads

2007-12-03 Thread PR Stanley
Hi Does the list consider http://en.wikibooks.org/w/index.php?title=Haskell/Understanding_monadsoldid=933545 a reliable tutorial on monads and, if not, could you recommend an onlien alternative please? Thanks, Paul ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Ketil Malde
Johan Tibell [EMAIL PROTECTED] writes: It would be great if someone could exemplify these rules of thumb, e.g. Primitive types such as Int should be strict unless in the three canonical examples X, Y and Z. My strictness radar is still quite poor and I feel I can't make informed decisions on

Re: [Haskell-cafe] Re: Array copying

2007-12-03 Thread Reinier Lamers
ChrisK wrote: For GHC 6.6 I created foreign import ccall unsafe memcpy memcpy :: MutableByteArray# RealWorld - MutableByteArray# RealWorld - Int# - IO () {-# INLINE copySTU #-} copySTU :: (Show i,Ix i,MArray (STUArray s) e (ST s)) = STUArray s i e - STUArray s i e - ST s ()

Re: [Haskell-cafe] A tale of three shootout entries

2007-12-03 Thread Don Stewart
s.clover: Was this with tossing the partial sums code into the optimised bangs program? Weird. I wonder if profiling will help explain why? In any case, If nobody comes up with any other tweaks, I'll probably submit the optimised bangs version to the shootout this weekend.

[Haskell-cafe] Parallelise now! Was: Re: Possible Improvements

2007-12-03 Thread Don Stewart
dons: Strict in the elements, lazy in the spine: data Tree = Leaf !Int | Node Tree !Int Tree $ time ./A 25 49 ./A 25 14.41s user 0.03s system 99% cpu 14.442 total ^^ 3056K heap use. And, finally, we can get a

[Haskell-cafe] Re: Optimizing cellular automata evaluation (round 2)

2007-12-03 Thread Mirko Rahn
http://hpaste.org/4151#a1 It is interesting, that the naive implementation import Data.List (tails) neighbours :: Int - [a] - [[a]] neighbours w = rotL . take w . map (take 3) . tails . cycle rotL :: [a] - [a] rotL xs = last xs : init xs type Rule a = [a] - a step :: Int - Rule a - [a]

[Haskell-cafe] Re: Trees

2007-12-03 Thread apfelmus
Thomas Davie wrote: apfelmus wrote Well, this problem doesn't make much sense in Haskell. How do you specify the subtrees u and v in the first place? One could alway store a node's depth at each node -- then you must search for u and v, creating a list of what nodes you found at each

Re: [Haskell-cafe] Re: Trees

2007-12-03 Thread Thomas Davie
One could alway store a node's depth at each node -- then you must search for u and v, creating a list of what nodes you found at each depth, and finally, simply compare the lists -- O(n) in the depth of u and v. Bob On 3 Dec 2007, at 08:40, apfelmus wrote: Adrian Neumann wrote: data

[Haskell-cafe] do

2007-12-03 Thread PR Stanley
Hi I've probably asked about the do construct, if that's the right label. Unfortunately I'm still not quite sure of its role and more specifically its syntax. Something to do with generators perhaps? A description plus some examples would be most gratefully received. Thanks, Paul

Re: [Haskell-cafe] ARM back end?

2007-12-03 Thread John Meacham
On Fri, Nov 02, 2007 at 01:30:44PM -0700, Greg Fitzgerald wrote: Anybody know of an ARM back end for any of the Haskell compilers? jhc can compile to the arm as well. This was tested by compiling a simple program for the iPhone. :) John -- John Meacham - ⑆repetae.net⑆john⑈

Re: [Haskell-cafe] I'm translating All about Monads to Chinese

2007-12-03 Thread Radosław Grzanka
2007/12/3, Albert Lee [EMAIL PROTECTED]: I have been confussed by monad for a long time. and I can't stand for it any more. so I start to translate the tutorial All About Monads to my mother language Chinese. My English is not good enough, so this work is only for my own study~ I know there

[Haskell-cafe] I'm translating All about Monads to Chinese

2007-12-03 Thread Albert Lee
I have been confussed by monad for a long time. and I can't stand for it any more. so I start to translate the tutorial All About Monads to my mother language Chinese. My English is not good enough, so this work is only for my own study~ I know there are some other Chinese fellow in this list,

[Haskell-cafe] type class question

2007-12-03 Thread Peter Padawitz
What is wrong here? ghci tries (and fails) to deduce certain types for the comp functions that I did not expect. |type Block = [Command] data Command = Skip | Assign String IntE | Cond BoolE Block Block | Loop BoolE Block data IntE= IntE Int | Var String | Sub IntE IntE |

[Haskell-cafe] Re: A tale of three shootout entries

2007-12-03 Thread Simon Marlow
Simon Peyton-Jones wrote: | There may well have been changes to the strictness analyser that make | some of the bangs (or most) unnecessary now. Also, its very likely | I didn't check all combinations of strict and lazy arguments for the | optimal evaluation strategy :) | | If it seems to be

[Haskell-cafe] Re: Waiting for thread to finish

2007-12-03 Thread Simon Marlow
Brad Clow wrote: On Nov 28, 2007 11:30 AM, Matthew Brecknell [EMAIL PROTECTED] wrote: Even with threads, results are evaluated only when they are needed (or when forced by a strictness annotation). So the thread that needs a result (or forces it) first will be the one to evaluate it. So does

Re: [Haskell-cafe] do

2007-12-03 Thread Denis Bueno
On Dec 3, 2007 6:55 AM, PR Stanley [EMAIL PROTECTED] wrote: Hi I've probably asked about the do construct, if that's the right label. Unfortunately I'm still not quite sure of its role and more specifically its syntax. Something to do with generators perhaps? A description plus some examples

[Haskell-cafe] Re: Array copying

2007-12-03 Thread ChrisK
Reinier Lamers wrote: ChrisK wrote: For GHC 6.6 I created foreign import ccall unsafe memcpy memcpy :: MutableByteArray# RealWorld - MutableByteArray# RealWorld - Int# - IO () {-# INLINE copySTU #-} copySTU :: (Show i,Ix i,MArray (STUArray s) e (ST s)) = STUArray s i e -

Re: [Haskell-cafe] Trees

2007-12-03 Thread Yitzchak Gale
Adrian Neumann wrote: data Tree a = Leaf a | Node a [Tree a] 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... In Haskell however the best way I've come up with so far is doing a BFS and

[Haskell-cafe] Re: Array copying

2007-12-03 Thread ChrisK
Andrew Coppin wrote: ChrisK wrote: For GHC 6.6 I created foreign import ccall unsafe memcpy memcpy :: MutableByteArray# RealWorld - MutableByteArray# RealWorld - Int# - IO () {-# INLINE copySTU #-} copySTU :: (Show i,Ix i,MArray (STUArray s) e (ST s)) = STUArray s i e -

Re: [Haskell-cafe] Trees

2007-12-03 Thread Matthew Brecknell
Adrian Neumann: data Tree a = Leaf a | Node a [Tree a] example: given a tree t and two nodes u,v, find the first common ancestor. The following solves what I think is a generalisation of this problem. That is, given a tree and a predicate on its elements, return the smallest subtree

Re: [Haskell-cafe] ARM back end?

2007-12-03 Thread Mathieu Boespflug
On Nov 2, 2007 10:19 PM, nornagon [EMAIL PROTECTED] wrote: On 03/11/2007, Greg Fitzgerald [EMAIL PROTECTED] wrote: Anybody know of an ARM back end for any of the Haskell compilers? If there's an arm-eabi port somewhere, I might be able to get Haskell code running on the Nintendo DS...

[Haskell-cafe] Nofib modifications

2007-12-03 Thread Neil Mitchell
Hi, Some of the nofib suite are messed up by Yhc/nhc because of the monomorphism restriction. Take imaginary/bernouilli as an example: powers = [2..] : map (zipWith (*) (head powers)) powers Hugs and GHC both see powers :: [[Integer]] and a CAF. Yhc (and nhc) both see powers :: (Enum a, Num a)

[Haskell-cafe] foild function for expressions

2007-12-03 Thread Carlo Vivari
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 -

Re: [Haskell-cafe] Trees

2007-12-03 Thread Derek Elkins
On Mon, 2007-12-03 at 16:56 +0200, Yitzchak Gale wrote: Adrian Neumann wrote: data Tree a = Leaf a | Node a [Tree a] 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... In Haskell however

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Derek Elkins
On Mon, 2007-12-03 at 10:48 +0100, Ketil Malde wrote: Johan Tibell [EMAIL PROTECTED] writes: It would be great if someone could exemplify these rules of thumb, e.g. Primitive types such as Int should be strict unless in the three canonical examples X, Y and Z. My strictness radar is still

Re: [Haskell-cafe] foild function for expressions

2007-12-03 Thread Kalman Noel
Carlo Vivari wrote: data AlgExp a = AlgExp { litI :: Int - a, litB :: Bool - a, add :: a - a - a, and :: a - a - a, ifte :: a - a - a - a} You're confusing sum and product types. That is, you're using a product type, but you probably need a sum type, like this: data Exp1 =

RE: [Haskell-cafe] Nofib modifications

2007-12-03 Thread Simon Peyton-Jones
By all means apply a patch, I think. Simon | -Original Message- | From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Neil Mitchell | Sent: 03 December 2007 17:34 | To: Haskell Cafe | Cc: Simon Marlow; Malcolm Wallace; Duncan Coutts | Subject: [Haskell-cafe] Nofib

Re: [Haskell-cafe] Parsing unstructured data

2007-12-03 Thread Olivier Boudry
On 12/2/07, Steven Fodstad [EMAIL PROTECTED] wrote: Sorry for not responding earlier. The haskell-cafe list is hard to keep up with. The process of finding geographic (lat/long) coordinates from a text address is called geocoding. Obviously extracting the parts of an address is part of

Re: [Haskell-cafe] do

2007-12-03 Thread Tim Newsham
Probably one should understand how to use monads before worrying about the do-notation. Here are some references: I don't totally agree. You can teach monads to beginners just fine using the do-notation. Unsuprisingly its very much like teaching monads using bind. You describe a two line

[Haskell-cafe] ANN: atom 2007.12

2007-12-03 Thread Tom Hawkins
Hello, Atom is a language embedded in Haskell for describing reactive software, primarily for realtime control applications. Based on conditional term rewriting, an atom description is composed of a set of state transition rules. The name atom comes from the atomic behavior of rules: if a rule

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Andrew Coppin
Johan Tibell wrote: It would be great if someone could exemplify these rules of thumb, e.g. Primitive types such as Int should be strict unless in the three canonical examples X, Y and Z. My strictness radar is still quite poor and I feel I can't make informed decisions on when I need to make

Re: [Haskell-cafe] A tale of three shootout entries

2007-12-03 Thread Andrew Coppin
Don Stewart wrote: Please go ahead and submit. :) and remember to upload also to our wiki, so we have a permanent record of the attempt, http://haskell.org/haskellwiki/Shootout Note down any ideas you have. Now that GHC 6.6 is available, please you it? Last time I looked at the

Re: [Haskell-cafe] A tale of three shootout entries

2007-12-03 Thread Don Stewart
andrewcoppin: Don Stewart wrote: Please go ahead and submit. :) and remember to upload also to our wiki, so we have a permanent record of the attempt, http://haskell.org/haskellwiki/Shootout Note down any ideas you have. Now that GHC 6.6 is available, please you it? Looks

Re: [Haskell-cafe] A tale of three shootout entries

2007-12-03 Thread Andrew Coppin
Don Stewart wrote: andrewcoppin: Now that GHC 6.6 is available, please you it? Looks like something broke in an edit. Feel free to correct it. Oh well. ;-) But then, the GHC wiki still says The 6.8 branch is the current STABLE, and we are in the 6.8.1 release candidate phase.

Re: [Haskell-cafe] do

2007-12-03 Thread Denis Bueno
On 03 Dec 2007, at 13:25 , Tim Newsham wrote: Probably one should understand how to use monads before worrying about the do-notation. Here are some references: I don't totally agree. You can teach monads to beginners just fine using the do-notation. Unsuprisingly its very much like

Re: [Haskell-cafe] ANN: atom 2007.12

2007-12-03 Thread Alex Jacobson
This sounds like a really interesting piece of software. That being another significant use for the name Atom these days is as an identifier for a feed format. http://en.wikipedia.org/wiki/Atom_(standard) You may find it easier to advertise and romote this project with a more unique name.

Re: [Haskell-cafe] do

2007-12-03 Thread Dan Piponi
On Dec 3, 2007 1:09 PM, Denis Bueno [EMAIL PROTECTED] wrote: I don't think I can conclude that there are *no* reasons to teach the do-notation first. I just think that it is more instructive to teach it later. It's standard in mathematics teaching, when introducing a mathematical structure

Re: [Haskell-cafe] Re: Waiting for thread to finish

2007-12-03 Thread Ryan Ingram
On 11/27/07, Matthew Brecknell [EMAIL PROTECTED] wrote: wait_first :: [Wait a] - IO (a, [Wait a]) wait_first [] = error wait_first: nothing to wait for wait_first ws = atomically (do_wait ws) where do_wait [] = retry do_wait (Wait w : ws) = do r - readTVar w case r of

[Haskell-cafe] Problems building and using ghc-6.9

2007-12-03 Thread Daniel Fischer
Hi, so today I built ghc-6.9.20071124. First, make died because HsColour version = 1.8 was needed, couldn't determine the version. I had HsColour 1.6, got myself 1.8, built and installed. make died again, same problem. I added (v, Version) to the optionTable in HsColour.hs and it worked :)

[Haskell-cafe] Re: Waiting for thread to finish

2007-12-03 Thread Ben Franksen
Belatedly I realized that this answer should have been going to the list: --- ChrisK wrote: On Mittwoch, 28. November 2007, you wrote: A safer gimmick... Ben Franksen wrote: tickWhileDoing :: String - IO a - IO a tickWhileDoing msg act = do hPutStr stderr msg hPutChar

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread ajb
G'day all. On Mon, 2007-12-03 at 10:48 +0100, Ketil Malde wrote: I find that I often need to add strictness when: left thumb) parsing [Char] into something more compact, i.e. almost all cases. right thumb) storing data into maps, especially when the values are produced by

[Haskell-cafe] Re: Monads

2007-12-03 Thread Ben Franksen
PR Stanley wrote: Does the list consider http://en.wikibooks.org/w/index.php?title=Haskell/Understanding_monadsoldid=933545 a reliable tutorial on monads and, if not, could you recommend an onlien alternative please? I strongly recommend the original papers by Philip Wadler, especially this

[Haskell-cafe] doing builds using cygwin on Windows

2007-12-03 Thread Galchin Vasili
To Nanonthief .. VasiliIGalchin wrote: .. however, I don't see in which file PATH can be set. Any help? I really want to get my Haskell build environment set up and cranking away. Unless I misunderstood what you want, you can add a path to the PATH variable by adding the line: export

[Haskell-cafe] Re: do

2007-12-03 Thread Ben Franksen
Dan Piponi wrote: On Dec 3, 2007 1:09 PM, Denis Bueno [EMAIL PROTECTED] wrote: I don't think I can conclude that there are *no* reasons to teach the do-notation first. I just think that it is more instructive to teach it later. It's standard in mathematics teaching, when introducing a

Re: [Haskell-cafe] foild function for expressions

2007-12-03 Thread Brent Yorgey
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) = ¿¿¿??? One comment: it looks like (add exp1 exp2), (and exp1 exp2) and so on

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Felipe Lessa
On Dec 3, 2007 9:23 PM, [EMAIL PROTECTED] wrote: 2. If it's logically a Functor, strictness will break the axioms, so don't do that. What do you mean by breaking the axioms? If I define data List a = Nil | Cons !a !(List a) instance Functor List where fmap f Nil = Nil fmap f (Cons x

Re: [Haskell-cafe] foild function for expressions

2007-12-03 Thread Ryan Ingram
On 12/3/07, Kalman Noel [EMAIL PROTECTED] wrote: You're confusing sum and product types. That is, you're using a product type, but you probably need a sum type, like this: I'm not so sure; it looks like they already have that type (Exp) and wants to use AlgExp to hold the folding functions

Re: [Haskell-cafe] Re: do

2007-12-03 Thread Dan Piponi
On Dec 3, 2007 3:54 PM, Ben Franksen [EMAIL PROTECTED] wrote: I don't buy this. As has been noted by others before, IO is a very special case, in that it can't be defined in Haskell itself, and there is no evaluation function runIO :: IO a - a. I'm not sure what a function of type m a - a has

Re: [Haskell-cafe] An interesting monad: Prompt

2007-12-03 Thread Thomas Hartman
I've been playing with MonadPrompt for about ten days now, trying to get it to do something useful for me. Specifically, I'm trying to implement guess a number since that's the hello world of haskell state programs, or so it seems to me. I want to have this with scripting / replay / undo and

Fw: [Haskell-cafe] Re: do

2007-12-03 Thread Thomas Hartman
It took me forever to get comfortable with monads. I think it helps if you've seen continuations, or done FP before, or a variety of things that build familiarity. But probably the only thing that I think will work for the masses of plodders (there are always a few stars to crash the curve) is

Re: [Haskell-cafe] Re: do

2007-12-03 Thread Jonathan Cast
On 3 Dec 2007, at 4:19 PM, Dan Piponi wrote: On Dec 3, 2007 3:54 PM, Ben Franksen [EMAIL PROTECTED] wrote: I don't buy this. As has been noted by others before, IO is a very special case, in that it can't be defined in Haskell itself, and there is no evaluation function runIO :: IO a - a.

[Haskell-cafe] ANN: Shu-thing 1.0 and Monadius 0.9

2007-12-03 Thread gwern0
Hi everyone. With the permission of the authors, I'd like to announce the release upload to Hackage of two games written in Haskell (you may've seen them mentioned here once or twice before): *Monadius *Shu-thing They are both scrolling 2 dimensional arcade shooting games which use 3D vector

[Haskell-cafe] IO is a bad example for Monads [was: do]

2007-12-03 Thread Ben Franksen
Dan Piponi wrote: On Dec 3, 2007 3:54 PM, Ben Franksen [EMAIL PROTECTED] wrote: I don't buy this. As has been noted by others before, IO is a very special case, in that it can't be defined in Haskell itself, and there is no evaluation function runIO :: IO a - a. I'm not sure what a

[Haskell-cafe] Advice for clean code.

2007-12-03 Thread David McBride
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

Re: [Haskell-cafe] Re: Waiting for thread to finish

2007-12-03 Thread Matthew Brecknell
Ryan Ingram said: Interesting, although this seems like a perfect use for orelse: wait_stm :: Wait a - STM a wait_stm (Wait w) = readTVar w = maybe retry return wait :: Wait a - IO a wait w = atomically $ wait_stm w wait_first :: [Wait a] - IO (a, [Wait a]) wait_first [] = error

Re: [Haskell-cafe] Advice for clean code.

2007-12-03 Thread Don Stewart
stefanor: 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

Re: [Haskell-cafe] foild function for expressions

2007-12-03 Thread Stefan O'Rear
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:

Re: [Haskell-cafe] foild function for expressions

2007-12-03 Thread Stefan O'Rear
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

Re: [Haskell-cafe] Advice for clean code.

2007-12-03 Thread Stefan O'Rear
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,

Re: [Haskell-cafe] foild function for expressions

2007-12-03 Thread Derek Elkins
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:

[Haskell-cafe] Looking for smallest power of 2 = Integer

2007-12-03 Thread Dan Piponi
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 anyone have any recommendations for how to do it efficiently. There are some obvious things that come to mind but which might involve quite a bit of useless

Re: [Haskell-cafe] Looking for smallest power of 2 = Integer

2007-12-03 Thread Brandon S. Allbery KF8NH
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)? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell]

Re: [Haskell-cafe] Advice for clean code.

2007-12-03 Thread Andrew Wagner
Don's code intrigued me, so I fired up my trusty emacs and ghci, and turned it into actual code, which type-checks. Well, ok, I kind of randomly poked at it, while begging for help, which I received in abundance from #haskell, particularly oerjan, and Don himself. Anyway, here's the code: {-#

Re: [Haskell-cafe] Looking for smallest power of 2 = Integer

2007-12-03 Thread Stefan O'Rear
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,

Re: [Haskell-cafe] Looking for smallest power of 2 = Integer

2007-12-03 Thread Don Stewart
dpiponi: On Dec 3, 2007 9:10 PM, Don Stewart [EMAIL PROTECTED] 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? Well, you could use testBit, which is pretty efficient, But testBit tests only one bit at a

Re: [Haskell-cafe] Looking for smallest power of 2 = Integer

2007-12-03 Thread Sterling Clover
Actually, I suspect GHC's strictness analyzer will give you reasonable performance with even the naive version, but fancier ideas are at http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog The problem with all those, however, is since they do bit-twiddling and use shifts and

Re: [Haskell-cafe] Looking for smallest power of 2 = Integer

2007-12-03 Thread Don Stewart
dpiponi: 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 anyone have any recommendations for how to do it efficiently. There are some obvious things that come to mind but which might involve quite a bit

Re: [Haskell-cafe] IO is a bad example for Monads [was: do]

2007-12-03 Thread Dan Piponi
On Dec 3, 2007 6:36 PM, Ben Franksen [EMAIL PROTECTED] wrote: then the special features of IO will remain associated with monads in general, leading to a whole jumble of completely wrong ideas about them. As I only learnt about monads a couple of years ago, the process is still fresh in my

Re: [Haskell-cafe] Looking for smallest power of 2 = Integer

2007-12-03 Thread Dan Piponi
On Dec 3, 2007 9:10 PM, Don Stewart [EMAIL PROTECTED] 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? Well, you could use testBit, which is pretty efficient, But testBit tests only one bit at a time. To prove

Re: [Haskell-cafe] Looking for smallest power of 2 = Integer

2007-12-03 Thread Dan Piponi
On Dec 3, 2007 9:32 PM, Sterling Clover [EMAIL PROTECTED] wrote: if all else fails, be determined by unpacking it into the primitives, which are (# Int#, ByteArr# #) with the Int# as the number of limbs of the integer, as well as its sign. That's the answer I'm looking for, thanks. -- Dan

Re: [Haskell-cafe] Looking for smallest power of 2 = Integer

2007-12-03 Thread David Benbennick
On 12/3/07, Dan Piponi [EMAIL PROTECTED] wrote: On Dec 3, 2007 9:32 PM, Sterling Clover [EMAIL PROTECTED] wrote: if all else fails, be determined by unpacking it into the primitives, which are (# Int#, ByteArr# #) with the Int# as the number of limbs of the integer, as well as its sign.

[Haskell-cafe] The Opposite of $

2007-12-03 Thread PR Stanley
Hi According to the Haskell Wikibook the € is the opposite of $. The text also oints out that the | can be used as a substitute. I tried using | but to no avail. Is the list au fait with the | operator? Thanks, Paul ___ Haskell-Cafe mailing list