Re: [Haskell-cafe] haskell platform questions

2010-03-21 Thread Don Stewart
You should file a bug on the Haskell Platform bug tracker.

http://haskell.org/haskellwiki/Haskell_Platform#Trouble_shooting

And I'm CC'ing the dmg maintainer -- it may also be a GHC issue as well.

-- Don

warrensomebody:
> I downloaded the new haskell-platform-2010.1.0.0-i386.dmg today... ran  
> the uninstaller, ghc installer and the platform installer. When I run  
> ghci, it seems to work fine, but when I try cabal, I get this crash:
>
> $ cabal --version
> dyld: unknown required load command 0x8022
> Trace/BPT trap
>
> Any suggestions? (I'm on 10.5.8). Maybe I'll try the macport install  
> process instead.
>
> Thanks for your help,
>
> Warren
>
> On Mar 18, 2010, at 9:26 AM, John Velman wrote:
>
>> I'm also on Mac Leopard.  I tried installing ghc 6.12 with Haskell
>> Platform 2009.2.9.2-i386.dmg (ghc 6.10.4) for some reason, and ran  
>> into
>> a bunch of problems (problems to me, anyway).  I ended up uninstalling 
>> 6.12
>> and reinstalling haskell platform.  Uninstall is easy, there is an
>> uninstaller script in /Library/Frameworks/GHC.framework/Tools.
>> (strangely, not in ..Frameworks/HaskellPaltform.framework).
>>
>> I'm still using Leopard, but would like to move to Snow Leopard once I 
>> get
>> a few things out of the way.  But I see that there are (or were) some 
>> tricks in
>> getting ghc to work on OS X 10.6, apparently.  These seem to be well
>> documented, but, I'd rather spend the time on my own projects.
>>
>> Best,
>>
>> John V.
>>
>>
>>
>> On Wed, Mar 17, 2010 at 09:07:03PM -0700, Warren Harris wrote:
>>> I installed haskell platform some time ago, and now I'm wondering  
>>> what
>>> version I have. How do I find out?
>>>
>>> Also, when the new one comes along on the 21st, is there a way to  
>>> upgrade?
>>> Or if I must first uninstall the one I have now, how do I uninstall  
>>> it?
>>>
>>> Is it recommended to periodically upgrade packages that came with the
>>> platform (cabal upgrade), or is it recommended that they be left  
>>> alone to
>>> avoid dependency incompatibilities. Similar question for ghc itself  
>>> --
>>> can/should it be upgraded in the context of haskell platform?  (I was
>>> hoping to try Leksah, but it dies without ghc 6.12.1. I seem to have
>>> 6.10.4.)
>>>
>>> Apologies in advance if this is all documented somewhere, but I  
>>> couldn't
>>> find it on the haskell platform site/trac. BTW, I'm on Mac/Leopard  
>>> -- love
>>> the fact that it didn't take hours to build everything!
>>>
>>> Warren
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] haskell platform questions

2010-03-21 Thread wren ng thornton

Gregory Collins wrote:

Warren Harris  writes:


I downloaded the new haskell-platform-2010.1.0.0-i386.dmg today... ran the
uninstaller, ghc installer and the platform installer. When I run  ghci, it
seems to work fine, but when I try cabal, I get this crash:

$ cabal --version
dyld: unknown required load command 0x8022
Trace/BPT trap

Any suggestions? (I'm on 10.5.8). Maybe I'll try the macport install process
instead.


Is anyone else still on Leopard who can test this? I am worried that the
binaries (which were linked on Snow Leopard) are not working on Leopard.


I'm still on 10.5.8. I don't have cabal-install installed yet, but I 
just installed GHC-6.12.1/HP-2010.1.0.0. I can verify that ghci works 
fine so far. I'll check out cabal-install in the next couple days.


--
Live well,
~wren
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Bubble sort algorithm implementations (Haskell vs. C)

2010-03-21 Thread kingping
Felipe Lessa  gmail.com> writes:

> 
> On Mon, Mar 22, 2010 at 01:08:39AM +, kingping wrote:
> > Here's my C implementation:
> > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=24191#a24191
> 
> I don't know how much difference in time there would be, but you
> should use lists in C and/or mutable arrays in Haskell, otherwise
> you are comparing apples to oranges.  Comparision of algorithms
> should use the same data structures, unless you're asking for a
> comparision of "idiomatic" implementations.



Yes, you're right. However then I'd like to ask what would suit my needs better
Data.Vector, Data.Array or something other.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] haskell platform questions

2010-03-21 Thread Gregory Collins
Warren Harris  writes:

> I downloaded the new haskell-platform-2010.1.0.0-i386.dmg today... ran the
> uninstaller, ghc installer and the platform installer. When I run  ghci, it
> seems to work fine, but when I try cabal, I get this crash:
>
> $ cabal --version
> dyld: unknown required load command 0x8022
> Trace/BPT trap
>
> Any suggestions? (I'm on 10.5.8). Maybe I'll try the macport install process
> instead.

Is anyone else still on Leopard who can test this? I am worried that the
binaries (which were linked on Snow Leopard) are not working on Leopard.

G
-- 
Gregory Collins 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] haskell platform questions

