Re: [Haskell-cafe] Re: Re: 0/0 1 == False

2008-01-19 Thread Kalman Noel
Ben Franksen wrote:
 Kalman Noel wrote:
  (2) lim a_n  = ∞
[...]
  (2) means that the sequence does not converge, because you can
  always find a value that is /larger/ than what you hoped might
  be the limit.

 (2) usually rather mean that for each positive limit A there is a number N
 such that a_N  A for /all/ n  N.

You're right here. I tried to come up with a more wordy, informal description,
but failed on that.

 Your definition of (2) is usually termed as '(a_n) contains a subsequence
 that tends toward +infinity'.

May you elaborate? I don't see where a subsequence comes into play here.

Kalman

--
Get a free email account with anti spam protection.
http://www.bluebottle.com/tag/2

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


Re: [Haskell-cafe] threads + IORefs = Segmentation fault?

2008-01-19 Thread Peter Verswyvelen
Hi David,

Which version of GHC are you using?

I tried to recompile some GHC 6.6.1 progs using GHC 6.8.2 and I also got
segfaults. I haven't figured out yet if this is because my changes to
make it work with GHC 6.8.2 are incorrect, or if this is an issue with
6.8.2.

Cheers,
Peter


On Fri, 2008-01-18 at 18:22 -0500, David Roundy wrote:
 Hi all,
 
 I'm working on some new progress-reporting code for darcs, and am getting
 segmentation faults!  :( The code uses threads + an IORef global variable
 to do this (with lots of unsafePerformIO).  So my question for the gurus
 who know more about this than I do:  is this safe? I thought it would be,
 because only one thread ever modifies the IORef, and the others only read
 it.  I don't really care if they read a correct value, as long as they
 don't segfault.
 
 The code (to summarize) looks like:
 
 {-# NOINLINE _progressData #-}
 _progressData :: IORef (Map String ProgressData)
 _progressData = unsafePerformIO $ newIORef empty
 
 updateProgressData :: String - (ProgressData - ProgressData) - IO ()
 updateProgressData k f = when (progressMode) $ modifyIORef _progressData 
 (adjust f k)
 
 setProgressData :: String - ProgressData - IO ()
 setProgressData k p = when (progressMode) $ modifyIORef _progressData (insert 
 k p)
 
 getProgressData :: String - IO (Maybe ProgressData)
 getProgressData k = if progressMode then lookup k `fmap` readIORef 
 _progressData
 else return Nothing
 
 The key function is
 
 beginTedious :: String - IO ()
 beginTedious k = do tid - forkIO $ handleProgress k
 debugMessage $ Beginning  ++ k
 setProgressData k $ ProgressData { sofar = 0,
latest = Nothing,
total = Nothing,
handler = Just tid }
 
 which is called before an action that may be so tedious for our users that
 they need their day brightened by messages such as Applying patch
 137/1436.  The handleProgress function alternates between threadDelay and
 reading the progress data to see whether any progress has been made and
 printing messages.  Meanwhile the main thread calls functions that update
 _progressData.
 
 Anyhow, the point is that I'm getting segfaults, even after recompiling
 everything from scratch! Is this in fact that unsafe? Do I really need to
 switch to MVars, even though no locking is required?

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


[Haskell-cafe] Re: threads + IORefs = Segmentation fault?

2008-01-19 Thread Achim Schneider
David Roundy [EMAIL PROTECTED] wrote:

 {-# NOINLINE _progressData #-}
 _progressData :: IORef (Map String ProgressData)
 _progressData = unsafePerformIO $ newIORef empty
 
 updateProgressData :: String 
   - (ProgressData - ProgressData) 
   - IO ()
 updateProgressData k f = when (progressMode) $ modifyIORef
   _progressData (adjust f k)
 
The question I'm asking myself is why you would want to modify a
reference to an always empty Map, which would be the case if
unsafePerformIO performs its action every time. If it doesnt' (and
experience suggest that it doesn't, as does the faithful usage of
{-# NOINLINE #-}, BUT YOU'LL NEVER, EVER, KNOW), I'm wondering why you
don't create the IORef in beginTedious and pass it around. Possibly
even with an implicit parameter.

And, yes, without multiple writing threads locking is unnecessary, and
mostly even with multiple writing threads, if they don't read, too.


/me mandates the renaming of unsafePerformIO to
iReallyReallyThoughtReallyHardAboutThisAndThereReallyIsNoDifferentWayThanToUseThisDreadedUnsafePerformIO.

OTOH, I have no idea what causes the segfault. 

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

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


Re: [Haskell-cafe] threads + IORefs = Segmentation fault?

2008-01-19 Thread David Roundy
Using ghc 6.6, but I've since isolated the bug as being unrelated to the
IORefs and threading, it was in an FFI binding that somehow never died
until I was testing this new code.

David

On Sat, Jan 19, 2008 at 01:27:47PM +0100, Peter Verswyvelen wrote:
 Hi David,
 
 Which version of GHC are you using?
 
 I tried to recompile some GHC 6.6.1 progs using GHC 6.8.2 and I also got
 segfaults. I haven't figured out yet if this is because my changes to
 make it work with GHC 6.8.2 are incorrect, or if this is an issue with
 6.8.2.
 
 Cheers,
 Peter
 
 
 On Fri, 2008-01-18 at 18:22 -0500, David Roundy wrote:
  Hi all,
  
  I'm working on some new progress-reporting code for darcs, and am getting
  segmentation faults!  :( The code uses threads + an IORef global variable
  to do this (with lots of unsafePerformIO).  So my question for the gurus
  who know more about this than I do:  is this safe? I thought it would be,
  because only one thread ever modifies the IORef, and the others only read
  it.  I don't really care if they read a correct value, as long as they
  don't segfault.
  
  The code (to summarize) looks like:
  
  {-# NOINLINE _progressData #-}
  _progressData :: IORef (Map String ProgressData)
  _progressData = unsafePerformIO $ newIORef empty
  
  updateProgressData :: String - (ProgressData - ProgressData) - IO ()
  updateProgressData k f = when (progressMode) $ modifyIORef _progressData 
  (adjust f k)
  
  setProgressData :: String - ProgressData - IO ()
  setProgressData k p = when (progressMode) $ modifyIORef _progressData 
  (insert k p)
  
  getProgressData :: String - IO (Maybe ProgressData)
  getProgressData k = if progressMode then lookup k `fmap` readIORef 
  _progressData
  else return Nothing
  
  The key function is
  
  beginTedious :: String - IO ()
  beginTedious k = do tid - forkIO $ handleProgress k
  debugMessage $ Beginning  ++ k
  setProgressData k $ ProgressData { sofar = 0,
 latest = Nothing,
 total = Nothing,
 handler = Just tid }
  
  which is called before an action that may be so tedious for our users that
  they need their day brightened by messages such as Applying patch
  137/1436.  The handleProgress function alternates between threadDelay and
  reading the progress data to see whether any progress has been made and
  printing messages.  Meanwhile the main thread calls functions that update
  _progressData.
  
  Anyhow, the point is that I'm getting segfaults, even after recompiling
  everything from scratch! Is this in fact that unsafe? Do I really need to
  switch to MVars, even though no locking is required?
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

-- 
David Roundy
Department of Physics
Oregon State University
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] threads + IORefs = Segmentation fault?

2008-01-19 Thread Lennart Augustsson
You should use an MVar if you want it to be thread safe.

On Jan 19, 2008 1:36 PM, David Roundy [EMAIL PROTECTED] wrote:

 Using ghc 6.6, but I've since isolated the bug as being unrelated to the
 IORefs and threading, it was in an FFI binding that somehow never died
 until I was testing this new code.

 David

 On Sat, Jan 19, 2008 at 01:27:47PM +0100, Peter Verswyvelen wrote:
  Hi David,
 
  Which version of GHC are you using?
 
  I tried to recompile some GHC 6.6.1 progs using GHC 6.8.2 and I also got
  segfaults. I haven't figured out yet if this is because my changes to
  make it work with GHC 6.8.2 are incorrect, or if this is an issue with
  6.8.2.
 
  Cheers,
  Peter
 
 
  On Fri, 2008-01-18 at 18:22 -0500, David Roundy wrote:
   Hi all,
  
   I'm working on some new progress-reporting code for darcs, and am
 getting
   segmentation faults!  :( The code uses threads + an IORef global
 variable
   to do this (with lots of unsafePerformIO).  So my question for the
 gurus
   who know more about this than I do:  is this safe? I thought it would
 be,
   because only one thread ever modifies the IORef, and the others only
 read
   it.  I don't really care if they read a correct value, as long as they
   don't segfault.
  
   The code (to summarize) looks like:
  
   {-# NOINLINE _progressData #-}
   _progressData :: IORef (Map String ProgressData)
   _progressData = unsafePerformIO $ newIORef empty
  
   updateProgressData :: String - (ProgressData - ProgressData) - IO
 ()
   updateProgressData k f = when (progressMode) $ modifyIORef
 _progressData (adjust f k)
  
   setProgressData :: String - ProgressData - IO ()
   setProgressData k p = when (progressMode) $ modifyIORef _progressData
 (insert k p)
  
   getProgressData :: String - IO (Maybe ProgressData)
   getProgressData k = if progressMode then lookup k `fmap` readIORef
 _progressData
   else return Nothing
  
   The key function is
  
   beginTedious :: String - IO ()
   beginTedious k = do tid - forkIO $ handleProgress k
   debugMessage $ Beginning  ++ k
   setProgressData k $ ProgressData { sofar = 0,
  latest =
 Nothing,
  total =
 Nothing,
  handler = Just
 tid }
  
   which is called before an action that may be so tedious for our users
 that
   they need their day brightened by messages such as Applying patch
   137/1436.  The handleProgress function alternates between threadDelay
 and
   reading the progress data to see whether any progress has been made
 and
   printing messages.  Meanwhile the main thread calls functions that
 update
   _progressData.
  
   Anyhow, the point is that I'm getting segfaults, even after
 recompiling
   everything from scratch! Is this in fact that unsafe? Do I really need
 to
   switch to MVars, even though no locking is required?
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe

 --
 David Roundy
 Department of Physics
 Oregon State University
 ___
 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] First go at reactive programming

2008-01-19 Thread Steve Lihn
Reactive-0.3 seems to have a dependency on TypeCompose-0.3. Earlier
version does not work (for lack of Data.Pair). This probably should be
specified in Cabal file.

I aslo fixed all the LANGUAGE problems and now encountered the
following error in TypeCompose:

[4 of 9] Compiling Control.Compose  ( src/Control/Compose.hs,
dist/build/Control/Compose.o )
src/Control/Compose.hs:561:0: parse error on input `deriving'

I tried to restored the commented out deriving Monoid and got pass
that. Not sure if that is right though. Back to reactive-0.3, I
encountered:

src/Data/Future.hs:60:27:
Module `Control.Monad' does not export `forever'

Forever is in the latest library, but not in my GHC 6.6. I am not sure
how to get this fixed. Any suggestion?

http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html


Steve


On Jan 19, 2008 1:31 AM, Conal Elliott [EMAIL PROTECTED] wrote:
 Hi Steve,

 Thanks for letting me know about the LANGUAGE problem.  Yes, I used
 6.8-friendly (6.6-unfriendly) LANGUAGE pragmas.  In retrospect, probably not
 such a great idea, since there seem to be many folks still on 6.6.

 I just changed the sources (commenting out the LANGUAGE pragmas and
 inserting -fglasgow-exts pragmas), darcs-pushed, and put a new version (0.3)
 on hackage.  Please give it another try.

 Cheers, - Conal



 On Jan 18, 2008 7:58 PM, Steve Lihn [EMAIL PROTECTED] wrote:
  Tried to install reactive-0.2 on GHC-6.6, but failed.
 
  Building reactive-0.2...
  src/Data/Reactive.hs:1:13: cannot parse LANGUAGE pragma
 
  Is the package for GHC 6.8? Is there an older version (0.0?) for GHC
  6.6 that I can play with your example? (Or advise how to hack that
  file to get it work on 6.6)
 
  Thanks,
  Steve
 


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


Re: [Haskell-cafe] Re: need help for cabal-install

2008-01-19 Thread Steve Lihn
On Jan 19, 2008 9:18 AM, Duncan Coutts [EMAIL PROTECTED] wrote:

 
  I think you're just missing a --user:
 
 $ cabal install --prefix=$HOME --user foo

 The prefix can also be set in the $HOME/.cabal/config file.


Syntax? Something like: prefix: /path/to/my/ghc ?

 BTW, In the development version of cabal-install --user is the default
 and the default user prefix is $HOME/.cabal (though both can be changed
 in the config file).


Is this newer than 12 hours ago? I tried cabal install --prefix=/path
package (without --user). That did not seem to work...

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


Re: [Haskell-cafe] Re: need help for cabal-install

2008-01-19 Thread Duncan Coutts

On Fri, 2008-01-18 at 23:44 -0500, Chris Ball wrote:
 Hi Steve,
 
 Now with cabal install, I can not figure out where to specify the
 --prefix. Cabal always complains failed to install package.
 
 I think you're just missing a --user:
 
$ cabal install --prefix=$HOME --user foo

The prefix can also be set in the $HOME/.cabal/config file.

BTW, In the development version of cabal-install --user is the default
and the default user prefix is $HOME/.cabal (though both can be changed
in the config file).

I'd also recommend anyone trying out cabal-install to ignore the old
version on hackage and go straight for the development version. It's a
tad harder to get installed since it also needs the development version
of the Cabal lib, but it has so many issues fixed.

darcs get --partial http://darcs.haskell.org/cabal
cd cabal
make setup
./setup configure --prefix=$HOME/.cabal --user
./setup build
./setup install
cd ..
darcs get --partial http://darcs.haskell.org/cabal-install
cd cabal-install
runghc Setup.hs configure --prefix=$HOME/.cabal --bindir=$HOME --user
runghc Setup.hs build
runghc Setup.hs install

This assumes $HOME/bin is on your path and that you already have the
zlib and HTTP packages installed.

Then get the latest hackage package list with:
cabal update

For a quick guide see:
cabal --help

There's also bash command line completion support:
source bash-completion/cabal

Then give it a try. 

Report any complaints or requests in the hackage trac:
http://hackage.haskell.org/trac/hackage/


Duncan

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


Re: [Haskell-cafe] Haskell-Support in Ohloh

2008-01-19 Thread Reinier Lamers


Op 17-jan-2008, om 1:21 heeft Joachim Breitner het volgende geschreven:


They explicitly write that they want haskell support, and the oldest
open bug report on their page is about this:

http://labs.ohloh.net/ohcount/ticket/205

So if anyone feels like programming some ruby (I guess they want it to
be in that language as well) and wants to give the haskell community a
chance for wider audience, give it a shot.
I used this rainy saturday to make a patch. It only took three lines  
of Ruby or so, and some more work getting ohcount to build on my  
machine and to make some unit tests. I submitted the patch to their  
trac, http://labs.ohloh.net/ohcount/ticket/205 .


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


Re: [Haskell-cafe] Re: need help for cabal-install

2008-01-19 Thread Steve Lihn
Just tried to test drive another feature and got the nasty error:

 cabal list
Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize' to increase it.


On Jan 19, 2008 9:27 AM, Steve Lihn [EMAIL PROTECTED] wrote:
 On Jan 19, 2008 9:18 AM, Duncan Coutts [EMAIL PROTECTED] wrote:
 
  
   I think you're just missing a --user:
  
  $ cabal install --prefix=$HOME --user foo
 
  The prefix can also be set in the $HOME/.cabal/config file.
 

 Syntax? Something like: prefix: /path/to/my/ghc ?

  BTW, In the development version of cabal-install --user is the default
  and the default user prefix is $HOME/.cabal (though both can be changed
  in the config file).
 

 Is this newer than 12 hours ago? I tried cabal install --prefix=/path
 package (without --user). That did not seem to work...

 Steve

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


Re: [Haskell-cafe] shootout using 6.6?

2008-01-19 Thread Richard Kelsall

Don Stewart wrote:
...

Yay, constructor specialisation!


http://shootout.alioth.debian.org/gp4/benchmark.php?test=binarytreeslang=all



And it's nice to see GHC 6.8.2 is now nearly ten times faster than
GCC for this benchmark :

http://shootout.alioth.debian.org/gp4/benchmark.php?test=threadringlang=all

Scary to think how fast GHC might become in 6.10 :)


Richard.

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


[Haskell-cafe] How best to make GHC 6.6 and 6.8 co-exist on one server/account

2008-01-19 Thread Steve Lihn
Hi,
It appears some of the latest hackages are moving towards 6.8 to take
advantage of the new features, while quite a few remains at 6.6. The
compatibility between the two versions has been problematic. I only
have 6.6 installed, but now thinking to add 6.8 to my account (so I
can switch between them, depending what works where).

What is the best practice to make 6.8 co-exist with 6.6 ? Specific
questions are:
1) I installed 6.6 under prefix=$HOME/ghc. If I install 6.8 to the
same prefix, it will overwrite 6.6. Correct? How do I get around it?
2) I installed additional tools and packages under $HOME/htools using
6.6. (Which I begin to wonder if that is necessary.) Do I have to use
a different directory for 6.8? I noticed that, for each package, the
path is $HOME/htools/lib/package-ver/ghc-6.6.1/ etc etc. It seems
that 6.8 will create subdirectories, so they can co-exist peacefully.
Correct?

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


Re: [Haskell-cafe] Re: need help for cabal-install

2008-01-19 Thread Duncan Coutts

On Sat, 2008-01-19 at 09:30 -0500, Steve Lihn wrote:
 Just tried to test drive another feature and got the nasty error:
 
  cabal list
 Stack space overflow: current size 8388608 bytes.
 Use `+RTS -Ksize' to increase it.

Oops, silly error on my part. darcs pull and it's fixed.

Duncan

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


Re: [Haskell-cafe] Re: need help for cabal-install

2008-01-19 Thread Duncan Coutts

On Sat, 2008-01-19 at 09:27 -0500, Steve Lihn wrote:
 On Jan 19, 2008 9:18 AM, Duncan Coutts [EMAIL PROTECTED] wrote:
 
  
   I think you're just missing a --user:
  
  $ cabal install --prefix=$HOME --user foo
 
  The prefix can also be set in the $HOME/.cabal/config file.
 
 
 Syntax? Something like: prefix: /path/to/my/ghc ?

Yes, but using ghc's path would be a really bad idea.

Actually there's user-prefix: and global-prefix: for the prefixes to
use when using --user or --global installs.

  BTW, In the development version of cabal-install --user is the default
  and the default user prefix is $HOME/.cabal (though both can be changed
  in the config file).
 
 
 Is this newer than 12 hours ago? I tried cabal install --prefix=/path
 package (without --user). That did not seem to work...

Remember, --user is default unless overridden by --global. So if you are
trying to install as root that probably will not work since it'll
probably have been built against packages that were in your user's
package db but are not in your root users package db. We've not
concentrated very much on global installs yet for cabal-install. We've
been trying to make ordinary user installs Just Worktm.

There was a bug a couple days ago where the prefix given on the command
line was being overridden from the one given in the config file. That's
now fixed. The command line overrides the saved config settings.

So if it's still not working for you, you'll have to give more details.
Details of what command you were using exactly and what the error
message was.

Duncan

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


Re: [Haskell-cafe] How best to make GHC 6.6 and 6.8 co-exist on one server/account

2008-01-19 Thread Duncan Coutts

On Sat, 2008-01-19 at 10:47 -0500, Steve Lihn wrote:
 Hi,
 It appears some of the latest hackages are moving towards 6.8 to take
 advantage of the new features, while quite a few remains at 6.6. The
 compatibility between the two versions has been problematic. I only
 have 6.6 installed, but now thinking to add 6.8 to my account (so I
 can switch between them, depending what works where).

It should all work. I've got 3 ghc versions installed.

 What is the best practice to make 6.8 co-exist with 6.6 ? Specific
 questions are:
 1) I installed 6.6 under prefix=$HOME/ghc. If I install 6.8 to the
 same prefix, it will overwrite 6.6. Correct? How do I get around it?

That could be ok. Check what the layout if $HOME/ghc is. If it looks
like:
bin/
lib/
lib/ghc-6.6/

then that's fine and you'll be able to install another ghc to the same
prefix, since the sub-dirs are versioned. You'll end up with
$HOME/bin/ghc being the latest ghc, and the older version available as
$HOME/ghc/bin/ghc-6.6.

 2) I installed additional tools and packages under $HOME/htools using
 6.6. (Which I begin to wonder if that is necessary.) Do I have to use
 a different directory for 6.8? I noticed that, for each package, the
 path is $HOME/htools/lib/package-ver/ghc-6.6.1/ etc etc. It seems
 that 6.8 will create subdirectories, so they can co-exist peacefully.
 Correct?

Yes.

The aim is to be able to have multiple haskell implementations, multiple
versions of each haskell implementations and multiple versions of each
library built for any/all haskell implementation/version and to have
them all co-exist peacefully.

Duncan

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


Re: [Haskell-cafe] First go at reactive programming

2008-01-19 Thread Conal Elliott
Thanks for the TypeCompose=0.3 tip. I've fixed my local Reactive.cabal and
will push at some point.

Oh yeay -- I'd forgotten about the deriving change in 6.8 vs 6.6.

Urg.  I didn't realize that 'forever' isn't in 6.2.  You can use the 6.8def:

-- | @'forever' act@ repeats the action infinitely.
forever :: (Monad m) = m a - m ()
forever a   = a  forever a

I'm wondering how hard to try to get these libs to work with both 6.6 and
6.8.  My hope has been that people will switch to 6.8, but perhaps there are
obstacles I don't know about.  Is there something that keeps you from
upgrading?

  - Conal

On Jan 19, 2008 6:14 AM, Steve Lihn [EMAIL PROTECTED] wrote:

 Reactive-0.3 seems to have a dependency on TypeCompose-0.3. Earlier
 version does not work (for lack of Data.Pair). This probably should be
 specified in Cabal file.

 I aslo fixed all the LANGUAGE problems and now encountered the
 following error in TypeCompose:

 [4 of 9] Compiling Control.Compose  ( src/Control/Compose.hs,
 dist/build/Control/Compose.o )
 src/Control/Compose.hs:561:0: parse error on input `deriving'

 I tried to restored the commented out deriving Monoid and got pass
 that. Not sure if that is right though. Back to reactive-0.3, I
 encountered:

 src/Data/Future.hs:60:27:
Module `Control.Monad' does not export `forever'

 Forever is in the latest library, but not in my GHC 6.6. I am not sure
 how to get this fixed. Any suggestion?


 http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html


 Steve


 On Jan 19, 2008 1:31 AM, Conal Elliott [EMAIL PROTECTED] wrote:
  Hi Steve,
 
  Thanks for letting me know about the LANGUAGE problem.  Yes, I used
  6.8-friendly (6.6-unfriendly) LANGUAGE pragmas.  In retrospect, probably
 not
  such a great idea, since there seem to be many folks still on 6.6.
 
  I just changed the sources (commenting out the LANGUAGE pragmas and
  inserting -fglasgow-exts pragmas), darcs-pushed, and put a new version (
 0.3)
  on hackage.  Please give it another try.
 
  Cheers, - Conal
 
 
 
  On Jan 18, 2008 7:58 PM, Steve Lihn [EMAIL PROTECTED] wrote:
   Tried to install reactive-0.2 on GHC-6.6, but failed.
  
   Building reactive-0.2...
   src/Data/Reactive.hs:1:13: cannot parse LANGUAGE pragma
  
   Is the package for GHC 6.8? Is there an older version (0.0?) for GHC
   6.6 that I can play with your example? (Or advise how to hack that
   file to get it work on 6.6)
  
   Thanks,
   Steve
  
 
 

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


Re: [Haskell-cafe] Haskell-Support in Ohloh

2008-01-19 Thread Jeremy Apthorp
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 20/01/2008, Reinier Lamers  wrote:

 Op 17-jan-2008, om 1:21 heeft Joachim Breitner het volgende geschreven:
 
  They explicitly write that they want haskell support, and the oldest
  open bug report on their page is about this:
 
  http://labs.ohloh.net/ohcount/ticket/205
 
  So if anyone feels like programming some ruby (I guess they want it to
  be in that language as well) and wants to give the haskell community a
  chance for wider audience, give it a shot.
 I used this rainy saturday to make a patch. It only took three lines
 of Ruby or so, and some more work getting ohcount to build on my
 machine and to make some unit tests. I submitted the patch to their
 trac, http://labs.ohloh.net/ohcount/ticket/205 .

Is it just me or does that patch not actually include the line counting code..?

Jeremy
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHkixQ5plcd8tF/AQRAqQeAJ420viuL4fdi3EqvtRZkbTSoJsmQQCgkYqG
oofypoHigdBzSNtM2xB1nw0=
=3tv8
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] functional graphs

2008-01-19 Thread Thomas Hartman
I don't get where the graph edges (Node,Node) are specified.

Do you just assume that every two nodes have an edge between them and
calculate the edge label from the function?

Also, is there a real world / motivating use for a graph defined this way?

thomas.

2008/1/18, Christian Maeder [EMAIL PROTECTED]:
 Hi,

 Given a complete graph as a list of nodes whose edge labels are given by
 a function over two nodes:

 data CGraph a b = CGraph [a] (a - a - b)

 Can I define an instance for the fgl Graph class?

 import Data.Graph.Inductive.Graph

 instance Graph CGraph where
   empty = CGraph []  -- and now?

 I had no idea how to define empty (except using undefined).

 I thought of requiring a context for the node labels of type a, but this
 type is not mentioned in the class header. So it looked to me like the
 impossibility to define sets (requiring an Ord) as monads. (i.e.
 instance Monad Data.Set.Set)

 Any working proposals for my graph problem?

 Cheers Christian
 ___
 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] First go at reactive programming

2008-01-19 Thread Steve Lihn
 -- | @'forever' act@ repeats the action infinitely.
 forever :: (Monad m) = m a - m ()
 forever a   = a  forever a

Great. The code compiled successfully by inserting this in various places.

 I'm wondering how hard to try to get these libs to work with both 6.6 and
 6.8.  My hope has been that people will switch to 6.8, but perhaps there are
 obstacles I don't know about.  Is there something that keeps you from
 upgrading?

I am asking this question in another thread. The problem is -- I've
got many modules compiled under 6.6, some with much agony. If I switch
to 6.8, I have to recompile them again. Two issues I image:

(1) It may take lots of effort to recompile all the modules. I have
forgetten how I got around some of the modules! Too bad... Got to take
notes next time...
(2) If I got stuck in 6.8, it may not be easy to switch back.

It does not appear straightforward to me. I'd like to hear how other
people approach these issues before I jump into it. Don't want to
break the working environment that I spent months to set up!
--
Finally, get to test the Reactive sample code.

(1) Levi's first post compiled successfully and worked like charm. Congrat.
(2) Levi's second post did not compile. There is a type error...

react.hs:33:65:
Couldn't match expected type `Handle'
   against inferred type `RequestHandler'
In the first argument of `handleConnection', namely `r'
In the first argument of `fmap', namely `(handleConnection r)'
In the second argument of `(.)', namely `fmap (handleConnection r)'

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


[Haskell-cafe] Throwback of inferred types

2008-01-19 Thread Jon Harrop

Is it possible to get throwback of inferred types into Emacs or an IDE for 
Haskell?

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] First go at reactive programming

