Re: [Haskell-cafe] How can I avoid buffered reads?

2012-11-29 Thread Leon Smith
Well,  I took Bardur's suggestion and avoided all the complexities of GHC's
IO stack and simply used System.Posix.IO and Foreign.This appears to
work,  but for better or worse,   it is using blocking calls to the read
system call and is not integrated with GHC's IO manager.   This shouldn't
be an issue for my purposes,  but I suppose it's worth pointing out.

{-# LANGUAGE BangPatterns, ViewPatterns #-}

import   Control.Applicative
import   Data.Bits
import   Data.Word(Word64)
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
import   Data.ByteString.Internal (c2w)
import   Control.Exception
import   System.Posix.IO
import   Foreign
import qualified System.IO  as IO
import qualified Data.Binary.Getas Get

showHex :: Word64 - S.ByteString
showHex n = s
  where
(!s,_) = S.unfoldrN 16 f n

f n = Just (char (n `shiftR` 60), n `shiftL` 4)

char (fromIntegral - i)
  | i  10= (c2w '0' -  0) + i
  | otherwise = (c2w 'a' - 10) + i

twoRandomWord64s :: IO (Word64,Word64)
twoRandomWord64s = bracket openRd closeRd readRd
  where
openRd = openFd /dev/urandom ReadOnly Nothing defaultFileFlags {
noctty = True }
readRd = \fd - allocaBytes 16 $ \ptr - do
fdReadAll fd ptr 16
x - peek (castPtr ptr)
y - peek (castPtr ptr `plusPtr` 8)
return (x,y)
closeRd = closeFd
fdReadAll fd ptr n = do
  n' - fdReadBuf fd ptr n
  if n /= n'
  then fdReadAll fd (ptr `plusPtr` n') (n - n')
  else return ()

main = do
   (x,y) - twoRandomWord64s
   S.hPutStrLn IO.stdout (S.append (showHex x) (showHex y))


On Wed, Nov 28, 2012 at 6:05 PM, Leon Smith leon.p.sm...@gmail.com wrote:

 If you have rdrand,  there is no need to build your own PRNG on top of
 rdrand.   RdRand already incorporates one so that it can produce random
 numbers as fast as they can be requested,  and this number is continuously
 re-seeded with the on-chip entropy source.

 It would be nice to have a little more information about /dev/urandom and
 how it varies by OS and hardware,   but on Linux and FreeBSD at least it's
 supposed to be a cryptographically secure RNG that incorporates a PRNG to
 produce numbers in case you exhaust the entropy pool.

 On Wed, Nov 28, 2012 at 5:00 PM, Vincent Hanquez t...@snarc.org wrote:

 On 11/28/2012 09:31 PM, Leon Smith wrote:

 Quite possibly,  entropy does seem to be a pretty lightweight
 dependency...

 Though doesn't recent kernels use rdrand to seed /dev/urandom if it's
 available?   So /dev/urandom is the most portable source of random numbers
 on unix systems,  though rdrand does have the advantage of avoiding system
 calls,  so it certainly would be preferable, especially if you need large
 numbers of random numbers.

 There's no much information on this i think, but if you need large number
 of random numbers you should build a PRNG yourself on top of the best
 random seed you can get, and make sure you reseed your prng casually with
 more entropy bytes. Also if
 you don't have enough initial entropy, you should block.

 /dev/urandom is not the same thing on every unix system. leading to
 various assumptions broken when varying the unixes. It also varies with the
 hardware context: for example on an embedded or some virtualized platform,
 giving you really terrible entropy.

 --
 Vincent



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


Re: [Haskell-cafe] Can not use ST monad with polymorphic function

2012-11-29 Thread Dmitry Kulagin
Thank you, MigMit!

If I replace your type FoldSTVoid with:
data FoldMVoid = FoldMVoid {runFold :: Monad m = (Int - m ()) - m ()}

then everything works magically with any monad!
That is exactly what I wanted, though I still do not quite understand why
wrapping the type solves the problem

Dmitry


On Thu, Nov 29, 2012 at 12:01 AM, MigMit miguelim...@yandex.ru wrote:

 Yes, monomorphism. do binding requires your fold'' to be of some
 monomorphic type, but runST requires some polymorphism.

 If you want, you can use special type like that:

 data FoldSTVoid = FoldSTVoid {runFold :: forall a. (Int - ST a ()) - ST
 a ()}

 fold :: Monad m = (Int - m ()) - m ()
 fold f = mapM_ f [0..20]

 selectFold :: String - IO FoldSTVoid -- ((Int - m ()) - m ())
 selectFold method = do
 -- in real program I'd like to choose between
 -- different fold methods, based on some IO context
 return $ FoldSTVoid fold

 useFold :: FoldSTVoid - ST a ()
 useFold fold' = runFold fold' f
 where f _ = return () -- some trivial iterator

 main = do
 fold'' - selectFold some-method-id
 print $ runST $ useFold fold''

 On Nov 28, 2012, at 9:52 PM, Dmitry Kulagin dmitry.kula...@gmail.com
 wrote:

  Hi Cafe,
 
  I try to implement some sort of monadic fold, where traversing is
 polymorphic over monad type.
  The problem is that the code below does not compile. It works with any
 monad except for ST.
  I suspect that monomorphism is at work here, but it is unclear for me
 how to change the code to make it work with ST.
 
  fold :: Monad m = (Int - m ()) - m ()
  fold f = mapM_ f [0..20]
 
  selectFold :: Monad m = String - IO ((Int - m ()) - m ())
  selectFold method = do
  -- in real program I'd like to choose between
  -- different fold methods, based on some IO context
  return fold
 
  useFold :: Monad m = ((Int - m ()) - m ()) - m ()
  useFold fold' = fold' f
  where f _ = return () -- some trivial iterator
 
  main = do
  fold'' - selectFold some-method-id
  print $ runST $ useFold fold''
 
 
  Thank you!
  Dmitry
  ___
  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] SOX - play simple

2012-11-29 Thread Antoine Latter
The example is assuming you have an import statement like this:

import qualified Sound.Sox.Option.Format as Option

On Wed, Nov 28, 2012 at 8:48 AM, Gary Klindt gary.kli...@googlemail.com wrote:
 Dear Cafe,

 after installing the Sox library
 (cabal install sox)
 I wanted to let run a minimal example from
 http://hackage.haskell.org/packages/archive/sox/0.2.2.2/doc/html/Sound-Sox-Play.html


 module Main where

 import Sound.Sox.Play
 import Sound.Sox.Signal.List
 --import Sound.Sox.Option.Format

 import Data.Int

 main = do
 simple Sound.Sox.Signal.List.put