2010-03-21 Thread Warren Harris
I downloaded the new haskell-platform-2010.1.0.0-i386.dmg today... ran  
the uninstaller, ghc installer and the platform installer. When I run  
ghci, it seems to work fine, but when I try cabal, I get this crash:


$ cabal --version
dyld: unknown required load command 0x8022
Trace/BPT trap

Any suggestions? (I'm on 10.5.8). Maybe I'll try the macport install  
process instead.


Thanks for your help,

Warren

On Mar 18, 2010, at 9:26 AM, John Velman wrote:


I'm also on Mac Leopard.  I tried installing ghc 6.12 with Haskell
Platform 2009.2.9.2-i386.dmg (ghc 6.10.4) for some reason, and ran  
into
a bunch of problems (problems to me, anyway).  I ended up  
uninstalling 6.12

and reinstalling haskell platform.  Uninstall is easy, there is an
uninstaller script in /Library/Frameworks/GHC.framework/Tools.
(strangely, not in ..Frameworks/HaskellPaltform.framework).

I'm still using Leopard, but would like to move to Snow Leopard once  
I get
a few things out of the way.  But I see that there are (or were)  
some tricks in

getting ghc to work on OS X 10.6, apparently.  These seem to be well
documented, but, I'd rather spend the time on my own projects.

Best,

John V.



On Wed, Mar 17, 2010 at 09:07:03PM -0700, Warren Harris wrote:
I installed haskell platform some time ago, and now I'm wondering  
what

version I have. How do I find out?

Also, when the new one comes along on the 21st, is there a way to  
upgrade?
Or if I must first uninstall the one I have now, how do I uninstall  
it?


Is it recommended to periodically upgrade packages that came with the
platform (cabal upgrade), or is it recommended that they be left  
alone to
avoid dependency incompatibilities. Similar question for ghc itself  
--

can/should it be upgraded in the context of haskell platform?  (I was
hoping to try Leksah, but it dies without ghc 6.12.1. I seem to have
6.10.4.)

Apologies in advance if this is all documented somewhere, but I  
couldn't
find it on the haskell platform site/trac. BTW, I'm on Mac/Leopard  
-- love

the fact that it didn't take hours to build everything!

Warren
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Occurs check error, help!

2010-03-21 Thread Ivan Miljenovic
On 22 March 2010 14:52, adamtheturtle  wrote:
> So sorry to keep on going on about this but I have been set to start with
> "shuffle :: Int -> [a] -> [a]" so I have to do that and can't use the given 
> code
> and I
> really don't know where to put (Eq a)

First of all, do a tutorial or something rather than blindly setting
out to code.

Secondly, if you have to use that type signature, then you're doing it
the wrong way since you can't use that type signature with your code.

Thirdly, if you have been "set to start with ...", then this sounds
like homework.  As such, you really should have stated this.  For more
information, see the Homework Help policy:
http://haskell.org/haskellwiki/Homework_help (and the humorous
version: http://haskell.org/haskellwiki/Humor/Homework ).


-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Occurs check error, help!

2010-03-21 Thread adamtheturtle
Ivan Miljenovic  gmail.com> writes:

> 
> Since my answer before to your question obviously wasn't clear enough,
> let me highlight the lines of the error message that summarise what
> you have to do:
> 
> On 22 March 2010 14:31, adamtheturtle  hotmail.com>
wrote:
> >    Possible fix:
> >      add (Eq a) to the context of the type signature for `shuffle'
> 
> Alternatively, use the random-shuffle package rather than coding your own.
> 


So sorry to keep on going on about this but I have been set to start with
"shuffle :: Int -> [a] -> [a]" so I have to do that and can't use the given code
and I 
really don't know where to put (Eq a)

Thank you so much for replying :)



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Occurs check error, help!

2010-03-21 Thread Ivan Miljenovic
Since my answer before to your question obviously wasn't clear enough,
let me highlight the lines of the error message that summarise what
you have to do:

On 22 March 2010 14:31, adamtheturtle  wrote:
>    Possible fix:
>      add (Eq a) to the context of the type signature for `shuffle'

Alternatively, use the random-shuffle package rather than coding your own.

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Occurs check error, help!

2010-03-21 Thread David Menendez
On Sun, Mar 21, 2010 at 11:31 PM, adamtheturtle  wrote:
> So I have the code
>
> shuffle :: Int -> [a] -> [a]
> shuffle i [] = []
> shuffle i cards = (cards!!i) : shuffle (fst pair) (delete (cards!!i) cards)
>    where pair = randomR (0, 51) (mkStdGen 42)
>
> and it doesn't work, am I missing something?

Are you familiar with class constraints? Try looking at the type of
delete. (Use ":type" at the ghci prompt.)

-- 
Dave Menendez 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Occurs check error, help!

2010-03-21 Thread adamtheturtle
So I have the code 

shuffle :: Int -> [a] -> [a]
shuffle i [] = []
shuffle i cards = (cards!!i) : shuffle (fst pair) (delete (cards!!i) cards)
where pair = randomR (0, 51) (mkStdGen 42)

and it doesn't work, am I missing something?

Cards.hs:39:51:
Could not deduce (Eq a) from the context ()
  arising from a use of `delete' at Cards.hs:39:51-73
Possible fix:
  add (Eq a) to the context of the type signature for `shuffle'
In the second argument of `shuffle', namely
`(delete (cards !! i) cards)'
In the second argument of `(:)', namely
`shuffle (fst pair) (delete (cards !! i) cards)'
In the expression:
  (cards !! i) : shuffle (fst pair) (delete (cards !! i) cards)
Failed, modules loaded: none.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Occurs check error, help!

2010-03-21 Thread Ivan Miljenovic
On 22 March 2010 13:49, adamtheturtle  wrote:
> Just tried the code
> shuffle :: Int -> [a] -> [a]
> shuffle i [] = []
> shuffle i cards = [(cards!!i) : shuffle (fst pair) (delete (cards!!i)
>    cards)]
>        where pair = randomR (0, 51) (mkStdGen 42)
>
> and I get:
>
> Could not deduce (Eq a) from the context ()
>      arising from a use of `delete' at Cards.hs:(23,51)-(24,8)
>    Possible fix:
>      add (Eq a) to the context of the type signature for `shuffle'
>    In the second argument of `shuffle', namely
>        `(delete (cards !! i) cards)'
>    In the second argument of `(:)', namely
>        `shuffle (fst pair) (delete (cards !! i) cards)'
>    In the expression:
>          (cards !! i) : shuffle (fst pair) (delete (cards !! i) cards)
> Failed, modules loaded: none.
>
>
> Any ideas?

Yes: do what it says!

Hint: http://hackage.haskell.org/package/random-shuffle


-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Occurs check error, help!

2010-03-21 Thread adamtheturtle
boblettoj  msn.com> writes:

> 
> 
> Haha, much better now!
> Thanks for all your help, it's working great!
>
>

Just tried the code
shuffle :: Int -> [a] -> [a]
shuffle i [] = []
shuffle i cards = [(cards!!i) : shuffle (fst pair) (delete (cards!!i)
cards)]
where pair = randomR (0, 51) (mkStdGen 42)

and I get:

Could not deduce (Eq a) from the context ()
  arising from a use of `delete' at Cards.hs:(23,51)-(24,8)
Possible fix:
  add (Eq a) to the context of the type signature for `shuffle'
In the second argument of `shuffle', namely
`(delete (cards !! i) cards)'
In the second argument of `(:)', namely
`shuffle (fst pair) (delete (cards !! i) cards)'
In the expression:
  (cards !! i) : shuffle (fst pair) (delete (cards !! i) cards)
Failed, modules loaded: none.


Any ideas?



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Bubble sort algorithm implementations (Haskell vs. C)

2010-03-21 Thread Felipe Lessa
On Mon, Mar 22, 2010 at 01:08:39AM +, kingping wrote:
> Here's my C implementation:
> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=24191#a24191

I don't know how much difference in time there would be, but you
should use lists in C and/or mutable arrays in Haskell, otherwise
you are comparing apples to oranges.  Comparision of algorithms
should use the same data structures, unless you're asking for a
comparision of "idiomatic" implementations.

Cheers,

--
Felipe.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Bubble sort algorithm implementations (Haskell vs. C)

2010-03-21 Thread kingping
Felipe Lessa  gmail.com> writes:

> 
> On Sun, Mar 21, 2010 at 03:39:08PM +1000, Yasir Arsanukaev wrote:
> > I'm interested not in particular algorithm performance but rather in
> > performance of its implementations in various languages.
> 
> Is your C program using lists or arrays?  These are different
> algorithms.
> 
> --
> Felipe.
> 

Here's my C implementation:
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=24191#a24191

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Bubble sort algorithm implementations (Haskell vs. C)

2010-03-21 Thread Felipe Lessa
On Sun, Mar 21, 2010 at 03:39:08PM +1000, Yasir Arsanukaev wrote:
> I'm interested not in particular algorithm performance but rather in
> performance of its implementations in various languages.

Is your C program using lists or arrays?  These are different
algorithms.

--
Felipe.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Google summer of code idea.

2010-03-21 Thread Don Stewart
mujtaba.boori:
> Hello 
> 
> I would like to discuss my idea for google summer of code.  I'm an active
> Haskell programmer . I have read the idea list . I think Improve Cabal's test
> support really suit my ability of haskell. I would like to give me advice 
> about
> my idea . and how to improve my proposal . Thank you.

Here is some advice on how to propose a project to haskell.org:


http://donsbot.wordpress.com/2010/03/13/so-you-want-to-hack-haskell-for-the-google-summer-of-code/

Try to show that you have the Haskell skills, can work in the community,
and your proposed work will bring value.

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Google summer of code idea.

2010-03-21 Thread Mujtaba Boori
Hello

I would like to discuss my idea for google summer of code.  I'm an active
Haskell programmer . I have read the idea list . I think Improve Cabal's
test support really suit my ability of haskell. I would like to give me
advice about my idea . and how to improve my proposal . Thank you.

-- 
Mujtaba Ali Alboori
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: Salvia-1.0.0

2010-03-21 Thread Carter Schonwald
apparently sometimes even though cabal can figure out the dependencies for a
package you want, it gets confused (or something) when it needs to figure
out the "transitive" dependencies (that which needs to be installed for the
direct dependencies to also install). So  try doing a cabal install of that
version of template  haskell with the explicit version
cabal install template-haskell-2.4.0.0
that should solve it

On Sun, Mar 21, 2010 at 7:57 PM, Bernie Pope  wrote:

> On 22 March 2010 03:05, Sebastiaan Visser  wrote:
>
> > Straight from Zurihac: I'm very pleased to announce the 1.0.0 release of
> the Salvia web server.
> >
> > Salvia is a feature rich web server and web application framework that
> can be used to write dynamic websites in Haskell. From the lower level
> protocol code up to the high level application code, everything is written
> as a Salvia handler. This approach makes the framework extremely modular and
> extensible.
> >
> > To do a full install first run `cabal update' followed by `cabal install
> salvia-demo'. Now you can run the salvia-demo command and point your browser
> to http://localhost:8080/ .
>
> Hi Sebastiaan,
>
> I was looking forward to a new version of Salvia.
>
> Do you have minumum requirements for GHC? I tried to 'cabal install
> salvia-demo', but with no luck:
>
> cabal install salvia-demo
> Resolving dependencies...
> cabal: cannot configure syb-with-class-0.6.1. It requires template-haskell
> ==2.4.*
> For the dependency on template-haskell ==2.4.* there are these packages:
> template-haskell-2.4.0.0. However none of them are available.
> template-haskell-2.4.0.0 was excluded because template-haskell-2.3.0.1 was
> selected instead
> template-haskell-2.4.0.0 was excluded because ghc-6.10.4 requires
> template-haskell ==2.3.0.1
>
> Cheers,
> Bernie.
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: Salvia-1.0.0

2010-03-21 Thread Ivan Miljenovic
On 22 March 2010 10:57, Bernie Pope  wrote:
> Do you have minumum requirements for GHC? I tried to 'cabal install
> salvia-demo', but with no luck:

Looking at the dependencies listed, they claim that GHC should work
with >= 6.10.1.

> cabal install salvia-demo
> Resolving dependencies...
> cabal: cannot configure syb-with-class-0.6.1. It requires template-haskell
> ==2.4.*
> For the dependency on template-haskell ==2.4.* there are these packages:
> template-haskell-2.4.0.0. However none of them are available.
> template-haskell-2.4.0.0 was excluded because template-haskell-2.3.0.1 was
> selected instead
> template-haskell-2.4.0.0 was excluded because ghc-6.10.4 requires
> template-haskell ==2.3.0.1

Hmmm a quick look through the dependencies couldn't reveal what
was pulling in syb-with-class; maybe if you just install
syb-with-class-0.6 first and it will use that instead?

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: Salvia-1.0.0

2010-03-21 Thread Bernie Pope
On 22 March 2010 03:05, Sebastiaan Visser  wrote:

> Straight from Zurihac: I'm very pleased to announce the 1.0.0 release of the 
> Salvia web server.
>
> Salvia is a feature rich web server and web application framework that can be 
> used to write dynamic websites in Haskell. From the lower level protocol code 
> up to the high level application code, everything is written as a Salvia 
> handler. This approach makes the framework extremely modular and extensible.
>
> To do a full install first run `cabal update' followed by `cabal install 
> salvia-demo'. Now you can run the salvia-demo command and point your browser 
> to http://localhost:8080/ .

Hi Sebastiaan,

I was looking forward to a new version of Salvia.

Do you have minumum requirements for GHC? I tried to 'cabal install
salvia-demo', but with no luck:

cabal install salvia-demo
Resolving dependencies...
cabal: cannot configure syb-with-class-0.6.1. It requires template-haskell
==2.4.*
For the dependency on template-haskell ==2.4.* there are these packages:
template-haskell-2.4.0.0. However none of them are available.
template-haskell-2.4.0.0 was excluded because template-haskell-2.3.0.1 was
selected instead
template-haskell-2.4.0.0 was excluded because ghc-6.10.4 requires
template-haskell ==2.3.0.1

Cheers,
Bernie.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Strange typing?

2010-03-21 Thread Christoph Bier
Hi,

> Only think I can think of is having the constructors, as seperate data
> types, introducing new type classes to group every possible subset of
> [X,Y,Z] and [A,B,C,D] and use those type classes when defining the
> functions. 

Wouldn't it be possible to use Either?
You make the constructors seperate data types and then have something
like

> func1 :: Either X Y -> Either B C

When you need more then two alternatives you could define similar
datatypes like

> OneOfThree x y z = OOTFirst x | OOTSecond y | OOTThird z

or something like

> {-# LANGUAGE TypeOperators #-}
> data Or x y = First x | Second y deriving (Show)
> infixl 5 `Or`

> func :: Int `Or` String `Or` Integer -> String `Or` Integer

but then pattern matching becomes ugly.

Christoph


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Data.Number.BigFloat/Fixed

2010-03-21 Thread Ivan Miljenovic
On 22 March 2010 08:33, Brandon S. Allbery KF8NH  wrote:
> On Mar 21, 2010, at 17:31 , Ivan Lazar Miljenovic wrote:
>>
>> I'm sorry, but is there a question in there?
>> H.  writes:
>>>
>>> (7e-3 :: BigFloat Prec50) < (6e-4 :: BigFloat Prec50)
>>> False
>
> 0.007 < 0.0006?

Oh, wait; that returns False which is correct, but 0.007 < 0.0008
returns True which is incorrect.  Which just goes to show I shouldn't
skim emails that early in the morning...

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Data.Number.BigFloat/Fixed

2010-03-21 Thread H .
Antoine Latter  gmail.com> writes:
> On Sun, Mar 21, 2010 at 4:49 PM, H.  hotmail.com> wrote:
> >
> >
> > 7e-3 < 8e-4
> > The result should be False, but it's True.
> >
> > Basically I don't know where to report this bug.
> >
> 
> Sending to the maintainer of the package, as listed on hackage.
> 
> Antoine


This was my first idea as well, but there's no email:
http://hackage.haskell.org/package/numbers


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Data.Number.BigFloat/Fixed

2010-03-21 Thread Antoine Latter
On Sun, Mar 21, 2010 at 4:49 PM, H.  wrote:
> Ivan Lazar Miljenovic  gmail.com> writes:
>
>>
>> I'm sorry, but is there a question in there?
>>
>> H.  hotmail.com> writes:
>> > (7e-3 :: BigFloat Prec50) < (6e-4 :: BigFloat Prec50)
>> > False
>> >
>> > (7e-3 :: BigFloat Prec50) < (8e-4 :: BigFloat Prec50)
>> > True
>>
>
>
> 7e-3 < 8e-4
> The result should be False, but it's True.
>
> Basically I don't know where to report this bug.
>

Sending to the maintainer of the package, as listed on hackage.

Antoine
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Data.Number.BigFloat/Fixed

2010-03-21 Thread H .
Ivan Lazar Miljenovic  gmail.com> writes:

> 
> I'm sorry, but is there a question in there?
> 
> H.  hotmail.com> writes:
> > (7e-3 :: BigFloat Prec50) < (6e-4 :: BigFloat Prec50)
> > False
> >
> > (7e-3 :: BigFloat Prec50) < (8e-4 :: BigFloat Prec50)
> > True
> 


7e-3 < 8e-4
The result should be False, but it's True.

Basically I don't know where to report this bug.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Data.Number.BigFloat/Fixed

2010-03-21 Thread Brandon S. Allbery KF8NH

On Mar 21, 2010, at 17:31 , Ivan Lazar Miljenovic wrote:

I'm sorry, but is there a question in there?
H.  writes:

(7e-3 :: BigFloat Prec50) < (6e-4 :: BigFloat Prec50)
False


0.007 < 0.0006?

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Data.Number.BigFloat/Fixed

2010-03-21 Thread Ivan Lazar Miljenovic
I'm sorry, but is there a question in there?

H.  writes:
> (7e-3 :: BigFloat Prec50) < (6e-4 :: BigFloat Prec50)
> False
>
> (7e-3 :: BigFloat Prec50) < (8e-4 :: BigFloat Prec50)
> True
>
> where in the sourecode is written:
> data BigFloat e = BF (Fixed e) Integer deriving (Eq, Ord)
>
> and
> import Data.Ratio
> newtype Fixed e = F Rational deriving (Eq, Ord, Enum, Real, RealFrac)

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to set a breakpoint in GHCi

2010-03-21 Thread Gracjan Polak

Hi all,

Tried to use :break today, without success:

guestbook-session-bug>ghci -DMIN_VERSION_template_haskell(a,b,c)=1 
-isrc Main -i../happstack/happstack-ixset/src
GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
...
...
[10 of 13] Compiling Happstack.Data.IxSet (
..\happstack\happstack-ixset\src\Happstack\Data\IxSet.hs, interpreted )
...
...
*Main> :m +Happstack.Data.IxSet
*Main Happstack.Data.IxSet> :bre getOrd
No breakpoints found at that location.
*Main Happstack.Data.IxSet>

What now?

-- 
Gracjan


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Data.Number.BigFloat/Fixed

2010-03-21 Thread H .
Hello,

With ghc-6.10.4 the following results are produced with numbers 2009.8.9:

(7e-3 :: BigFloat Prec50) < (6e-4 :: BigFloat Prec50)
False

(7e-3 :: BigFloat Prec50) < (8e-4 :: BigFloat Prec50)
True

where in the sourecode is written:
data BigFloat e = BF (Fixed e) Integer deriving (Eq, Ord)

and
import Data.Ratio
newtype Fixed e = F Rational deriving (Eq, Ord, Enum, Real, RealFrac)

H.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] developing against privately patched libraries, and cabal

2010-03-21 Thread Dougal Stanton
On Sun, Mar 21, 2010 at 5:15 PM, Leon Smith  wrote:
> As somebody who's hacked on cabal-install a bit  (but don't have a
> worthwhile patch to contribute (yet?)),  I can tell you that versions
> support a "tag" structure,  at least internally,  but I haven't seen a
> non-empty tags field and don't know how to make the tags field
> non-empty.   For that I'd have to go source-code diving again.
>
> http://www.haskell.org/ghc/docs/latest/html/libraries/Cabal-1.8.0.2/Distribution-Version.html