2008-01-19 Thread gwern0
On 2008.01.19 12:22:43 -0500, Steve Lihn [EMAIL PROTECTED] scribbled 1.5K 
characters:
...
 I am asking this question in another thread. The problem is -- I've
 got many modules compiled under 6.6, some with much agony. If I switch
 to 6.8, I have to recompile them again. Two issues I image:

 (1) It may take lots of effort to recompile all the modules. I have
 forgetten how I got around some of the modules! Too bad... Got to take
 notes next time...

These days, every package you'd want to install (with the exception of GHC, 
Darcs, and the large graphics toolkits) should be available on Hackage or at 
least in Cabalized form.

If they aren't, then that's a bug or at least missing feature. The whole point 
of Cabal was so you don't have to take notes!

 (2) If I got stuck in 6.8, it may not be easy to switch back.

Well, uh, is that really a bad thing? Do you worry about device drivers 
'because if I got stuck in the 2.x series of Linux kernels, it may not be easy 
to switch back [to 1.x]'? No; 6.8.x is the future. The older GHCs will fall 
behind, people will rightfully upgrade, things will bitrot, and so on. There's 
no real benefit to willfully using outdated software - the most painful parts 
of the 6.8.x upgrade are past.

 It does not appear straightforward to me. I'd like to hear how other
 people approach these issues before I jump into it. Don't want to
 break the working environment that I spent months to set up!