Option.none
11025
(iterate (1000+) (0::Data.Int.Int16))

 in this version, I get the error:
  Not in scope: `Option.none'

 So, I imported Sound.Sox.Option.Format, because there is a none with the
 right type. I also changed Option.none to none.

 Then the program compiles and I get the runtime error:
 fd:4: hClose: resource vanished (Broken pipe)


 What is wrong here?

 I appreciate your help!

 Best regards, Gary

 ___
 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] Simple GUI Form

2012-11-29 Thread Rune Harder Bak
Hi

I have some input parameters
data Input = ...
that I need the user to enter in a gui pop-up. (windows people...)
The rest of the app is not gui (or perhaps progress could be displayed
in a log-window)

What is the easiest way to make such a GUI form?

It need to compile for both Linux and Windows, so I though WxWidgets was ideal,
and I got wx[1]  0.90 to install (using wxWidgets2.8) on both windows
and linux.

Now I just need to create the form, but how do you do that?
Any clues or links to examples? I have never used wxwidgets on any
platform or done any other form of GUI before for that matters.
(apart from some Visual Basic ten years ago, and html).

I tried looking at wx examples, but I couldn't find this simple use
case explained anywhere.

I installed wx in the first place because WxGeneric[2] seemed exactly
what I needed,
but I can't get it to compile using ghc7.4.2 from haskell-platform.
Anybody got that working or have some other simple method?

Help much appreciated!

-Rune

[1] http://hackage.haskell.org/package/wx-0.13.2.3
[2] http://hackage.haskell.org/package/WxGeneric

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


Re: [Haskell-cafe] Simple GUI Form

2012-11-29 Thread Ertugrul Söylemez
Hi there Rune,

if you want to get started with declarative GUI programming in Haskell,
I really recommend taking the FRP route.  Check out the
reactive-banana-wx [1] library instead of using wxHaskell directly.  If
you manage to get wxHaskell working on Windows, then reactive-banana
will work as well.

[1]: http://www.haskell.org/haskellwiki/Reactive-banana


Greets,
Ertugrul


Rune Harder Bak r...@bak.dk wrote:

 I have some input parameters
 data Input = ...
 that I need the user to enter in a gui pop-up. (windows people...)
 The rest of the app is not gui (or perhaps progress could be displayed
 in a log-window)
 
 What is the easiest way to make such a GUI form?
 
 It need to compile for both Linux and Windows, so I though WxWidgets
 was ideal, and I got wx[1]  0.90 to install (using wxWidgets2.8) on
 both windows and linux.
 
 Now I just need to create the form, but how do you do that?
 Any clues or links to examples? I have never used wxwidgets on any
 platform or done any other form of GUI before for that matters.
 (apart from some Visual Basic ten years ago, and html).
 
 I tried looking at wx examples, but I couldn't find this simple use
 case explained anywhere.
 
 I installed wx in the first place because WxGeneric[2] seemed exactly
 what I needed,
 but I can't get it to compile using ghc7.4.2 from haskell-platform.
 Anybody got that working or have some other simple method?
 
 Help much appreciated!
 
 -Rune
 
 [1] http://hackage.haskell.org/package/wx-0.13.2.3
 [2] http://hackage.haskell.org/package/WxGeneric

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.


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


Re: [Haskell-cafe] delete http://www.haskell.org/haskellwiki/Haskell_IDE

2012-11-29 Thread Roman Beslik

Good point. Done.

On 29.11.12 06:16, Conrad Parker wrote:

#REDIRECT [[IDEs]]


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


Re: [Haskell-cafe] Simple GUI Form

2012-11-29 Thread Rune Harder Bak
I'm very interested in FRP,  but all the examples I could see was
forms with live feedback
gui like a real-time calculator.
This is a one-time form where the user fills everything in, clicks on a button,
where after the computations might take a long time, perhaps display
some console-info.
But maybe this is a good use-case for reactive-banana as well?
Do you have any good examples in this regard?

On Thu, Nov 29, 2012 at 2:37 PM, Ertugrul Söylemez e...@ertes.de wrote:
 Hi there Rune,

 if you want to get started with declarative GUI programming in Haskell,
 I really recommend taking the FRP route.  Check out the
 reactive-banana-wx [1] library instead of using wxHaskell directly.  If
 you manage to get wxHaskell working on Windows, then reactive-banana
 will work as well.

 [1]: http://www.haskell.org/haskellwiki/Reactive-banana


 Greets,
 Ertugrul


 Rune Harder Bak r...@bak.dk wrote:

 I have some input parameters
 data Input = ...
 that I need the user to enter in a gui pop-up. (windows people...)
 The rest of the app is not gui (or perhaps progress could be displayed
 in a log-window)

 What is the easiest way to make such a GUI form?

 It need to compile for both Linux and Windows, so I though WxWidgets
 was ideal, and I got wx[1]  0.90 to install (using wxWidgets2.8) on
 both windows and linux.

 Now I just need to create the form, but how do you do that?
 Any clues or links to examples? I have never used wxwidgets on any
 platform or done any other form of GUI before for that matters.
 (apart from some Visual Basic ten years ago, and html).

 I tried looking at wx examples, but I couldn't find this simple use
 case explained anywhere.

 I installed wx in the first place because WxGeneric[2] seemed exactly
 what I needed,
 but I can't get it to compile using ghc7.4.2 from haskell-platform.
 Anybody got that working or have some other simple method?

 Help much appreciated!

 -Rune

 [1] http://hackage.haskell.org/package/wx-0.13.2.3
 [2] http://hackage.haskell.org/package/WxGeneric

 --
 Not to be or to be and (not to be or to be and (not to be or to be and
 (not to be or to be and ... that is the list monad.

 ___
 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] Simple GUI Form

2012-11-29 Thread Ertugrul Söylemez
Rune Harder Bak r...@bak.dk wrote:

 I'm very interested in FRP, but all the examples I could see was forms
 with live feedback gui like a real-time calculator.
 This is a one-time form where the user fills everything in, clicks on
 a button, where after the computations might take a long time, perhaps
 display some console-info.
 But maybe this is a good use-case for reactive-banana as well?

Of course.  There is no reason to think that FRP is limited to real-time
applications with complicated interactions.


 Do you have any good examples in this regard?

Not myself, but there is a somewhat comprehensive tutorial [1] as well
as lots of examples [2] linked from the wiki.

I just want to stress the importance of the last tutorial section:  FRP
is not a concrete design pattern, but rather a family of them.  The
tutorial explains FRP as understood and implemented specifically by
reactive-banana.  There are a number of other practical libraries that
use different notions, in particular of events.

[1]: http://www.haskell.org/haskellwiki/
  FRP_explanation_using_reactive-banana
[2]: http://www.haskell.org/haskellwiki/Reactive-banana/Examples


Greets,
Ertugrul

-- 
Key-ID: E5DD8D11 Ertugrul Soeylemez e...@ertes.de
FPrint: BD28 3E3F BE63 BADD 4157  9134 D56A 37FA E5DD 8D11
Keysrv: hkp://subkeys.pgp.net/


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


Re: [Haskell-cafe] Observer pattern in haskell FRP

2012-11-29 Thread Heinrich Apfelmus

Nathan Hüsken wrote:

Heinrich Apfelmus wrote:


Personally, I would recommend is a complete change in perspective.

The main idea of FRP is that it is a method to describe the evolution of
values in time. What is a game? It's just a picture that evolves in
time. The user can exert influence on the evolution by clicking certain
buttons on a mechanical device, but in the end, all he sees is a picture
that moves. [..]


That perspective certainly make sense. But couldn't one also describe a
game as a set of entities (spaceships) that react to the clicking of
buttons?


Of course, generally speaking, you can describe it any way you like, FRP 
is just a perspective, not a dictatorial doctrine.


But you probably mean that you want to describe spaceships within the 
FRP perspective, though independent of how they are displayed. That's a 
good point, which I missed. (The guideline of working backwards from the 
very final result has served me very well when developing in FRP style, 
though, hence my insistence on it.)


In the FRP perspective, I would use a slightly different language, 
though. Namely, I would not say that spaceships are entities that react 
to button clicks, but rather that they are represented by time-varying 
positions that depend on past button clicks. The change is subtle but 
important: you invert the direction of control. Instead of having a 
button click do something to the spaceship (push), you have a 
spaceship whose present position depends on past button clicks (pull).


The FRP perspective is also more holistic: you can think of a 
spaceship and other time-varying values as if you knew their values for 
all points in time, as if you were given graphical plots. (I have drawn 
a few pretty pictures in the slides linked to here 
http://apfelmus.nfshost.com/blog/2012/07/15-frp-tutorial-slides.html)



If I take for example the breakout game from here [1]. It outputs an
object scene of type Picture. But this picture is calculated from the
objects ballPos and paddlePos. So first a game state (ballPos,
paddlePos) is created and than transformed to something renderable.

I believe all examples I have seen for games with FRP follow this
pattern, and I would I want to do is seperate the steps of calculating
the game state and calculating the renderable from it.


In that light, the separation seems straightforward to me. Given the 
time-varying values that represent game objects,


   bSpaceShipPosition :: Behavior Position
   bAsteroidPositions :: Behavior [Position]
   bTime  :: Behavior Time

you can transform and combine them into a graphic, for instance like this

   bSpaceShipPicture :: Behavior Graphic
   bSpaceShipPicture =
   blinkenLights $ bTime * bSpaceShipPosition

   bAsteroidPictures = map drawAsteroid $ bAsteroidPositions

   bPicture = overlay $
   ((:) $ bSpaceShipPicture * bAsteroidPictures)

In other words, you just combine old time-varying values into new ones, 
much like you would combine combine graphical plots. Also note that you 
can add animation a posteriori; it doesn't have to be part of the values 
representing a space ship.



Of course, one important question is whether to represent asteroid 
positions as a time-varying collection  Behavior [Position]  or as a 
collection of time-varying values  [Behavior Position] . The latter form 
tends to require dynamic event switching, while the former form tends 
towards a monolithic  GameState  value, which would forgo many of the 
advantages of FRP.


I don't have enough practical experience to give a useful recommendation 
here, but at the moment, I tend towards breaking it up as much as 
possible, but trying to avoid dynamic event switching. My rule of thumb 
is to model similar objects (asteroids) as a time-varying collection, 
while modeling distinct objects (player space ship) as individual behaviors.



Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com


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


[Haskell-cafe] lambda case (was Re: A big hurray for lambda-case (and all the other good stuff))

2012-11-29 Thread Jon Fairbairn
Ben Franksen ben.frank...@online.de writes:

 just wanted to drop by to say how much I like the new lambda case extension. 
 I use it all the time and I just *love* how it relieves me from conjuring up 
 dummy variables, which makes teh code not only esier to write but also to 
 read.

 […] should *definitely* go into Haskell'13.

As I was opposed to the suggestion for lambda case I didn’t
really follow the discussion of the syntax, but I’m puzzled by
the choice. To me it seems obvious that if we are going to do
this (as opposed to something more decomposable like
lambda-match), we should do it simply by making the “case exp”
part of a case expression optional. So the syntax for lambda-
case would be

   of {alts…}

and we would then describe

   case e of {…}

as syntactic sugar for

   (of {…}) (e)

Doing it this way doesn’t introduce any new syntactic elements
and has fewer tokens at the point of use.

I don’t see any need for a \ in the syntax: this is a functional
language we are talking about after all. Once we know that “of”
introduces a function, that should be enough.

-- 
Jón Fairbairn jon.fairba...@cl.cam.ac.uk


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


[Haskell-cafe] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Fixie Fixie
Hi all haskellers

I every now and then get the feeling that doing my job code in Haskell would be 
a good idea.

I have tried a couple of times, but each time I seem to run into performance 
problems - I do lots of heavy computing.

The problem seems to be connected to lazy loading, which makes my programs so 
slow that I really can not show them to anyone. I have tried all tricks in the 
books, like !, seq, non-lazy datatypes...

I was poking around to see if this had changed, then I ran into this forum 
post: http://stackoverflow.com/questions/9409634/is-indexing-of-data-vector-unboxed-mutable-mvector-really-this-slow

The last solution was a haskell program which was in the 3x range to C, which I 
think is ok. This was in the days of ghc 7.0

I then tried compile the programs myself (ghc 7.4.1), but found that now the C 
program now was more that 100x faster. The ghc code was compiled with both O2 
and O3, giving only small differences on my 64-bit Linux box.

So it seems something has changed - and even small examples are still not safe 
when it comes to the lazy-monster. It reminds me of some code I read a couple 
of years ago where one of the Simons actually fired off a new thread, to make 
sure a variable was realized.

A sad thing, since I am More that willing to go for Haskell if proves to be 
usable. If anyone can see what is wrong with the code (there are two haskell 
versions on the page, I have tried the last and fastest one) it would also be 
interesting.

What is your experience, dear haskellers? To me it seems this beautiful 
language is useless without a better lazy/eager-analyzer.

Cheers,

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


Re: [Haskell-cafe] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Alfredo Di Napoli
Hi there,
I'm only an amateur so just my 2 cent: Haskell can be really fast, but
reaching that speed can be all but trivial: you need to use different data
types (e.g. ByteString vs. the normal String type) relies on
unconventional IO (e.g. Conduit, Iterateee) and still be ready to go out
of the base, using packages and functions wich are not in base/haskell
platform (e.g. mwc-random).

My 2 cents :)
A.

On 29 November 2012 18:09, Fixie Fixie fixie.fi...@rocketmail.com wrote:

 Hi all haskellers

 I every now and then get the feeling that doing my job code in Haskell
 would be a good idea.

 I have tried a couple of times, but each time I seem to run into
 performance problems - I do lots of heavy computing.

 The problem seems to be connected to lazy loading, which makes my programs
 so slow that I really can not show them to anyone. I have tried all tricks
 in the books, like !, seq, non-lazy datatypes...

 I was poking around to see if this had changed, then I ran into this forum
 post:
 http://stackoverflow.com/questions/9409634/is-indexing-of-data-vector-unboxed-mutable-mvector-really-this-slow

 The last solution was a haskell program which was in the 3x range to C,
 which I think is ok. This was in the days of ghc 7.0

 I then tried compile the programs myself (ghc 7.4.1), but found that now
 the C program now was more that 100x faster. The ghc code was compiled with
 both O2 and O3, giving only small differences on my 64-bit Linux box.

 So it seems something has changed - and even small examples are still not
 safe when it comes to the lazy-monster. It reminds me of some code I read a
 couple of years ago where one of the Simons actually fired off a new
 thread, to make sure a variable was realized.

 A sad thing, since I am More that willing to go for Haskell if proves to
 be usable. If anyone can see what is wrong with the code (there are two
 haskell versions on the page, I have tried the last and fastest one) it
 would also be interesting.

 What is your experience, dear haskellers? To me it seems this beautiful
 language is useless without a better lazy/eager-analyzer.

 Cheers,

 Felix

 ___
 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] Simple GUI Form

2012-11-29 Thread timothyhobbs
I know it's not wx, but if you were willing to use GTK, you could simply 
install:

http://hackage.haskell.org/package/gtk-jsinput

and generate the form automatically as described in:

https://github.com/timthelion/gtk-jsinput/blob/master/Graphics/UI/Gtk/
Custom/JSInput.hs



Timothy




-- Původní zpráva --
Od: Rune Harder Bak r...@bak.dk
Datum: 29. 11. 2012
Předmět: [Haskell-cafe] Simple GUI Form

Hi

I have some input parameters
data Input = ...
that I need the user to enter in a gui pop-up. (windows people...)
The rest of the app is not gui (or perhaps progress could be displayed
in a log-window)

What is the easiest way to make such a GUI form?

It need to compile for both Linux and Windows, so I though WxWidgets was 
ideal,
and I got wx[1]  0.90 to install (using wxWidgets2.8) on both windows
and linux.

Now I just need to create the form, but how do you do that?
Any clues or links to examples? I have never used wxwidgets on any
platform or done any other form of GUI before for that matters.
(apart from some Visual Basic ten years ago, and html).

I tried looking at wx examples, but I couldn't find this simple use
case explained anywhere.

I installed wx in the first place because WxGeneric[2] seemed exactly
what I needed,
but I can't get it to compile using ghc7.4.2 from haskell-platform.
Anybody got that working or have some other simple method?

Help much appreciated!

-Rune

[1] http://hackage.haskell.org/package/wx-0.13.2.3
(http://hackage.haskell.org/package/wx-0.13.2.3)
[2] http://hackage.haskell.org/package/WxGeneric
(http://hackage.haskell.org/package/WxGeneric)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
(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] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Johan Tibell
Hi Felix,

On Thu, Nov 29, 2012 at 10:09 AM, Fixie Fixie
fixie.fi...@rocketmail.com wrote:
 The problem seems to be connected to lazy loading, which makes my programs
 so slow that I really can not show them to anyone. I have tried all tricks
 in the books, like !, seq, non-lazy datatypes...

My advice usually goes like this:

 1. Use standard, high-performance libraries (I've made a list of high
quality libraries at
https://github.com/tibbe/haskell-docs/blob/master/libraries-directory.md).
 2. Make your data type fields strict.
 3. Unpack primitive types (e.g. Int, Word, Float, Double).
 4. Reduce allocation in tight loops (e.g. avoid creating lots of
intermediate lists).

I always do 1-3, but only do 4 when it's really necessary (e.g. in the
inner loop of some machine learning algorithm).

Rarely is performance issues due to lacking bang patterns on functions
(although there are cases, e.g. when writing recursive functions with
accumulators, where you need one).

 I was poking around to see if this had changed, then I ran into this forum
 post:
 http://stackoverflow.com/questions/9409634/is-indexing-of-data-vector-unboxed-mutable-mvector-really-this-slow

 The last solution was a haskell program which was in the 3x range to C,
 which I think is ok. This was in the days of ghc 7.0

 I then tried compile the programs myself (ghc 7.4.1), but found that now the
 C program now was more that 100x faster. The ghc code was compiled with both
 O2 and O3, giving only small differences on my 64-bit Linux box.

 So it seems something has changed - and even small examples are still not
 safe when it comes to the lazy-monster. It reminds me of some code I read a
 couple of years ago where one of the Simons actually fired off a new thread,
 to make sure a variable was realized.

Note that the issues in the blog post are not due to laziness (i.e.
there are no space leaks), but due to the code being more polymorphic
than the C code, causing extra allocation and indirection.

 A sad thing, since I am More that willing to go for Haskell if proves to be
 usable. If anyone can see what is wrong with the code (there are two haskell
 versions on the page, I have tried the last and fastest one) it would also
 be interesting.

 What is your experience, dear haskellers? To me it seems this beautiful
 language is useless without a better lazy/eager-analyzer.

It's definitely possible to write fast Haskell code (as some Haskell
programmers manage to do so consistently), but I appreciate that it's
harder than it should be. In my opinion the major thing missing is a
good text on how to write fast Haskell code and some tweaks to the
compiler (e.g. unbox strict primitive fields like Int by default).

Hope this helps.

Cheers,
Johan

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


Re: [Haskell-cafe] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Ivan Salazar
I hear you, my friend.

What I love of Haskell is that a lot of algorithms are very clean to
express and understand compared to, say, Lisp or C. Compared to Lisp,
function manipulation is also very clean (even compared to Racket). A great
plus is also type inference.

The bad side is that direct translation of algorithms are almost always
very slow and the work needed to make them perform is very mind bending. I
sometimes feel as if I am doing the work of a compiler/optimizer and wonder
if a computer program can do this translations.

In the correct hands (the Simons, Don Stewart, etc) I am sure Haskell is a
killer, but in hands of lowly, imperative mortals it is a time bomb. A good
example of this is narrated in Clarke's
Superiorityhttp://www.mayofamily.com/RLM/txt_Clarke_Superiority.html
.

I am a total Haskell newbie, so please ignore me if my opinion sounds
stupid, but I think I read once that Peyton-Jones said that the Haskell of
the future will be strict.

Thanks!


2012/11/29 Fixie Fixie fixie.fi...@rocketmail.com

 Hi all haskellers

 I every now and then get the feeling that doing my job code in Haskell
 would be a good idea.

 I have tried a couple of times, but each time I seem to run into
 performance problems - I do lots of heavy computing.

 The problem seems to be connected to lazy loading, which makes my programs
 so slow that I really can not show them to anyone. I have tried all tricks
 in the books, like !, seq, non-lazy datatypes...

 I was poking around to see if this had changed, then I ran into this forum
 post:
 http://stackoverflow.com/questions/9409634/is-indexing-of-data-vector-unboxed-mutable-mvector-really-this-slow

 The last solution was a haskell program which was in the 3x range to C,
 which I think is ok. This was in the days of ghc 7.0

 I then tried compile the programs myself (ghc 7.4.1), but found that now
 the C program now was more that 100x faster. The ghc code was compiled with
 both O2 and O3, giving only small differences on my 64-bit Linux box.

 So it seems something has changed - and even small examples are still not
 safe when it comes to the lazy-monster. It reminds me of some code I read a
 couple of years ago where one of the Simons actually fired off a new
 thread, to make sure a variable was realized.

 A sad thing, since I am More that willing to go for Haskell if proves to
 be usable. If anyone can see what is wrong with the code (there are two
 haskell versions on the page, I have tried the last and fastest one) it
 would also be interesting.

 What is your experience, dear haskellers? To me it seems this beautiful
 language is useless without a better lazy/eager-analyzer.

 Cheers,

 Felix

 ___
 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] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Clark Gaebel
If you can give an example of some underperforming code, I'm sure someone
(or several people) on this list would be more than happy to help you make
it more performant.

Generally, it doesn't take much. It's all in knowing where to look. Also,
if you know performance is key, you should be using the
performance-oriented data structures (ByteString, Text, Vector) from the
very beginning. Personally, I never find myself using Data.Array, and
rarely use String in real code. It's just not worth the performance
headaches.

And finally, depending on what you're doing, neither Haskell, nor C might
be right for you! Especially with certain numerics-related code, you might
find fortran, OpenCL, or CUDA easier to make performant.

Examples of this would be lovely.

  - Clark


On Thu, Nov 29, 2012 at 2:00 PM, Alfredo Di Napoli 
alfredo.dinap...@gmail.com wrote:

 Hi there,
 I'm only an amateur so just my 2 cent: Haskell can be really fast, but
 reaching that speed can be all but trivial: you need to use different data
 types (e.g. ByteString vs. the normal String type) relies on
 unconventional IO (e.g. Conduit, Iterateee) and still be ready to go out
 of the base, using packages and functions wich are not in base/haskell
 platform (e.g. mwc-random).

 My 2 cents :)
 A.

 On 29 November 2012 18:09, Fixie Fixie fixie.fi...@rocketmail.com wrote:

 Hi all haskellers

 I every now and then get the feeling that doing my job code in Haskell
 would be a good idea.

 I have tried a couple of times, but each time I seem to run into
 performance problems - I do lots of heavy computing.

 The problem seems to be connected to lazy loading, which makes my
 programs so slow that I really can not show them to anyone. I have tried
 all tricks in the books, like !, seq, non-lazy datatypes...

 I was poking around to see if this had changed, then I ran into this
 forum post:
 http://stackoverflow.com/questions/9409634/is-indexing-of-data-vector-unboxed-mutable-mvector-really-this-slow

 The last solution was a haskell program which was in the 3x range to C,
 which I think is ok. This was in the days of ghc 7.0

 I then tried compile the programs myself (ghc 7.4.1), but found that now
 the C program now was more that 100x faster. The ghc code was compiled with
 both O2 and O3, giving only small differences on my 64-bit Linux box.

 So it seems something has changed - and even small examples are still not
 safe when it comes to the lazy-monster. It reminds me of some code I read a
 couple of years ago where one of the Simons actually fired off a new
 thread, to make sure a variable was realized.

 A sad thing, since I am More that willing to go for Haskell if proves to
 be usable. If anyone can see what is wrong with the code (there are two
 haskell versions on the page, I have tried the last and fastest one) it
 would also be interesting.

 What is your experience, dear haskellers? To me it seems this beautiful
 language is useless without a better lazy/eager-analyzer.

 Cheers,

 Felix

 ___
 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] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Fixie Fixie
Oh, my - what an indentation :-)

New try:

- Videresendt melding 
Fra: Fixie Fixie fixie.fi...@rocketmail.com
Til: haskell-cafe@haskell.org haskell-cafe@haskell.org 
Kopi: Clark Gaebel cgae...@uwaterloo.ca 
Sendt: Torsdag, 29. november 2012 20.57
Emne: Vedr: [Haskell-cafe] To my boss: The code is cool, but it is about 100 
times slower than the old one...

Sure, the code is from the url I mentioned, both in C and in Haskell.

It allready seems like the haskell-version should run fast to me - it uses 
unboxed arrays and even unsafe functions to make it run faster. Well, have a 
look:

C-version:

#include stdint.h
#include stdio.h


#define VDIM    100
#define VNUM    10



uint64_t prng (uint64_t w) {
    w ^= w  13;
    w ^= w  7;
    w ^= w  17;
    return w;
};

void kahanStep (double *s, double *c, double x) {
    double y, t;
    y  = x - *c;
    t  = *s + y;
    *c = (t - *s) - y;
    *s = t;
}

void kahan(double s[], double c[]) {
    for (int i = 1; i = VNUM; i++) {
        uint64_t w = i;
        for (int j = 0; j
  VDIM; j++) {
                kahanStep(s[j], c[j], w);
                w = prng(w);
        }
    }
};


int main (int argc, char* argv[]) {
    double acc[VDIM], err[VDIM];
    for (int i = 0; i  VDIM; i++) {
        acc[i] = err[i] = 0.0;
    };
    kahan(acc, err);
    printf([ );
    for (int i = 0; i  VDIM; i++) {
        printf(%g , acc[i]);
    };
    printf(]\n);
};

And the haskell version:

{-# LANGUAGE CPP, BangPatterns #-}
module Main (main) where

#define VDIM 100
#define VNUM 10

import Data.Array.Base
import Data.Array.ST
import Data.Array.Unboxed
import Control.Monad.ST
import GHC.Word
import Control.Monad
import Data.Bits

prng :: Word - Word
prng w = w'
  where
    !w1 = w `xor` (w `shiftL` 13)
    !w2 = w1 `xor` (w1 `shiftR` 7)
    !w' = w2 `xor` (w2 `shiftL` 17)

type Vec s = STUArray s Int Double

kahan :: Vec s - Vec s - ST s ()
kahan s c = do
    let inner w j
            | j  VDIM  = do
                !cj - unsafeRead c j
                !sj - unsafeRead s j
                let !y = fromIntegral w - cj
                    !t = sj + y
                    !w' = prng w
                unsafeWrite c j ((t-sj)-y)
                unsafeWrite s j t
                inner w' (j+1)
            | otherwise = return ()
    forM_ [1 .. VNUM] $ \i - inner (fromIntegral i) 0

calc :: ST s (Vec s)
calc = do
    s - newArray (0,VDIM-1) 0
    c - newArray (0,VDIM-1) 0
    kahan s c
    return s

main :: IO ()
main = print . elems $ runSTUArray calc

Cheers,

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


Re: [Haskell-cafe] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Johan Tibell
Ack, it seems like you're running into one of these bugs (all now
fixed, but I don't know in which GHC version):

http://hackage.haskell.org/trac/ghc/search?q=doubleFromInteger

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


[Haskell-cafe] Vedr: To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Fixie Fixie
The program seems to take around 6 seconds on my linux-box, while the c version 
goes for 0.06 sekcond.

That is really some regression bug :-)

Anyone with a more recent version thatn 7.4.1?

Felix



 Fra: Johan Tibell johan.tib...@gmail.com
Til: Fixie Fixie fixie.fi...@rocketmail.com 
Kopi: Haskell cafe haskell-cafe@haskell.org 
Sendt: Torsdag, 29. november 2012 21.50
Emne: Re: [Haskell-cafe] To my boss: The code is cool, but it is about 100 
times slower than the old one...
 
Ack, it seems like you're running into one of these bugs (all now
fixed, but I don't know in which GHC version):

http://hackage.haskell.org/trac/ghc/search?q=doubleFromInteger___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Johan Tibell
On Thu, Nov 29, 2012 at 1:00 PM, Fixie Fixie fixie.fi...@rocketmail.com wrote:
 The program seems to take around 6 seconds on my linux-box, while the c
 version goes for 0.06 sekcond.

 That is really some regression bug :-)

 Anyone with a more recent version thatn 7.4.1?

On 7.4.2:

$ time ./c_test
...

real0m0.145s
user0m0.040s
sys 0m0.003s

$ time ./Test
...

real0m0.234s
user0m0.220s
sys 0m0.006s

Both compiled with -O2.

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


[Haskell-cafe] Vedr: To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Fixie Fixie
That's really an argument for upgrading to 7.4.2 :-)

Another reason for doing things with haskell is this mailing list.

Thanks!

Felix



 Fra: Johan Tibell johan.tib...@gmail.com
Til: Fixie Fixie fixie.fi...@rocketmail.com 
Kopi: Haskell cafe haskell-cafe@haskell.org 
Sendt: Torsdag, 29. november 2012 22.06
Emne: Re: [Haskell-cafe] To my boss: The code is cool, but it is about 100 
times slower than the old one...
 
On Thu, Nov 29, 2012 at 1:00 PM, Fixie Fixie fixie.fi...@rocketmail.com wrote:
 The program seems to take around 6 seconds on my linux-box, while the c
 version goes for 0.06 sekcond.

 That is really some regression bug :-)

 Anyone with a more recent version thatn 7.4.1?

On 7.4.2:

$ time ./c_test
...

real    0m0.145s
user    0m0.040s
sys    0m0.003s

$ time ./Test
...

real    0m0.234s
user    0m0.220s
sys    0m0.006s

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


Re: [Haskell-cafe] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Johan Tibell
On Thu, Nov 29, 2012 at 1:23 PM, Fixie Fixie fixie.fi...@rocketmail.com wrote:
 That's really an argument for upgrading to 7.4.2 :-)

 Another reason for doing things with haskell is this mailing list.

FYI I'm still looking into this issue as I'm not 100% happy with the
code GHC generates.

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


Re: [Haskell-cafe] Vedr: To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Daniel Fischer
On Donnerstag, 29. November 2012, 21:00:36, Fixie Fixie wrote:
 The program seems to take around 6 seconds on my linux-box, while the c
 version goes for 0.06 sekcond.
 
 That is really some regression bug :-)
 
 Anyone with a more recent version thatn 7.4.1?

I don't even have a problem with 7.4.1:

$ for ghc in $GHCS; do echo $ghc; time ./hskahan-$ghc  /dev/null; done;
7.0.4

real0m0.217s
user0m0.214s
sys 0m0.002s
7.2.1

real0m0.197s
user0m0.194s
sys 0m0.002s
7.2.2

real0m0.187s
user0m0.187s
sys 0m0.000s
7.4.1

real0m0.253s
user0m0.249s
sys 0m0.003s
7.4.2

real0m0.250s
user0m0.247s
sys 0m0.002s
7.6.1

real0m0.224s
user0m0.221s
sys 0m0.002s

$ time ./ckahan  /dev/null

real0m0.102s
user0m0.079s
sys 0m0.022s


We have an unpleasant regression in comparison to 7.2.* and the 7.4.* were 
slower than 7.6.1 is, but it's all okay here (not that it wouldn't be nice to 
have it faster still).

Are you on a 32-bit system?

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


Re: [Haskell-cafe] Vedr: To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Johan Tibell
On Thu, Nov 29, 2012 at 1:32 PM, Daniel Fischer
daniel.is.fisc...@googlemail.com wrote:
 We have an unpleasant regression in comparison to 7.2.* and the 7.4.* were
 slower than 7.6.1 is, but it's all okay here (not that it wouldn't be nice to
 have it faster still).

 Are you on a 32-bit system?

This version works around the Word-Double conversion bug and shows
good performance:

(Always compile with -Wall, it tells you if some arguments are
defaulted to slow Integers, instead of fast Ints.)

{-# LANGUAGE CPP, BangPatterns, MagicHash #-}
module Main (main) where

#define VDIM 100
#define VNUM 10

import Control.Monad.ST
import Data.Array.Base
import Data.Array.ST
import Data.Bits
import GHC.Word

import GHC.Exts

prng :: Word - Word
prng w = w'
  where
w1 = w `xor` (w `shiftL` 13)
w2 = w1 `xor` (w1 `shiftR` 7)
w' = w2 `xor` (w2 `shiftL` 17)

type Vec s = STUArray s Int Double

kahan :: Vec s - Vec s - ST s ()
kahan s c = do
let inner !w j
| j  VDIM  = do
cj - unsafeRead c j
sj - unsafeRead s j
let y = word2Double w - cj
t = sj + y
w' = prng w
unsafeWrite c j ((t-sj)-y)
unsafeWrite s j t
inner w' (j+1)
| otherwise = return ()

outer i | i  VNUM = inner (fromIntegral i) 0  outer (i + 1)
| otherwise = return ()
outer (0 :: Int)

calc :: ST s (Vec s)
calc = do
s - newArray (0,VDIM-1) 0
c - newArray (0,VDIM-1) 0
kahan s c
return s

main :: IO ()
main = print . elems $ runSTUArray calc

word2Double :: Word - Double
word2Double (W# w) = D# (int2Double# (word2Int# w))

On my (64-bit) machine the Haskell and C versions are on par.

-- Johan

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


Re: [Haskell-cafe] Vedr: To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Johan Tibell
On Thu, Nov 29, 2012 at 1:40 PM, Johan Tibell johan.tib...@gmail.com wrote:
 This version works around the Word-Double conversion bug and shows
 good performance:

I'd also like to point out that I've removed lots of bang patterns
that weren't needed. This program runs fine without any bang patterns
(but I've kept the one that can possibly have any performance
implication at all).

-- Johan

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


Re: [Haskell-cafe] Vedr: To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Daniel Fischer
On Donnerstag, 29. November 2012, 13:40:42, Johan Tibell wrote:
 word2Double :: Word - Double
 word2Double (W# w) = D# (int2Double# (word2Int# w))
 
 On my (64-bit) machine the Haskell and C versions are on par.

Yes, but the result is very different.

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


[Haskell-cafe] Is anyone working on a sparse matrix library in Haskell?

2012-11-29 Thread Mark Flamer
I am looking to continue to learn Haskell while working on something that
might eventually be useful to others and get posted on Hackage. I have
written quite a bit of Haskell code now, some useful and a lot just throw
away for learning. In the past others have expressed interest in having a
native Haskell sparse matrix and linear algebra library available(not just
bindings to a C lib). This in combination with FEM is one of my interests.
So my questions, is anyone currently working on a project like this? Does it
seem like a good project/addition to the community? I'm also interested if
anyone has any other project idea's, maybe even to collaborate on. Thanks



--
View this message in context: 
http://haskell.1045720.n5.nabble.com/Is-anyone-working-on-a-sparse-matrix-library-in-Haskell-tp5721452.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


Re: [Haskell-cafe] To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Stephen Tetley
On 29 November 2012 18:09, Fixie Fixie fixie.fi...@rocketmail.com wrote:


 What is your experience, dear haskellers? To me it seems this beautiful
 language is useless without a better lazy/eager-analyzer.


Since when has speed been the sole arbiter of utility?

10 years ago I switched from Clean to Haskell, even though Clean was
then faster (and included a good strictness analyser). The available
libraries for Haskell is what swung the decision for me.

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


Re: [Haskell-cafe] Vedr: To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Daniel Fischer
On Donnerstag, 29. November 2012, 13:40:42, Johan Tibell wrote:
 
 word2Double :: Word - Double
 word2Double (W# w) = D# (int2Double# (word2Int# w))
 
 On my (64-bit) machine the Haskell and C versions are on par.

On my box, the Haskell is even faster then, but, as said, the result is 
incorrect

With

correction :: Double
correction = 2 * int2Double minBound

word2Double :: Word - Double
word2Double w = case fromIntegral w of
   i | i  0 - int2Double i - correction
 | otherwise - int2Double i

I get

real0m0.078s
user0m0.077s
sys 0m0.001s

with correct results.

Okay, we **need** a better Word - Double etc. conversion. We could start with 
the above, that seems not too shabby.

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


Re: [Haskell-cafe] Vedr: To my boss: The code is cool, but it is about 100 times slower than the old one...

2012-11-29 Thread Johan Tibell
On Thu, Nov 29, 2012 at 2:02 PM, Johan Tibell johan.tib...@gmail.com wrote:
 On Thu, Nov 29, 2012 at 2:01 PM, Daniel Fischer
 daniel.is.fisc...@googlemail.com wrote:
 On Donnerstag, 29. November 2012, 13:40:42, Johan Tibell wrote:
 word2Double :: Word - Double
 word2Double (W# w) = D# (int2Double# (word2Int# w))

 On my (64-bit) machine the Haskell and C versions are on par.

 Yes, but the result is very different.

 Doh, I guess I didn't look at the output carefully enough.

One obvious error is that the C code has one loop go from 1..n where I
just naively assumed all loops go from 0..n-1. This fixes that:

outer i | i = VNUM = inner (fromIntegral i) 0  outer (i + 1)
| otherwise = return ()
outer (1 :: Int)

Perhaps the other issue is that

word2Double (W# w) = D# (int2Double# (word2Int# w))

is possibly the wrong way and we need a word2Double#.

-- Johan

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


Re: [Haskell-cafe] Why Kleisli composition is not in the Monad signature?

2012-11-29 Thread Brent Yorgey
On Thu, Nov 29, 2012 at 03:52:58AM +0100, Ben Franksen wrote:
 Tony Morris wrote:
  As a side note, I think a direct superclass of Functor for Monad is not
  a good idea, just sayin'
  
  class Functor f where
fmap :: (a - b) - f a - f b
  
  class Functor f = Apply f where
(*) :: f (a - b) - f a - f b
  
  class Apply f = Bind f where
(=) :: (a - f b) - f a - f b
  
  class Apply f = Applicative f where
unit :: a - f a
  
  class (Applicative f, Bind f) = Monad f where
  
  Same goes for Comonad (e.g. [] has (=) but not counit)
  ... and again for Monoid, Category, I could go on...
 
 Hi Tony
 
 even though I dismissed your mentioning this on the Haskell' list, I do have 
 to admit that the proposal has a certain elegance. However, before I buy 
 into this scheme, I'd like to see some striking examples for types with 
 natural (or at least useful) Apply and Bind instances that cannot be made 
 Applicative resp. Monad. 

Try writing an Applicative instances for (Data.Map.Map k).  It can't
be done, but the Apply instance is (I would argue) both natural and useful.

 Also, it is not clear to me what laws should hold 
 for them.

http://hackage.haskell.org/package/semigroupoids defines all of these
and specifies laws, presumably derived in a principled way.

-Brent

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


Re: [Haskell-cafe] Recursive timezone-loading function

2012-11-29 Thread Yitzchak Gale
Hi David,

David Thomas wrote:

 https://github.com/dlthomas/tzcache
 A small bit of code, but seems likely to be useful enough that I figured I
 should share.


Thanks for sharing this!


 1) Does this already exist somewhere I missed?


I haven't seen it anywhere.


 2) It seems silly to make this its own library

 - any suggestions where it could be added?


If you feel it is appropriate, I would be willing to add it
to timezone-olson. Does anyone else have an opinion
about it?

3) Is the traverse-a-directory-and-populate-a-map

pattern one worth abstracting?  If so, where should that go?


I think the proper abstraction would be a more
general fold or traversal over a directory structure.
Some languages have something like that (e.g.,
os.walk in Python). But look how simply it worked
out for you in Haskell - perhaps that's why there
doesn't seem to be a standard function for this
anywhere. That said, it might be interesting to
have this as a lens-package-style traversal.

4) Presently, it's a static cache entirely pre-loaded.

This seems fine, as it's not a terribly huge amount

of data, but it's worth noting.


Yes. The total amount of timezone data in the world
is likely to continue increasing at a significantly
slower rate than Moore's law.

5) Any comments on the code generally?

Improvements?  Complaints?


I like your code. I'm not sure how well this
brute-force mapM recursion would scale over
a timezone directory structure with, say, millions
of nodes. But that's not the use case here at all.

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


Re: [Haskell-cafe] Recursive timezone-loading function

2012-11-29 Thread Roman Cheplyaka
* Yitzchak Gale g...@sefer.org [2012-11-30 00:28:45+0200]
 I think the proper abstraction would be a more
 general fold or traversal over a directory structure.
 Some languages have something like that (e.g.,
 os.walk in Python).

Check out 
http://hackage.haskell.org/packages/archive/filemanip/latest/doc/html/System-FilePath-Find.html

Roman

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


Re: [Haskell-cafe] Why Kleisli composition is not in the Monad signature?

2012-11-29 Thread Ben Franksen
Brent Yorgey wrote:
 On Thu, Nov 29, 2012 at 03:52:58AM +0100, Ben Franksen wrote:
 Tony Morris wrote:
  As a side note, I think a direct superclass of Functor for Monad is not
  a good idea, just sayin'
  
  class Functor f where
fmap :: (a - b) - f a - f b
  
  class Functor f = Apply f where
(*) :: f (a - b) - f a - f b
  
  class Apply f = Bind f where
(=) :: (a - f b) - f a - f b
  
  class Apply f = Applicative f where
unit :: a - f a
  
  class (Applicative f, Bind f) = Monad f where
  
  Same goes for Comonad (e.g. [] has (=) but not counit)
  ... and again for Monoid, Category, I could go on...
 
 Hi Tony
 
 even though I dismissed your mentioning this on the Haskell' list, I do 
have 
 to admit that the proposal has a certain elegance. However, before I buy 
 into this scheme, I'd like to see some striking examples for types with 
 natural (or at least useful) Apply and Bind instances that cannot be made 
 Applicative resp. Monad. 
 
 Try writing an Applicative instances for (Data.Map.Map k).  It can't
 be done, but the Apply instance is (I would argue) both natural and 
useful.

I see. So there is one example. Are there more? I'd like to get a feeling 
for the abstraction and this is hard if there is only a single example.

 Also, it is not clear to me what laws should hold 
 for them.
 
 http://hackage.haskell.org/package/semigroupoids defines all of these
 and specifies laws, presumably derived in a principled way.

Ok. I was not surprised to see that there are not many laws for the classes 
without unit.

Cheers
-- 
Ben Franksen
()  ascii ribbon campaign - against html e-mail 
/\  www.asciiribbon.org   - against proprietary attachments


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


Re: [Haskell-cafe] Is anyone working on a sparse matrix library in Haskell?

2012-11-29 Thread Andreas Abel

Hi Mark,

I might become your user.  Currently, for Agda I have rolled my own 
sparse matrix implementation, see


http://hackage.haskell.org/packages/archive/Agda/latest/doc/html/src/Agda-Termination-SparseMatrix.html

Cheers,
Andreas

On 29.11.12 5:03 PM, Mark Flamer wrote:

I am looking to continue to learn Haskell while working on something that
might eventually be useful to others and get posted on Hackage. I have
written quite a bit of Haskell code now, some useful and a lot just throw
away for learning. In the past others have expressed interest in having a
native Haskell sparse matrix and linear algebra library available(not just
bindings to a C lib). This in combination with FEM is one of my interests.
So my questions, is anyone currently working on a project like this? Does it
seem like a good project/addition to the community? I'm also interested if
anyone has any other project idea's, maybe even to collaborate on. Thanks



--
View this message in context: 
http://haskell.1045720.n5.nabble.com/Is-anyone-working-on-a-sparse-matrix-library-in-Haskell-tp5721452.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



--
Andreas AbelDu bist der geliebte Mensch.

Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY

andreas.a...@ifi.lmu.de
http://www2.tcs.ifi.lmu.de/~abel/

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


Re: [Haskell-cafe] lambda case (was Re: A big hurray for lambda-case (and all the other good stuff))

2012-11-29 Thread Andreas Abel
I had been missing a pattern matching lambda in Haskell for a long time 
(SML had fn since ages) and my typical use will be


  monadic_expr = \case
branches

I think \case is not the worst choice, certainly better than of ...

Thanks to the GHC 7.6 developers!

Cheers,
Andreas

On 29.11.12 12:49 PM, Jon Fairbairn wrote:

Ben Franksen ben.frank...@online.de writes:


just wanted to drop by to say how much I like the new lambda case extension.
I use it all the time and I just *love* how it relieves me from conjuring up
dummy variables, which makes teh code not only esier to write but also to
read.



[…] should *definitely* go into Haskell'13.


As I was opposed to the suggestion for lambda case I didn’t
really follow the discussion of the syntax, but I’m puzzled by
the choice. To me it seems obvious that if we are going to do
this (as opposed to something more decomposable like
lambda-match), we should do it simply by making the “case exp”
part of a case expression optional. So the syntax for lambda-
case would be

of {alts…}

and we would then describe

case e of {…}

as syntactic sugar for

(of {…}) (e)

Doing it this way doesn’t introduce any new syntactic elements
and has fewer tokens at the point of use.

I don’t see any need for a \ in the syntax: this is a functional
language we are talking about after all. Once we know that “of”
introduces a function, that should be enough.



--
Andreas AbelDu bist der geliebte Mensch.

Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY

andreas.a...@ifi.lmu.de
http://www2.tcs.ifi.lmu.de/~abel/

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