That seems just the kind of thing that could be co-opted to my
purposes, but as you say the cabal file format doesn't seem to mention
how I'd go about setting my tag field. Trying "Tag: dougal1" didn't
work, as I suspected ;-)

In the mean time I will try Stephen Tetley's approach of renaming the
package instead of the version.

Cheers,


D

-- 
Dougal Stanton
dou...@dougalstanton.net // http://www.dougalstanton.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] developing against privately patched libraries, and cabal

2010-03-21 Thread Leon Smith
As somebody who's hacked on cabal-install a bit  (but don't have a
worthwhile patch to contribute (yet?)),  I can tell you that versions
support a "tag" structure,  at least internally,  but I haven't seen a
non-empty tags field and don't know how to make the tags field
non-empty.   For that I'd have to go source-code diving again.

http://www.haskell.org/ghc/docs/latest/html/libraries/Cabal-1.8.0.2/Distribution-Version.html

Best,
Leon

On Sun, Mar 21, 2010 at 10:58 AM, Dougal Stanton
 wrote:
> If you're making local changes against a library you don't own (with
> the ultimate intention of sending those changes back upstream to the
> library maintainer) it makes sense change the version number to avoid
> clashes with the canonical version of the library.
>
> Of course, it's easy to lose track and end up publishing your own
> program against a non-existent (outside your hard disk) version of the
> library. I'd like to make it very obvious, both in mypogram.cabal and
> library.cabal that one is a patched copy and the other has to be
> compiled against a patched copy.
>
> Does cabal provide any way of marking a version private? I thought
> initially to just mark the version field in the patched library as
> X.y-dougal and enforce my program to compile against that, but it
> doesn't seem to recognise the -dougal suffix there.
>
> Thoughts?
>
> D
>
> --
> Dougal Stanton
> dou...@dougalstanton.net // http://www.dougalstanton.net
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] developing against privately patched libraries, and cabal