I began darcs send'ing patches for stuff broken by 6.8.x; by this point, all 
the major stuff I use is fixed, at least out of Darcs (although many packages 
are woefully outdated on Hackage. I've been working on this).

...
 Thanks.
 Steve

--
gwern
Information II captain SAS BRLO unclassified of Audiotel Taiwan RSOC


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


Re: [Haskell-cafe] Throwback of inferred types

2008-01-19 Thread gwern0
On 2008.01.19 17:30:50 +, Jon Harrop [EMAIL PROTECTED] scribbled 0.2K 
characters:

 Is it possible to get throwback of inferred types into Emacs or an IDE for
 Haskell?

 --
 Dr Jon D Harrop, Flying Frog Consultancy Ltd.

Sure. I once hacked together quite a while ago a little function for 
haskell-mode which looked like:

,
| (defun getHaskellFunctionTypeSignature ()
|   (interactive)
|   (progn
| (setq file-name buffer-file-name)
| (setq functionName (thing-at-point 'word))
| (shell-command (concat echo :t  functionName  | ghci -v0 -cpp 
-fglasgow-exts -w  file-name |grep  functionName) t)))
| (global-set-key \C-c\l 'getHaskellFunctionTypeSignature)
`

And I think haskell-mode has a better way of doing things somewhere in its 
inf-haskell.el.

--
gwern
Information II captain SAS BRLO unclassified of Audiotel Taiwan RSOC


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


RE: [Haskell-cafe] Throwback of inferred types

2008-01-19 Thread Peter Verswyvelen
Visual Haskell does that, but IMHO not as good as the F# plugin for Visual
Studio.

Currently I just use Emacs and Haskell Mode and the :t command, but this
only works for top level functions (is this correct? Maybe some syntax
exists to refer to an inner function?), so yeah, it would be really handy to
have a good IDE that shows you the inferred types on the fly. 

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:haskell-cafe-
 [EMAIL PROTECTED] On Behalf Of Jon Harrop
 Sent: Saturday, January 19, 2008 6:31 PM
 To: haskell-cafe@haskell.org
 Subject: [Haskell-cafe] Throwback of inferred types
 
 
 Is it possible to get throwback of inferred types into Emacs or an IDE
 for
 Haskell?
 
 --
 Dr Jon D Harrop, Flying Frog Consultancy Ltd.
 http://www.ffconsultancy.com/products/?e
 ___
 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] Re: Re: Re: 0/0 1 == False

2008-01-19 Thread Ben Franksen
Kalman Noel wrote:
 Ben Franksen wrote:
 Kalman Noel wrote:
  (2) lim a_n  = ∞
 [...]
  (2) means that the sequence does not converge, because you can
  always find a value that is /larger/ than what you hoped might
  be the limit.

 (2) usually rather mean that for each positive limit A there is a number
 N such that a_N  A for /all/ n  N.
 
 You're right here. I tried to come up with a more wordy, informal
 description, but failed on that.
 
 Your definition of (2) is usually termed as '(a_n) contains a subsequence
 that tends toward +infinity'.
 
 May you elaborate? I don't see where a subsequence comes into play here.

I'll show (2) = (2'), where

(2'): (a_n) contains a subsequence that tends toward +infinity

= : Assume (2) holds. Construct a subsequence (b_m) of (a_n) by chosing,
for each natural number m, an index n_m such that b_m = n_(n_m) is larger
than m (which is possible by (2)). Then (b_m) is a subsequence of (a_n)
that tends toward infinity (as I defined it).

= : Assume (2') holds. Let A  0 be any positive number (that you hope
might be the limit). We want to show that we can find N such that a_N  A.
To do so, chose a M, such that b_M  A (which is possible by assumption).
Then there exists an N such that a_N = b_M, because (b_n) is a subsequence
of (a_n).

q.e.d

Cheers
Ben

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


RE: [Haskell-cafe] Throwback of inferred types

2008-01-19 Thread Peter Verswyvelen
The problem is that this only works when the complete source file compiles
correctly no?

I would find it most useful to get type inference information on the fly,
even when not all of the code compiles correctly yet.

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:haskell-cafe-
 [EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
 Sent: Saturday, January 19, 2008 6:42 PM
 To: Jon Harrop; haskell-cafe@haskell.org
 Subject: Re: [Haskell-cafe] Throwback of inferred types
 
 On 2008.01.19 17:30:50 +, Jon Harrop [EMAIL PROTECTED]
 scribbled 0.2K characters:
 
  Is it possible to get throwback of inferred types into Emacs or an
 IDE
  for Haskell?
 
  --
  Dr Jon D Harrop, Flying Frog Consultancy Ltd.
 
 Sure. I once hacked together quite a while ago a little function for
 haskell-mode which looked like:
 
 ,
 | (defun getHaskellFunctionTypeSignature ()
 |   (interactive)
 |   (progn
 | (setq file-name buffer-file-name)
 | (setq functionName (thing-at-point 'word))
 | (shell-command (concat echo :t  functionName  | ghci -v0 -cpp
 | -fglasgow-exts -w  file-name |grep  functionName) t)))
 | (global-set-key \C-c\l 'getHaskellFunctionTypeSignature)
 `
 
 And I think haskell-mode has a better way of doing things somewhere in
 its inf-haskell.el.
 
 --
 gwern
 Information II captain SAS BRLO unclassified of Audiotel Taiwan RSOC

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


Re: [Haskell-cafe] functional graphs

2008-01-19 Thread Benja Fallenstein
Hi Christian,

On Jan 18, 2008 1:55 PM, Christian Maeder [EMAIL PROTECTED] wrote:
 data CGraph a b = CGraph [a] (a - a - b)

 Can I define an instance for the fgl Graph class?

 I had no idea how to define empty (except using undefined).

Well, presumably the function does not need to be defined on values
not in the list, so returning an error is fair enough--

empty = CGraph [] (const $ error Node not in graph)

I suppose you want to use the index in the list as the Node (= Int),
which should be fine, but you'll run into problems with mkGraph,
because you don't have an Eq constraint on a, so you can't implement
the function to pass to CGraph. Since mkGraph is required to have the
type

mkGraph :: [LNode a] - [LEdge b] - CGraph a b

for *all* a and b, you don't have a way to add an Eq constraint
anywhere, either.

So, no dice...

However, if you'd be able to live with

data CGraph a b = CGraph [LNode a] (Node - Node - b)

then you should be able to write the instance like this--

instance Graph CGraph where
  empty = CGraph [] (const $ error Node not in graph)
  isEmpty (CGraph xs _) = null xs
  labNodes (CGraph xs _) = xs
  mkGraph nodes edges = CGraph nodes f where
f x y = fromMaybe (error Edge not found) (lookup (x,y) edges')
edges' = map (\(x,y,l) - ((x,y),l)) edges
  match x (CGraph nodes f) = case lookup x nodes of
Nothing - (Nothing, CGraph nodes f)
Just l -
  let nodes' = filter ((/= x) . fst) nodes
  left = map (\(y,_) - (f y x, y)) nodes'
  right = map (\(y,_) - (f x y, y)) nodes'
  in (Just (left, x, l, right), CGraph nodes' f)

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


Re: [Haskell-cafe] functional graphs

2008-01-19 Thread Benja Fallenstein
Hi,

On Jan 19, 2008 6:05 PM, Thomas Hartman [EMAIL PROTECTED] wrote:
 Do you just assume that every two nodes have an edge between them [...]?

Since that's what complete graph means, I assume so =-)

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


Re: [Haskell-cafe] threads + IORefs = Segmentation fault?

2008-01-19 Thread Alfonso Acosta
On Jan 19, 2008 2:36 PM, David Roundy [EMAIL PROTECTED] wrote:
 Using ghc 6.6, but I've since isolated the bug as being unrelated to the
 IORefs and threading, it was in an FFI binding that somehow never died
 until I was testing this new code.

In case the you are creating a binding of haskell code. Did you make
sure that the runtime constructor and destructor (hs_* functions) are
properly called? The could be the source of the segfault.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Re: Re: 0/0 1 == False

2008-01-19 Thread Kalman Noel
Ben Franksen wrote:
 Kalman Noel wrote:
  Ben Franksen wrote:
  Kalman Noel wrote:
   (2) means that the sequence does not converge, because you can
   always find a value that is /larger/ than what you hoped might
   be the limit.
  Your definition of (2) is usually termed as '(a_n) contains a subsequence
  that tends toward +infinity'.
 I'll show (2) = (2'), where
 
 (2'): (a_n) contains a subsequence that tends toward +infinity

Only now did I understand that your point was to explain why and how my
definition (2) is incorrect.  It's clear to me now.

Kalman

--
Finally - A spam blocker that actually works.
http://www.bluebottle.com/tag/4

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


Re: [Haskell-cafe] Throwback of inferred types

2008-01-19 Thread Jon Harrop
On Saturday 19 January 2008 18:11:13 Peter Verswyvelen wrote:
 I would find it most useful to get type inference information on the fly,
 even when not all of the code compiles correctly yet.

Yes. Is this not provided by any development environments then?

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Throwback of inferred types

2008-01-19 Thread Achim Schneider
Peter Verswyvelen [EMAIL PROTECTED] wrote:

 The problem is that this only works when the complete source file
 compiles correctly no?
 
ghc could just insert appropriate calls to error everywhere it can't
compile, so you can choose whether to fix the bugs by lexical or
operational ordering, ecj (the eclipse compiler) does exactly that.

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

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


Re: [Haskell-cafe] Hangman game

2008-01-19 Thread Yitzchak Gale
Hi Ronald,

Ronald Guida wrote:
 I'm interested in learning how to program games.  Since I have to start
 somewhere, I decided to write a simple Hangman game.  I'm wondering if
 anyone can look at my code and give me some feedback.

Lots of fun, thanks! And nicely written.

One point is that while it's OK to do your random
calculation directly in IO for this simple case, in general
you will have many random calculations and you will
want to avoid forcing them all into IO.

You can add one more field to GameState that holds
a random generator. Let's say you call it gsRandGen.
Make sure that gsRandGen gets initialized somewhere.

Define this utility function:

rand :: MonadState GameState m = (StdGen - (a, StdGen)) - m a
rand f = do
  gs - get
  let (x, g) = f $ gsRandGen gs
  put $ gs {gsRandGen = g}
  return x

Now, instead of:

   nWord - liftIO $ getStdRandom (randomR (0,length wordList - 1))

you can write:

   nWord - rand $ randomR (0,length wordList - 1)

If you want, you can even remove the dependence on
StdGen by making some of your function types polymorphic,
qualified where necessary by RandomGen g = ...

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


Re: [Haskell-cafe] Re: 0/0 1 == False

2008-01-19 Thread Jonathan Cast

On 19 Jan 2008, at 2:52 AM, Kalman Noel wrote:


Jonathan Cast wrote:

On 12 Jan 2008, at 3:23 AM, Kalman Noel wrote:

   (2) lim a_n  = ∞

[...]

   (2) means that the sequence does not converge,


To a value in R.  Again, inf is a perfectly well defined extended
real number, and behaves like any other element of R u {-inf, inf}.
(Although that structure isn't quite a field --- 0 * inf isn't
defined, nor is inf - inf).


Out of curiosity, is there some typical application domain for  
extended real

numbers?


In calculus and elementary analysis, the notion of limits at/to  
infinity, improper Riemann integrals, etc., are introduced by a  
succession of `special notations'.  Taking the extended real numbers  
as the underlying space permits these notations to be defined more  
compositionally, because ∞ is now an ordinary mathematical object.


For example, if f is a nonnegative measurable function, ∫f on a  
measurable set is /always/ defined (as an extended real number) and  
the special case of an `integrable' function is simply one where the  
integral (which is an actual mathematical value) is an element of R.   
So, when we say ∫f ∈ R, that notation is compositional --- that's  
real set membership there.  Similarly, ∫_{-∞}^∞ f is defined (as  
a Lebesgue integral) the same way any other integral is, because the  
interval [-∞, ∞] is a perfectly good mathematical object.


jcc

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


[Haskell-cafe] overlapping instance error -- need help using instance Monoid (Sum a) where a is a map of money values

2008-01-19 Thread Thomas Hartman
The code below compiles as given, however if I uncomment the tSM
function I get the overlapping instance error mentioned in the subject
line.

Can someone give me advice on how to do what I want to do?

basically I want to add, for example, (USD,1) and (USD,2) and (Euro,3)
and get result

fromList [(USD,3), (Euro,3)]

the datatypes below are more verbose but the above is the basic idea

thanks!

thomas.

*

module TransactionRows {- ( mkTransactionRows,TransactionRows ) -} where
import Data.Monoid
import Data.List
import qualified Data.Map as M

data Currency a = Currency a
  deriving ( Show, Eq, Ord )
data Money c a = Money ( M.Map c a )
  deriving Show
instance (Num a, Ord c)= Monoid ( Sum (Money c a) ) where
  mempty = Sum ( Money M.empty )
  Sum ( Money m1 ) `mappend` Sum ( Money m2 ) = Sum (Money m1
`plusmoney` Money m2)

plusmoney (Money m1s) (Money m2s) = Money msum
  where msum = foldl' f m1s (M.toList m2s)
f m (k,v) = M.insertWith (+) k v m

mkMoney1 :: Currency String - Float - Money (Currency String) Float
mkMoney1 c a = Money $ M.singleton c a

--sumMoney :: [Money (Currency String) Float] - Money (Currency String) Float
sumMoney ms = getSum $ mconcat $ map Sum ms

-- if I uncomment this, get Overlapping instances for Monoid error
--tSM = sumMoney [mkMoney1 (Currency usd) 1 :: Money (Currency String) Float]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] overlapping instance error -- need help using instance Monoid (Sum a) where a is a map of money values

2008-01-19 Thread David Menendez
On Jan 20, 2008 12:56 AM, Thomas Hartman [EMAIL PROTECTED] wrote:

 The code below compiles as given, however if I uncomment the tSM
 function I get the overlapping instance error mentioned in the subject
 line.

 Can someone give me advice on how to do what I want to do?

 basically I want to add, for example, (USD,1) and (USD,2) and (Euro,3)
 and get result

 fromList [(USD,3), (Euro,3)]

 the datatypes below are more verbose but the above is the basic idea

 thanks!

 thomas.

 *

 module TransactionRows {- ( mkTransactionRows,TransactionRows ) -} where
 import Data.Monoid
 import Data.List
 import qualified Data.Map as M

 data Currency a = Currency a
  deriving ( Show, Eq, Ord )
 data Money c a = Money ( M.Map c a )
  deriving Show
 instance (Num a, Ord c)= Monoid ( Sum (Money c a) ) where
  mempty = Sum ( Money M.empty )
  Sum ( Money m1 ) `mappend` Sum ( Money m2 ) = Sum (Money m1
 `plusmoney` Money m2)


This is the overlap. Data.Monoid already defines an instance for Monoid (Sum
a), so it's going to overlap with your Monoid (Sum (Money c a)).

Unless you're planning to define more than one Monoid for Money, I suggest
skipping Sum entirely.

-- 
Dave Menendez [EMAIL PROTECTED]
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Basic binary IO

2008-01-19 Thread Jamie Love

Hello all,

I'm wondering if anyone has a reference to any binary IO and data 
conversion tutorials.


I'm playing around with generating a BMP file in haskell, and am a 
little stuck on the best way to go about the simple task of creating 
the BMP header. The header is


BM + 4 bytes for file size + 4 bytes reserved + 4 bytes for offset 
where data begins.


I have the basis starting off at:

bmpHeader = B.pack $
   [ 0x42, 0x4D ] ++
   [0 , 0, 0, 0] ++
   [0 , 0, 0, 0] ++
   [14 :: Int32]

(where B is Data.ByteString)

I'm wondering how I can:

1/ convert a 32 bit number (Int32, Char32) to 4 Char8 elements
2/ rotate bits/bytes in a 32 bit Char32 (or Int32) so they are 
explicitly little-endian (I work on a mac powerbook, and it is big-endian)

3/ convert an Integer or Int type to an Int32 type

Any pointers or suggestions would be helpful.

Thanks

--
Jamie Love
Senior Consultant
Aviarc Australia
Mobile: +61 400 548 048



 

This message has been scanned for viruses and dangerous content 
by MailScanner and is believed to be clean.


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


Re: [Haskell-cafe] Basic binary IO

2008-01-19 Thread Don Stewart
jamie.love:
 Hello all,
 
 I'm wondering if anyone has a reference to any binary IO and data 
 conversion tutorials.

A good place to start looking is Data.Binary,

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary
  
 I'm playing around with generating a BMP file in haskell, and am a 
 little stuck on the best way to go about the simple task of creating 
 the BMP header. The header is
 
 BM + 4 bytes for file size + 4 bytes reserved + 4 bytes for offset 
 where data begins.
 
 I have the basis starting off at:
 
 bmpHeader = runPut $
[ 0x42, 0x4D ] ++
[0 , 0, 0, 0] ++
[0 , 0, 0, 0] ++
[14 :: Int32]

bmpHeader = runPut $ do
put 'B'
put 'M'
put (0  :: Int32)
put (0  :: Int32)
put (14 :: Int32)

Yields the lazy bytestring,

BM\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\SO

 (where B is Data.ByteString)
 
 I'm wondering how I can:
 
 1/ convert a 32 bit number (Int32, Char32) to 4 Char8 elements

Data.Binary.put (x :: Int32) etc.

 2/ rotate bits/bytes in a 32 bit Char32 (or Int32) so they are 
 explicitly little-endian (I work on a mac powerbook, and it is big-endian)

Use the little endian 'put' primitives,

putWord32le (fromIntegral (7 :: Int32))

 3/ convert an Integer or Int type to an Int32 type
 
 Any pointers or suggestions would be helpful.

fromIntegral

Data.Binary should support all this nicely, I hope.

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


Re: [Haskell-cafe] One-line haskell program with GHC

2008-01-19 Thread Sukit Tretriluxana
Thanks all. This really helps me a lot!

On Jan 18, 2008 6:24 PM, Jonathan Cast [EMAIL PROTECTED] wrote:

 On 18 Jan 2008, at 2:00 PM, Clifford Beshers wrote:

 2008/1/18 Sukit Tretriluxana [EMAIL PROTECTED]:

  Hi,
 
  I don't know if it's been asked before. I just wonder if GHC supports
  some sort of one-liner program that can be specify right as the argument to
  either ghci or runghc program. In perl, they have something like
 
  perl *-e* 'print Hello'
 
  Do we have similar thing with GHC?



  ghc -e 'putStrLn Yes, we do.'


 Although, unlike perl, you don't have to say print explicitly if you don't
 need it:

 ghc -e 'This works great!'

 jcc



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