2010-03-21 Thread Stephen Tetley
Hi Dougal

Could you prefix or suffix the forked package name in the cabal file
instead, then choose the appropriate one when you use GHC with the
-package-name flag?


Best wishes

Stephen
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANN: Salvia-1.0.0

2010-03-21 Thread Sebastiaan Visser
Hi all,

Straight from Zurihac: I'm very pleased to announce the 1.0.0 release of the 
Salvia web server.

Salvia is a feature rich web server and web application framework that can be 
used to write dynamic websites in Haskell. From the lower level protocol code 
up to the high level application code, everything is written as a Salvia 
handler. This approach makes the framework extremely modular and extensible.

This release include the following stack of packages:

  * salvia-protocol: Protocol stack containing URI, HTTP, Cookie and Mime.
  * salvia: Basic server interface and implementation.
  * salvia-extras: Additional server handlers and back end implementation.
  * salvia-sessions: Session and user management support.
  * salvia-websocket: Cutting edge HTML5 web socket support.
  * salvia-demo: Demo servers showing how to use Salvia.

All the code is on Hackage[1] and the source repositories can be found on 
GitHub[2].

Most of the basic ideas of the previous Salvia release are still in these 
package, but all the code has been cleaned up considerably. There is now a very 
strong separation between interface and implementation making it more easy to 
plug-in new back-ends for your web application.

To do a full install first run `cabal update' followed by `cabal install 
salvia-demo'. Now you can run the salvia-demo command and point your browser to 
http://localhost:8080/ .

Thanks to the people that helped me with coding, suggestions and bug-reports. 
Any comments/suggestions are welcome!

Have fun,

--

Sebatiaan Visser

[1] http://hackage.haskell.org/package/salvia (-protocol, -demo, etc)
[2] http://github.com/sebastiaanvisser/salvia (-protocol, -demo, etc)


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: fixed-list -- A fixed length list library

2010-03-21 Thread Job Vranish
Is there anything wrong with increasing the context stack? That's what I do
when I run into an overflow, and so far I haven't had any problems with it.

Generally my uses of FixedList involve relatively short lists (vectors and
such) so it usually isn't a problem.

I could implement a more sophisticated way to keep track of the list lengths
that doesn't have this problem, but I really like the simplicity of the
current implementation.

- Job

On Sun, Mar 21, 2010 at 2:37 AM, Casey McCann wrote:

> Job Vranish  wrote:
> > Its main advantages are:
> >  Very easy to use.
> >  Almost entirely Haskell98 (the non Haskell98 pieces are not critical,
> just
> > nice)
> >  The datatype is a member of  Foldable, Traverable, Applicative, Monad,
> > etc...
> >  Then length of the list is encoded in the type in a natural way.
>
> Unfortunately, it's very easy to get a context reduction stack
> overflow from GHC this way, which makes using such datatypes awkward
> for anything but very short lists. Explicit type annotations will
> often make things work, but at that point the type class isn't helping
> you anyway. For example, assuming the default stack size:
>
> import Data.FixedList
>
> fixed18 :: FixedList18 Int
> fixed18 = fromFoldable' [1..] -- this works
>
> fixed20 = 20 :. 20 :. fixed18 -- this works
>
> fixed22 :: FixedList22 Int
> fixed22 = 22 :. 22 :. fixed20 -- this only works with a type annotation
>
> show18 = show fixed18 -- this works
>
> -- this doesn't work:
> -- show20 = show fixed20
>
> show20' :: FixedList20 Int -> String
> show20' list20 = show list20
>
> show20 = show20' fixed20 -- this does work
>
> Using head and tail on longer lists fails likewise. I expect there's
> some way to make it work without simply increasing the stack depth,
> but I'm not sure how. Any thoughts?
>
> - C.
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] developing against privately patched libraries, and cabal

2010-03-21 Thread Dougal Stanton
If you're making local changes against a library you don't own (with
the ultimate intention of sending those changes back upstream to the
library maintainer) it makes sense change the version number to avoid
clashes with the canonical version of the library.

Of course, it's easy to lose track and end up publishing your own
program against a non-existent (outside your hard disk) version of the
library. I'd like to make it very obvious, both in mypogram.cabal and
library.cabal that one is a patched copy and the other has to be
compiled against a patched copy.

Does cabal provide any way of marking a version private? I thought
initially to just mark the version field in the patched library as
X.y-dougal and enforce my program to compile against that, but it
doesn't seem to recognise the -dougal suffix there.

Thoughts?

D

-- 
Dougal Stanton
dou...@dougalstanton.net // http://www.dougalstanton.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Parallel Pi

2010-03-21 Thread Daniel Fischer
-Ursprüngliche Nachricht-
Von: Simon Marlow 
Gesendet: 19.03.2010 09:24:12
An: Daniel Fischer 
Betreff: Re: Parallel Pi

>On 18/03/10 22:52, Daniel Fischer wrote:
>> Am Donnerstag 18 März 2010 22:44:55 schrieb Simon Marlow:
>>> On 17/03/10 21:30, Daniel Fischer wrote:
>>> It works for me (GHC 6.12.1):
>>>
>>> SPARKS: 1 (1 converted, 0 pruned)
>>>
>>> INIT  time0.00s  (  0.00s elapsed)
>>> MUT   time9.05s  (  4.54s elapsed)
>>> GCtime0.12s  (  0.09s elapsed)
>>> EXIT  time0.00s  (  0.01s elapsed)
>>> Total time9.12s  (  4.63s elapsed)
>>>
>>> wall-clock speedup of 1.93 on 2 cores.
>>
>> Is that Artyom's original code or with the pseq'ed length?
>
>Your fixed version.

Good. So I can at least continue to believe I have a rough idea of how GHC 
behaves.

>
>> And, with -N2, I also have a productivity of 193.5%, but the elapsed time
>> is larger than the elapsed time for -N1. How long does it take with -N1 for
>> you?
>
>The 1.93 speedup was compared to the time for -N1 (8.98s in my case).
>
>>> What hardware are you using there?
>>
>> 3.06GHz Pentium 4, 2 cores.
>> I have mixed results with parallelism, some programmes get a speed-up of
>> nearly a factor 2 (wall-clock time), others 1.4, 1.5 or so, yet others take
>> about the same wall-clock time as the single threaded programme, some -
>> like this - take longer despite using both cores intensively.
>
>I suspect it's something specific to that processor, probably 
>cache-related.  Perhaps we've managed to put some data frequently 
>accessed by both CPUs on the same cache line.  I'd have to do some 
>detailed profiling on that processor to find out though.  If you're have 
>the time and inclination, install oprofile and look for things like 
>"memory ordering stalls".
>

It seems that I've just been fooled by /proc/cpuinfo listing it as two and 
having something like 190% cpu usage in top/time.
Being oblivious of almost everything hardware-related, I naively took it at 
face value.
In fact it's probably just one hyperthreaded CPU, so since the two threads here 
do exactly the same type of work, it's natural then that it doesn't give a 
speed-up.

>>> Have you tried changing any GC settings?
>>
>> I've played around a little with -qg and -qb and -C, but that showed little
>> influence. Any tips what else might be worth a try?
>
>-A would be the other thing to try.
>
>Cheers,
>   Simon
>
>>>
>>> Cheers,
>>> Simon
>>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Takusen sqlite3 insert is very slow

2010-03-21 Thread Leon Smith
Using PostgreSQL on my computer,  your code executes in 3.5 seconds
with GHCi,  while compiled it executes in 16.2 seconds!   Clearly
something is wrong,  although I don't yet know enough about Takusen
enough to be able to say what.

I tried hoisting the preparation of the statement out of the loop,
however,  Takusen throws an error after the first insertion.  However,
 the insertion was apparently successful,  as a single row shows up in
the table afterwards.   Here's sample code and a sample shell session:

Best,
Leon

> import Database.PostgreSQL.Enumerator
> import Database.Enumerator
> import Control.Monad(forM_)

> main = do
>   withSession
> (connect [ CAhost "localhost"
>  , CAport "5432"
>  , CAuser "takusen"
>  , CApassword "takusen"
>  , CAdbname "test"  ])
> $ do
> execDDL (sql "create table x (y text)")
> let query = sql "insert into x (y) values (?)"
> stmt  = prepareQuery "testinsert" query [bindType (0::Int)]
> forM_ ([1..1] :: [Int]) $ \x -> do
>  withPreparedStatement stmt $ \pstmt -> do
>withBoundStatement pstmt [bindP x] $ \bstmt -> do
>  execDML bstmt
>  return ()

$ psql test
psql (8.4.2)
Type "help" for help.

test=# select * from x;
ERROR:  relation "x" does not exist
LINE 1: select * from x;
  ^
test=# \q
$ ghci Tak.lhs
GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
[1 of 1] Compiling Main ( Tak.lhs, interpreted )
Ok, modules loaded: Main.
(0.09 secs, 40984568 bytes)
*Main> main
Loading package mtl-1.1.0.2 ... linking ... done.
Loading package old-locale-1.0.0.2 ... linking ... done.
Loading package old-time-1.0.0.3 ... linking ... done.
Loading package time-1.1.4 ... linking ... done.
Loading package Takusen-0.8.5 ... linking ... done.
*** Exception: DBError ("","") 1 ""
*Main> :q
Leaving GHCi.
$ psql test
psql (8.4.2)
Type "help" for help.

test=# select * from x;
 y
---
 1
(1 row)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: fixed-list -- A fixed length list library

2010-03-21 Thread Khudyakov Alexey
В сообщении от 21 марта 2010 09:37:26 Casey McCann написал:
> Using head and tail on longer lists fails likewise. I expect there's
> some way to make it work without simply increasing the stack depth,
> but I'm not sure how. Any thoughts?
> 
It's possible to use binary encoding for natural numbers. 2^20 is pretty big 
number. 

There is article on haskell wiki[1]. And implementation by Oleg Kiselyov[2].

http://www.haskell.org/haskellwiki/Type_arithmetic
http://article.gmane.org/gmane.comp.lang.haskell.general/13223
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Occurs check error, help!

2010-03-21 Thread boblettoj

Haha, much better now!
Thanks for all your help, it's working great!
-- 
View this message in context: 
http://old.nabble.com/Occurs-check-error%2C-help%21-tp27966341p27975606.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Occurs check error, help!

2010-03-21 Thread TeXitoi
boblettoj  writes:

> newStdGen results in IO Ints whereas i need normal Ints and it seems theres
> no easy way to convert them without a lot more knowledge of haskell. I have
> tried using a where clause instead of using do but this is giving me the
> occurs check error again!
> 
> --function used to shuffle cards 
> --list equals random member of array plus the rest of the array
> --i is randomly generated from range of length equal to that of cards.
> shuffle :: Int -> [a] -> [a]
> shuffle i [] = []
> shuffle i cards = [(cards!!i) : shuffle (fst pair) (delete (cards!!i) cards)]
^ ^

You are trying to do a one element list of list of card. so, the
result of this line should be a [[b]] = [a] => a = [b]. Inside this
list, we cons (cards !! i (type b) with shuffle (type [a] = [[b]]).

problem : we try to conssomething of type b with something of type [a]
= [[b]], but

ghci> :t (:)
(:) :: a -> [a] -> [a]

so b should be [b]. And so on.

Just remove the brackets.

>   where pair = randomR (0, 51) (mkStdGen 42)

It makes me remember jokes :
 - http://xkcd.com/221/
 - http://www.random.org/analysis/dilbert.jpg

> and the error:
> cards.hs:30:0:
> Occurs check: cannot construct the infinite type: a = [a]
> When generalising the type(s) for `shuffle'
> Failed, modules loaded: none.
> 
> hmmm...

-- 
Guillaume Pinot   http://www.irccyn.ec-nantes.fr/~pinot/

« Les grandes personnes ne comprennent jamais rien toutes seules, et
c'est fatigant, pour les enfants, de toujours leur donner des
explications... » -- Antoine de Saint-Exupéry, Le Petit Prince

()  ASCII ribbon campaign  -- Against HTML e-mail
/\  http://www.asciiribbon.org -- Against proprietary attachments

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANN: regular-web 0.1 | generic web programming in Haskell

2010-03-21 Thread Chris Eidhof
From the ZuriHac hackathon, I am happy to announce the first release of the 
regular-web package [1]. The package contains functions for generic web 
programming: generating HTML, JSON and Formlets. It is based on the regular 
generic programming library [2].

Generic HTML and forms are often not sufficient for real purposes, so we 
encourage the use of regular-web in combination with the fclabels package [3].  
There is an example in the documentation of the Formlets module. Furthermore, 
there is a slightly larger example [4] on github that shows off some more 
features of the package.

This is a preliminary release and the API will probably change. I am interested 
to see what other people think of this. So please send me your comments or fork 
the project on github.  

[1]: http://hackage.haskell.org/package/regular-web
[2]: http://hackage.haskell.org/package/regular
[3]: http://hackage.haskell.org/package/fclabels
[4]: http://github.com/chriseidhof/regular-web/blob/master/Example.lhs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Bubble sort algorithm implementations (Haskell vs. C)

2010-03-21 Thread Mark Lentczner
You might express the algorithm more directly in Haskell, without the reverse 
calls:

bubblesort :: (Ord a) => [a] -> [a]
bubblesort []  = []
bubblesort (x0:xs) = case bubble x0 xs of
(xs', True)  -> bubblesort xs'
(xs', False) -> xs'
where bubble x1 (x2:xs) | x1 <= x2  = merge x1 False $ bubble x2 xs
| otherwise = merge x2 True  $ bubble x1 xs
  bubble x1 []  = ([x1], False)
  merge x s (xs, s') = (x:xs, s || s')

Here, the local bubble function does the job of bubbling a value through, and 
the merge function handles both rebuilding the new, bubbled list, and the swap 
flag. The case expression in bubblesort is a direct expression in Haskell of 
"bubble through the list once, and if we swapped anything, do it again".

This version clocks in at about 35% faster than your original.

- Mark

P.S.: Code and driver Main files can be found here:
http://bitbucket.org/mtnviewmark/haskell-playground/src/tip/cafe/


Mark Lentczner
http://www.ozonehouse.com/mark/
IRC: mtnviewmark



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe