Re: [Haskell-cafe] how to implement daemon start and stop directives?

2009-01-22 Thread Belka

 You can abstract this pattern:
 
 -- runs its argument in an infinite loop, and returns an action that stops
 the loop
 daemon :: IO () - IO (IO ())
 daemon action = do
 stopvar - atomically $ newTVar False
 let run = do
   stop - atomically $ readTVar stopvar
   if stop then return () else (action  run)
 forkIO run
 return (atomically $ writeTVar stopvar True)
 
 TVars are overkill here, actually, an IORef would be just fine, I think.
 
 Luke

Thanks, Luke!

Why do you write return (atomically $ writeTVar stopvar True) in the end?

Actually, I'm more interested in technical details how to communicate from
shell with background process - how to send commands to it. Currently
looking into POSIX libraries hope to find answers there... 
Also, maybe a FIFO-pipe-file would solve my problem. Imagine writing a
command in it, while one of daemon's thread is locked-while-awaits for
anything to come out from the other side of the pipe...

Belka
-- 
View this message in context: 
http://www.nabble.com/how-to-implement-daemon-start-and-stop-directives--tp21598690p21599567.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] A pattern type signature cannot bind scoped type variables `t'

2009-01-22 Thread George Pollard
On Mon, 2009-01-12 at 20:24 -0200, rodrigo.bonifacio wrote:
 Hi all,
 
 I'm trying to build a library that has the following code:
 
 hasTypeOf (TermRep (dx,_,_)) (x::t)
 = ((fromDynamic dx)::Maybe t)
 
Could you do something like this?

Enforce the types with a signature:

hasTypeOf :: (Typeable t) = Dynamic - t - Maybe t
hasTypeOf x _ = fromDynamic x

 hasTypeOf (toDyn (2::Int)) (undefined::Integer)
Nothing
 hasTypeOf (toDyn (2::Int)) (undefined::Int)
Just 2

Or if you just want boolean result:

hasTypeOf x y = typeOf y == dynTypeRep x


rcmAttmntN3MDzg
Description: micalg/pgp-sha1
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] how to implement daemon start and stop directives?

2009-01-22 Thread Eugene Kirpichov
Although I am not Luke, I will answer :)
The code creates a TVar 'stopvar', whose truth means to the 'run' loop
that it's time to return ().
So, if we're going to return an action that stops the loop, we're
going to return an action that sets stopvar to True.
That's precisely what return (atomically $ writeTVar stopvar True)
does. In case you're wondering about the atomically, it's because
writeTVar  has type STM () and whereas we need to 'return' an IO
(). For precisely the same reason is atomically present in the run
loop, since the loop is also in the IO monad.

2009/1/22 Belka lambda-be...@yandex.ru:

 You can abstract this pattern:

 -- runs its argument in an infinite loop, and returns an action that stops
 the loop
 daemon :: IO () - IO (IO ())
 daemon action = do
 stopvar - atomically $ newTVar False
 let run = do
   stop - atomically $ readTVar stopvar
   if stop then return () else (action  run)
 forkIO run
 return (atomically $ writeTVar stopvar True)

 TVars are overkill here, actually, an IORef would be just fine, I think.

 Luke

 Thanks, Luke!

 Why do you write return (atomically $ writeTVar stopvar True) in the end?

 Actually, I'm more interested in technical details how to communicate from
 shell with background process - how to send commands to it. Currently
 looking into POSIX libraries hope to find answers there...
 Also, maybe a FIFO-pipe-file would solve my problem. Imagine writing a
 command in it, while one of daemon's thread is locked-while-awaits for
 anything to come out from the other side of the pipe...

 Belka
 --
 View this message in context: 
 http://www.nabble.com/how-to-implement-daemon-start-and-stop-directives--tp21598690p21599567.html
 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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



-- 
Евгений Кирпичев
Разработчик Яндекс.Маркета
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: tensor product of dynamic-sized bits

2009-01-22 Thread Lutz Donnerhacke
* Ahn, Ki Yung wrote:
 This is why I am looking for existing work, because I am
 not yet very sure about my code I'm using.

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


[Haskell-cafe] Cabal.exe is available from http://haskell.org/~duncan/cabal/, but is not included in the latest cabal-install tool (version 0.6.0).

2009-01-22 Thread Benjamin L . Russell
I just tried to install the cabal-install tool (version 0.6.0) (see
http://www.haskell.org/cabal/download.html) on Windows XP, Service
Pack 2, but when I followed the instructions on the download page and
downloaded cabal-install-0.6.0.tar.gz, the gunzipped untarred
cabal-install-0.6.0 directory did not include cabal.exe.

Further, according to the bundled README file:

Quickstart on Windows systems
-

For Windows users we hope to provide a pre-compiled `cabal.exe` program 
shortly.
In the mean time you have to build the three dependencies in [the standard 
way].

[the standard way]:
  http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package

Running the bundled bootstrap.sh file in Cygwin resulted in an
installation error.

However, when I then visited the above-mentioned HaskellWiki page, I
discovered that cabal.exe, in fact, already existed:

... Windows users can download a binary (cabal.exe) from here.

(Here currently references http://haskell.org/~duncan/cabal/.)

Apparently, this cabal.exe file is in fact the complete cabal-install
tool (version 0.6.0) itself:

(After adding the cabal.exe installation directory to the path:)

C:\Documents and Settings\Benjamincabal --version
cabal-install version 0.6.0
using version 1.6.0.1 of the Cabal library

To facilitate installation for Windows users, perhaps cabal.exe should
be bundled with cabal-install-0.6.0.tar.gz, and the README file
updated?

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

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


RE: [Haskell-cafe] GLUT (glutGet undefined reference)

2009-01-22 Thread Paul Keir
Thanks Kazuya, that link is perfect.

Basically, I have to explicitly add -lglut :

ghc -package GLUT -lglut HelloWorld.hs -o HelloWorld

Great. GLUT (and now FreeGLUT) remains the simplest
and most reliable standard cross-platform OpenGL
windowing API.

(It seems from the link that the information used by
ghc-pkg is wrong, and stems from the GLUT package's
relationship to libraries known as Xmu and Xi.)

Cheers,
Paul


-Original Message-
From: Kazuya Sakakihara [mailto:kaz...@gmail.com]
Sent: Thu 22/01/2009 02:14
To: Paul Keir
Cc: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] GLUT (glutGet undefined reference)[MESSAGE NOT 
SCANNED]
 
Check this thread:
http://groups.google.com/group/fa.haskell/browse_thread/thread/1716fa5e5643541e/38373ec65e2537fd?lnk=gst

Kazuya

2009/1/20 Paul Keir pk...@dcs.gla.ac.uk:
 Hi all,

 I was hoping to introduce my old pal OpenGL
 with my new chum, Haskell. I used cabal to
 install GLUT on my 64-bit Ubuntu machine with
 GHC 6.8.2 (installed via apt-get/synaptic).

 I followed the wiki OpenGLTutorial1 until:
 ghc -package GLUT HelloWorld.hs -o HelloWorld
 at which point my screen is filled with errors.
 The errors begin with:

 /home/paul/.cabal/lib/GLUT-2.1.1.2/ghc-6.8.2/libHSGLUT-2.1.1.2.a(Begin.o):
 In function `szEn_info':
 (.text+0x26c): undefined reference to `glutGet'

 This surprised me a little because I've already
 seen these same errors recently on two separate
 Windows boxes. Somehow I'd got the idea it was
 (on Windows) due to installing from a binary; though
 I guess the story is the same with apt-get. Should
 I look for an apt-get switch to reinstall GHC from
 source instead?

 Regards,
 Paul


 ___
 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: how to implement daemon start and stop directives?

2009-01-22 Thread Ertugrul Soeylemez
Luke Palmer lrpal...@gmail.com wrote:

 TVars are overkill here, actually, an IORef would be just fine, I
 think.

Using IORefs is generally a sign of bad style.  But MVars would
perfectly suffice here.  They would be essentially the same, but without
'atomically'.


Greets,
Ertugrul.


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://blog.ertes.de/


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


Re: [Haskell-cafe] how to implement daemon start and stop directives?

2009-01-22 Thread Magnus Therning
On Thu, Jan 22, 2009 at 8:11 AM, Belka lambda-be...@yandex.ru wrote:

 You can abstract this pattern:

 -- runs its argument in an infinite loop, and returns an action that stops
 the loop
 daemon :: IO () - IO (IO ())
 daemon action = do
 stopvar - atomically $ newTVar False
 let run = do
   stop - atomically $ readTVar stopvar
   if stop then return () else (action  run)
 forkIO run
 return (atomically $ writeTVar stopvar True)

 TVars are overkill here, actually, an IORef would be just fine, I think.

 Luke

 Thanks, Luke!

 Why do you write return (atomically $ writeTVar stopvar True) in the end?

 Actually, I'm more interested in technical details how to communicate from
 shell with background process - how to send commands to it. Currently
 looking into POSIX libraries hope to find answers there...
 Also, maybe a FIFO-pipe-file would solve my problem. Imagine writing a
 command in it, while one of daemon's thread is locked-while-awaits for
 anything to come out from the other side of the pipe...

I think you should follow Unix standards in this case.  So depending
on what you kind of communication you are looking for you have
different options (this is based on my understanding of the Unix way):

 * Signals - for simple control, such as getting the daemon to stop,
reread its configuration, or restart
 * Pipe/Socket - for more complex control such as job control

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: how to implement daemon start and stop directives?

2009-01-22 Thread Luke Palmer
On Thu, Jan 22, 2009 at 5:48 AM, Ertugrul Soeylemez e...@ertes.de wrote:

 Luke Palmer lrpal...@gmail.com wrote:

  TVars are overkill here, actually, an IORef would be just fine, I
  think.

 Using IORefs is generally a sign of bad style.


I totally disagree.

The disadvantage of IORefs is that they do not work together very nicely.
 If you have more than one, it is very hard (impossible) to keep
multithreaded invariants between them.

But in this case, the IORef is completely encapsulated: it does not leave
the scope in which it was created.  You will never have to use it with any
other IORef, because nobody else even knows it exists.  The pattern is
self-contained and threadsafe with just an IORef.

A program that needs only IORefs and is threadsafe is *good* style to me,
because it means all the state is well-encapsulated (if it escaped, it would
fail to be threadsafe).

Luke


  But MVars would
 perfectly suffice here.  They would be essentially the same, but without
 'atomically'.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Big endian vs little endian in Haskell land?

2009-01-22 Thread Thomas DuBuisson
Sure, I've had to deal with this frequently.  Luckily, Data.Binary has
functions like getWord32be, putWord64le, etc.  I've never had any
problems and typically don't worry about the wire format after making
the Binary instances.

Or, if your question was what types of programs might be concerned you
can include any program that writes data to a file where the file
might be read on a different system and networking programs,
obviously.

Tom

2009/1/22 Galchin, Vasili vigalc...@gmail.com:
 Hello,

 Are there applications that have to deal with both(!!!) big endian
 and little endian on persistent store?? I.e. when marshalling out and
 unmarshalling in endian-ness has to be considered??

 Regards, Vasili

 ___
 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] Cabal.exe is available from http://haskell.org/~duncan/cabal/, but is not included in the latest cabal-install tool (version 0.6.0).

2009-01-22 Thread Duncan Coutts
On Thu, 2009-01-22 at 18:38 +0900, Benjamin L.Russell wrote:

 To facilitate installation for Windows users, perhaps cabal.exe should
 be bundled with cabal-install-0.6.0.tar.gz, and the README file
 updated?

I will mention it in the README for the next release. As it happens the
new bootstrap.sh also works if you've got mingw/cygwin and wget/curl.

I did not have access to a Windows machine at the time I made the
previous release, so the cabal.exe was not available at the time. Also
it was a bit experimental at the time, not many people had tested it on
Windows.

Duncan

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


Re: Re: [Haskell-cafe] How to make code least strict?

2009-01-22 Thread Jan Christiansen



Thomas Davie wrote:
 
 Further to all the playing with unamb to get some very cool behaviors,  
 you might want to look at Olaf Chitil's paper here:
 
 http://www.cs.kent.ac.uk/pubs/2006/2477/index.html
 
 It outlines a tool for checking if your programs are as non-strict as  
 they can be.
 

We have discussed StrictCheck on the thread Maintaining Laziness which
also covered the topic least strictness but wasn't as popular as this one.

I have put up a page with functions from Data.List which are not least
strict. I want to extend this with other examples from standard libraries.
The page can be found at
http://www.informatik.uni-kiel.de/~jac/strictcheck/.

Jan
-- 
View this message in context: 
http://www.nabble.com/How-to-make-code-least-strict--tp21546891p21604665.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] Why monoids will abide...

2009-01-22 Thread Dan Piponi
On Wed, Jan 21, 2009 at 11:12 PM, Eugene Kirpichov ekirpic...@gmail.com wrote:
 To my mind, in the map-reduce case you generally need a commutative
 monoid. Or, you need an extra infrastructure that mappend's only
 results from adjacent machines, or something like that.

This is a good paper on the stuff I'm talking about:
http://citeseer.ist.psu.edu/blelloch90prefix.html It doesn't
explicitly mention monoids but it's all about associative operations
with identity.
--
Dan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why monoids will abide...

2009-01-22 Thread Andrew Wagner
See, that's the kind of name we need!
StructureWithAssociativeOperationAndIdentity -- make both the mathematicians
AND the non-mathematicians mad!

On Thu, Jan 22, 2009 at 9:53 AM, Dan Piponi dpip...@gmail.com wrote:

 On Wed, Jan 21, 2009 at 11:12 PM, Eugene Kirpichov ekirpic...@gmail.com
 wrote:
  To my mind, in the map-reduce case you generally need a commutative
  monoid. Or, you need an extra infrastructure that mappend's only
  results from adjacent machines, or something like that.

 This is a good paper on the stuff I'm talking about:
 http://citeseer.ist.psu.edu/blelloch90prefix.html It doesn't
 explicitly mention monoids but it's all about associative operations
 with identity.
 --
 Dan
 ___
 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] Monoids and newtypes

2009-01-22 Thread Ketil Malde

One wart that was briefly mentioned during the Great Monoid Naming
Thread of 2009 is the need to wrap types in newtypes to provide multiple
instances of the same class with different semantics -- the archetypical
example being Integer as a monoid over addition as well as
multiplication. 

I was just wondering if not phantom types might serve here as an
alternative way to go about that.  Here's a small example illustrating
it: 


{-# LANGUAGE EmptyDataDecls  #-}
{-# LANGUAGE FlexibleInstances  #-}

module Monoids where
import Data.Monoid

data Foo a = Foo Integer deriving (Show, Eq)

data Additive
data Multiplicative

instance Monoid (Foo Additive) where
mappend (Foo x) (Foo y) = Foo (x+y)
mempty = Foo 0

instance Monoid (Foo Multiplicative) where
mappend (Foo x) (Foo y) = Foo (x*y)
mempty = Foo 1

instance Num (Foo a) where
fromInteger x = Foo x
Foo x + Foo y = Foo (x+y)
Foo x * Foo y = Foo (x*y)
signum (Foo x) = Foo (signum x)


Loading this into ghci, you get:
*Monoids mconcat [1,2]

interactive:1:0:
Ambiguous type variable `t' in the constraints:
  `Monoid t' arising from a use of `mconcat' at interactive:1:0-12
  `Num t' arising from the literal `2' at interactive:1:11
Probable fix: add a type signature that fixes these type variable(s)
*Monoids mconcat [1,2::Foo Additive]
Foo 3
*Monoids mconcat [1,2::Foo Multiplicative]
Foo 2

(This can of course be prettified a bit by omitting the constructor
from the Show instance).  

Any thought about this, pro/contra the newtype method?

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why monoids will abide...

2009-01-22 Thread Ross Paterson
On Thu, Jan 22, 2009 at 06:53:24AM -0800, Dan Piponi wrote:
 On Wed, Jan 21, 2009 at 11:12 PM, Eugene Kirpichov ekirpic...@gmail.com 
 wrote:
  To my mind, in the map-reduce case you generally need a commutative
  monoid. Or, you need an extra infrastructure that mappend's only
  results from adjacent machines, or something like that.
 
 This is a good paper on the stuff I'm talking about:
 http://citeseer.ist.psu.edu/blelloch90prefix.html It doesn't
 explicitly mention monoids but it's all about associative operations
 with identity.

Indeed, the parallel scan algorithm over an arbitrary monoid (originally
due to Ladner and Fischer) was one of the inspirations for the use of
monoids in the fingertree paper.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why monoids will abide...

2009-01-22 Thread Eugene Kirpichov
Thanks; I saw you mention the paper before, but now I finally started
reading it :)
By the way, the paper *does* arrange an extra infrastructure for
mappending only adjacent results.
Looks like with a commutative monoid, a fold could be done in a fully
distributed fashion, however it would no more be a scan.

2009/1/22 Dan Piponi dpip...@gmail.com:
 On Wed, Jan 21, 2009 at 11:12 PM, Eugene Kirpichov ekirpic...@gmail.com 
 wrote:
 To my mind, in the map-reduce case you generally need a commutative
 monoid. Or, you need an extra infrastructure that mappend's only
 results from adjacent machines, or something like that.

 This is a good paper on the stuff I'm talking about:
 http://citeseer.ist.psu.edu/blelloch90prefix.html It doesn't
 explicitly mention monoids but it's all about associative operations
 with identity.
 --
 Dan

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


[Haskell-cafe] Re: how to implement daemon start and stop directives?

2009-01-22 Thread Ertugrul Soeylemez
Luke Palmer lrpal...@gmail.com wrote:

 On Thu, Jan 22, 2009 at 5:48 AM, Ertugrul Soeylemez e...@ertes.de wrote:

  Luke Palmer lrpal...@gmail.com wrote:
 
   TVars are overkill here, actually, an IORef would be just fine, I
   think.
 
  Using IORefs is generally a sign of bad style.

 I totally disagree.

 The disadvantage of IORefs is that they do not work together very
 nicely.  If you have more than one, it is very hard (impossible) to
 keep multithreaded invariants between them.

 But in this case, the IORef is completely encapsulated: it does not
 leave the scope in which it was created.  You will never have to use
 it with any other IORef, because nobody else even knows it exists.
 The pattern is self-contained and threadsafe with just an IORef.

 A program that needs only IORefs and is threadsafe is *good* style to
 me, because it means all the state is well-encapsulated (if it
 escaped, it would fail to be threadsafe).

That's not my point.  The use of IORefs indicates an imperative
programming style.  Sometimes this is inevitable, but I've never seen a
case, where IORefs couldn't be replaced by a more elegant
State/StateT-based solution.  And if you need to do multi-threading,
Chans, MVars and semaphores are better anyway.  There is no reason to
prefer an IORef over an MVar to signal something to another thread.

By the way, IORefs are by themselves not thread-safe.  You need to use a
special function, when using it in a multi-threaded manner.


Greets,
Ertugrul.


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://blog.ertes.de/


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


Re: [Haskell-cafe] Re: how to implement daemon start and stop directives?

2009-01-22 Thread Luke Palmer
On Thu, Jan 22, 2009 at 9:04 AM, Ertugrul Soeylemez e...@ertes.de wrote:

  A program that needs only IORefs and is threadsafe is *good* style to
  me, because it means all the state is well-encapsulated (if it
  escaped, it would fail to be threadsafe).

 That's not my point.  The use of IORefs indicates an imperative
 programming style.


Um, we were talking about IORefs vs. MVars or TVars.  I thought we were
already firmly in the imperative world.  Nobody on this list will argue
against a pure solution always being preferable.


  Sometimes this is inevitable, but I've never seen a
 case, where IORefs couldn't be replaced by a more elegant
 State/StateT-based solution.  And if you need to do multi-threading,
 Chans, MVars and semaphores are better anyway.


Please define better.  For the function in question, what advantages do
they give us?

Just to be clear, I wouldn't dare argue that IORefs can do everything MVars
and TVars can do.   I'm just perplexed why you say MVars and TVars are
better, when an IORef does the trick just fine for our function.




There is no reason to
 prefer an IORef over an MVar to signal something to another thread.


Well, I usually don't go here, but benchmarks show that IORefs are the
fastest of any of the mutable variable primitives, by at least a factor of
2.  I wish I remembered where I saw that.


 By the way, IORefs are by themselves not thread-safe.  You need to use a
 special function, when using it in a multi-threaded manner.


You mean atomicModifyIORef?

IORefs *are* thread-safe by themselves: you will not make your program
segfault by using them in a multithreaded program.  So it all comes down to
invariants.  IORefs have no synchronization concepts, so code like:

x - readIORef ref
writeIORef ref (x+1)

Is not threadsafe by most standards.  That doesn't mean IORefs themselves
are not threadsafe, just that you have to be careful how you use them.

And I will reiterate:  *in this case* the use of IORef is fully encapsulated
in this function and *is threadsafe!*  Which is the basis of my argument: in
imperative code, when you can limit the scope of an IORef to a small
abstraction that is threadsafe, there is no advantage of TVars or MVars over
them.  I don't think they deserve bad style sledgehammer.  (An instance of
use the right tool for the job)

daemon :: IO () - IO (IO ())
daemon action = do
stopvar - newIORef False
let run = do
  stop - readIORef stopvar
  if stop then return () else (action  run)
forkIO run
return (writeIORef stopvar True)

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


Re: [Haskell-cafe] Pure Haskell implementation of Float type?

2009-01-22 Thread Henning Thielemann
Lennart Augustsson schrieb:
 There's the numbers package which contains BigFloat.  You can pick
 your own precision, but it's not IEEE.
 It's actually base 10 floats which makes it more fun (actually, the
 iEEE standard will cover base 10 floats in the future).

Actually, all of the arbitrary precision real number implementations may
be of interest for you:

http://haskell.org/haskellwiki/Applications_and_libraries/Mathematics#Number_representations

The NumericPrelude implementation by me, however, sometimes uses the
Double implementation for speedup.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Does readFile /proc/mounts hang for you?

2009-01-22 Thread David Fox
On Wed, Jan 21, 2009 at 9:20 AM, David Fox dds...@gmail.com wrote:

 I posted a bug about this (http://hackage.haskell.org/trac/ghc/ticket/2971)
 but its so odd I had to ask here.  Using ghc 6.10.1, both readFile
 /proc/mounts and Data.ByteString.Lazy.Char8.readFile /proc/mounts hang
 on an amd64 machine running Linux.  Also, Data.ByteString.readFile
 /proc/mounts returns the empty string.  Is this behavior present for
 others?  On i386?


I can now confirm that this bug also affects the i386 architecture.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Elegant external sorting

2009-01-22 Thread Bulat Ziganshin
Hello haskell-cafe,

SPJ asked us a few years ago about examples of simple and elegant
haskell programs. i want to propose this external sorting program: it
reads stdin in chunks of 5000 lines, writes sorted chunks into files
and then merges files together:

import Data.List
import Control.Monad
import Control.Arrow

main = do -- (Lazily) create sorted sublists
  sublists - fmap chop_and_sort getContents
  -- Write the sublists into files named 1..n
  n - fmap length $ zipWithM writeFile (map show [1..]) sublists
  -- Read (again lazily) contents of these files
  sublists - mapM (fmap lines.readFile.show) [1..n]
  -- Merge them and write result to stdout
  putStr (unlines (merge_lists compare sublists))

-- Split input list into 5000-line chunks and sort them
chop_and_sort = lines  recursive (splitAt 5000)  map (sortunlines)

-- unfoldr variant that stops on empty list
recursive splitFunc  =  unfoldr (\xs - guard (xs[])  Just (splitFunc xs))


-- Merging sorted lists (kidnapped from Data.List)
merge_lists :: (a - a - Ordering) - [[a]] - [a]
merge_lists cmp [] = []
merge_lists cmp [xs] = xs
merge_lists cmp xss = merge_lists cmp (merge_pairs cmp xss)

merge_pairs :: (a - a - Ordering) - [[a]] - [[a]]
merge_pairs cmp [] = []
merge_pairs cmp [xs] = [xs]
merge_pairs cmp (xs:ys:xss) = merge cmp xs ys : merge_pairs cmp xss

merge :: (a - a - Ordering) - [a] - [a] - [a]
merge cmp xs [] = xs
merge cmp [] ys = ys
merge cmp (x:xs) (y:ys)
 = case x `cmp` y of
GT - y : merge cmp (x:xs)   ys
_  - x : merge cmpxs (y:ys)

  

-- 
Best regards,
 Bulat  mailto:bulat.zigans...@gmail.com

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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Andrew Wagner
Interesting. I have a similar, but worse problem. For me, ':load'ing main.hs
would fail to find the imported files. The only thing I appear to be able to
:load is files that don't import from local directories.

2009/1/22 Peter Verswyvelen bugf...@gmail.com

 I have a silly problem.
 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the current
 directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching to the
 parent directory of src instead of src itself, and how to fix this?

 Thanks a lot,
 Peter


 ___
 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: Re[2]: [Haskell-cafe] Comments from OCaml Hacker Brian Hurt

2009-01-22 Thread Jeremy Shaw
Hello,

Just some minor suggestions and comments:

The description might read better as two sentences:

   A class for monoids with various general-purpose instances. Monoids
   are types with an associative binary operation that has an
   identity.

One thing that I think is a bit unclear from that description is the
fact that it does not matter *what* the binary operation does, as long
as the laws are followed. That is the whole point of the monoid class
-- you use it when you only care about the laws, not the specific
operation...

For the laws, it would be nice to label each rule, something like

 * mappend mempty x = x -- Left Identity
 * mappend x empty = x  -- Right Identity
 * mappend x (mappend y z) = mappend (mappend x y) z-- Associative
 * mconcat = foldr mappend mempty   -- Not sure what to 
call this. Perhaps it an axiom?

See the Applicative class for a formatting example:

http://www.haskell.org/ghc/dist/current/docs/libraries/base/Control-Applicative.html

As an expert, seeing the name is faster than reverse engineering the
meaning of each law. I also suspect many people have never heard of
the concept of an identity element (I am pretty sure I hadn't when I
first started Haskell). So, I think it would be nice to tie together
the concepts mentioned in the description with the actual laws so that
the link is explicit.

j. 

At Sun, 18 Jan 2009 13:57:07 +,
Duncan Coutts wrote:
 
 On Sat, 2009-01-17 at 13:36 -0800, David Leimbach wrote:
  
  
  On Sat, Jan 17, 2009 at 9:16 AM, david48 dav.vire+hask...@gmail.com
  wrote:
  On Sat, Jan 17, 2009 at 4:08 PM, David Leimbach
  leim...@gmail.com wrote:
  
   So you're saying it should be better documented in Haskell
  what a Monoid is.
Did you say you searched for C++ class why not Haskell
  Monoid then?
The first correct google hit that didn't think I meant
  Monads, takes you
   straight to the GHC documentation for Data.Monoid.
  
  Read my first post on the thread, that's exactly what I did
  ( and then
  complained that the doc for Data.Monoid was close to useless )
  
  
  Sorry missed it!  This is an exceptionally long thread! :-)  I agree
  Data.Monoid's docs don't give you much to work with. 
 
 Do you think they look better now:
 
 http://www.haskell.org/ghc/dist/current/docs/libraries/base/Data-Monoid.html
 
 Any other improvements you'd make?
 
 Duncan
 
 ___
 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] Haskell mode for Emacs question

2009-01-22 Thread Peter Verswyvelen
I have a silly problem.
I'm using Emacs with the Haskell mode extension on Windows

I have a source file in say

c:/foo/src/main.hs

main.hs is importing some other modules in that same src directory

When I invoke GHCi from within Emacs, the first thing it does is

:cd c:/foo

and then

:load src/main.hs

But of course GHCi won't find the imported modules now, since the current
directory is wrong.

If I type in GHCi

:cd src
:load main.hs

then it compiles fine.

Does anyone have an idea why Emacs or the Haskell mode is switching to the
parent directory of src instead of src itself, and how to fix this?

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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Miguel Mitrofanov

On my Mac I've had the same problem. Commenting out lines

  (unless (equal default-directory root)
(setq default-directory root)
(inferior-haskell-send-command
 proc (concat :cd  default-directory)))

solved it for me.


On 22 Jan 2009, at 20:23, Andrew Wagner wrote:

Interesting. I have a similar, but worse problem. For me, ':load'ing  
main.hs would fail to find the imported files. The only thing I  
appear to be able to :load is files that don't import from local  
directories.


2009/1/22 Peter Verswyvelen bugf...@gmail.com
I have a silly problem.

I'm using Emacs with the Haskell mode extension on Windows

I have a source file in say

c:/foo/src/main.hs

main.hs is importing some other modules in that same src directory

When I invoke GHCi from within Emacs, the first thing it does is

:cd c:/foo

and then

:load src/main.hs

But of course GHCi won't find the imported modules now, since the  
current directory is wrong.


If I type in GHCi

:cd src
:load main.hs

then it compiles fine.

Does anyone have an idea why Emacs or the Haskell mode is switching  
to the parent directory of src instead of src itself, and how to fix  
this?


Thanks a lot,
Peter


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


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


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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Peter Verswyvelen
mmm, it seems that the code is searching for the location of a cabal file
and uses that as the current directory, assuming all source code is relative
to that directory, instead of using the source directive in that cabal file.
On Thu, Jan 22, 2009 at 6:23 PM, Andrew Wagner wagner.and...@gmail.comwrote:

 Interesting. I have a similar, but worse problem. For me, ':load'ing
 main.hs would fail to find the imported files. The only thing I appear to be
 able to :load is files that don't import from local directories.

 2009/1/22 Peter Verswyvelen bugf...@gmail.com

 I have a silly problem.
 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the current
 directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching to the
 parent directory of src instead of src itself, and how to fix this?

 Thanks a lot,
 Peter


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



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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Miguel Mitrofanov
Oops, sorry, forgot to mention that lines worth commenting were in  
inf-haskell.el file.


On 22 Jan 2009, at 20:23, Andrew Wagner wrote:

Interesting. I have a similar, but worse problem. For me, ':load'ing  
main.hs would fail to find the imported files. The only thing I  
appear to be able to :load is files that don't import from local  
directories.


2009/1/22 Peter Verswyvelen bugf...@gmail.com
I have a silly problem.

I'm using Emacs with the Haskell mode extension on Windows

I have a source file in say

c:/foo/src/main.hs

main.hs is importing some other modules in that same src directory

When I invoke GHCi from within Emacs, the first thing it does is

:cd c:/foo

and then

:load src/main.hs

But of course GHCi won't find the imported modules now, since the  
current directory is wrong.


If I type in GHCi

:cd src
:load main.hs

then it compiles fine.

Does anyone have an idea why Emacs or the Haskell mode is switching  
to the parent directory of src instead of src itself, and how to fix  
this?


Thanks a lot,
Peter


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


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


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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Peter Verswyvelen
indeed, that works! the comment above those lines is:
;; Not sure if it's useful/needed and if it actually works.

:-)

On Thu, Jan 22, 2009 at 6:41 PM, Miguel Mitrofanov miguelim...@yandex.ruwrote:

 On my Mac I've had the same problem. Commenting out lines

  (unless (equal default-directory root)
(setq default-directory root)
(inferior-haskell-send-command
 proc (concat :cd  default-directory)))

 solved it for me.



 On 22 Jan 2009, at 20:23, Andrew Wagner wrote:

  Interesting. I have a similar, but worse problem. For me, ':load'ing
 main.hs would fail to find the imported files. The only thing I appear to be
 able to :load is files that don't import from local directories.

 2009/1/22 Peter Verswyvelen bugf...@gmail.com
 I have a silly problem.

 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the current
 directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching to the
 parent directory of src instead of src itself, and how to fix this?

 Thanks a lot,
 Peter


 ___
 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] Monoids and newtypes

2009-01-22 Thread Derek Elkins
On Thu, 2009-01-22 at 16:11 +0100, Ketil Malde wrote:
 One wart that was briefly mentioned during the Great Monoid Naming
 Thread of 2009 is the need to wrap types in newtypes to provide multiple
 instances of the same class with different semantics -- the archetypical
 example being Integer as a monoid over addition as well as
 multiplication. 
 
 I was just wondering if not phantom types might serve here as an
 alternative way to go about that.  Here's a small example illustrating
 it: 
 
 
 {-# LANGUAGE EmptyDataDecls  #-}
 {-# LANGUAGE FlexibleInstances  #-}
 
 module Monoids where
 import Data.Monoid
 
 data Foo a = Foo Integer deriving (Show, Eq)
 
 data Additive
 data Multiplicative
 
 instance Monoid (Foo Additive) where
 mappend (Foo x) (Foo y) = Foo (x+y)
 mempty = Foo 0
 
 instance Monoid (Foo Multiplicative) where
 mappend (Foo x) (Foo y) = Foo (x*y)
 mempty = Foo 1
 
 instance Num (Foo a) where
 fromInteger x = Foo x
 Foo x + Foo y = Foo (x+y)
 Foo x * Foo y = Foo (x*y)
 signum (Foo x) = Foo (signum x)
 
 
 Loading this into ghci, you get:
 *Monoids mconcat [1,2]
 
 interactive:1:0:
 Ambiguous type variable `t' in the constraints:
   `Monoid t' arising from a use of `mconcat' at interactive:1:0-12
   `Num t' arising from the literal `2' at interactive:1:11
 Probable fix: add a type signature that fixes these type variable(s)
 *Monoids mconcat [1,2::Foo Additive]
 Foo 3
 *Monoids mconcat [1,2::Foo Multiplicative]
 Foo 2
 
 (This can of course be prettified a bit by omitting the constructor
 from the Show instance).  
 
 Any thought about this, pro/contra the newtype method?
 

The old wiki had an excellent page that has not been replicated either
verbatim or in spirit in the new wiki.
http://web.archive.org/web/20060831090007/http://www.haskell.org/hawiki/CommonHaskellIdioms

This lists many small tips and tricks that Haskell programmers have
discovered/used throughout the years.

This particular example is an example of using wrapper types to attach a
phantom type as described here:
http://web.archive.org/web/20070614230306/http://haskell.org/hawiki/WrapperTypes

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


Re: Re[2]: [Haskell-cafe] Comments from OCaml Hacker Brian Hurt

2009-01-22 Thread Derek Elkins
On Thu, 2009-01-22 at 11:32 -0600, Jeremy Shaw wrote:
 Hello,
 
 Just some minor suggestions and comments:
 
 The description might read better as two sentences:
 
A class for monoids with various general-purpose instances. Monoids
are types with an associative binary operation that has an
identity.
 
 One thing that I think is a bit unclear from that description is the
 fact that it does not matter *what* the binary operation does, as long
 as the laws are followed. That is the whole point of the monoid class
 -- you use it when you only care about the laws, not the specific
 operation...
 
 For the laws, it would be nice to label each rule, something like
 
  * mappend mempty x = x -- Left Identity
  * mappend x empty = x  -- Right Identity
  * mappend x (mappend y z) = mappend (mappend x y) z-- Associative


  * mconcat = foldr mappend mempty   -- Not sure what to 
 call this. Perhaps it an axiom?

This is just a definition, both actually and nominally.

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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread John A. De Goes


Not that you're looking to switch editors, but if you want something a  
little more hassle-free:


http://www.n-brain.net/unashots/Haskell/ErrorHighlighting.png

Regards,

John

On Jan 22, 2009, at 10:17 AM, Peter Verswyvelen wrote:


I have a silly problem.

I'm using Emacs with the Haskell mode extension on Windows

I have a source file in say

c:/foo/src/main.hs

main.hs is importing some other modules in that same src directory

When I invoke GHCi from within Emacs, the first thing it does is

:cd c:/foo

and then

:load src/main.hs

But of course GHCi won't find the imported modules now, since the  
current directory is wrong.


If I type in GHCi

:cd src
:load main.hs

then it compiles fine.

Does anyone have an idea why Emacs or the Haskell mode is switching  
to the parent directory of src instead of src itself, and how to fix  
this?


Thanks a lot,
Peter

___
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] Why monoids will abide...

2009-01-22 Thread Tim Newsham

On Thu, 22 Jan 2009, Eugene Kirpichov wrote:

To my mind, in the map-reduce case you generally need a commutative
monoid. Or, you need an extra infrastructure that mappend's only
results from adjacent machines, or something like that.


The paper
   http://www.cs.vu.nl/~ralf/MapReduce/

analyzes the model of Google's MapReduce and Sawzall.  quick haskell 
summaries at:

   http://www.thenewsh.com/~newsham/x/machine/MapReduce.hs
   http://www.thenewsh.com/~newsham/x/machine/Sawzall.hs

The MapReduce model isn't based directly on a monoid, but the Sawzall 
model is.


Tim Newsham
http://www.thenewsh.com/~newsham/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Does readFile /proc/mounts hang for you?

2009-01-22 Thread Gregory Collins
Thomas DuBuisson thomas.dubuis...@gmail.com writes:

 open(/proc/mounts, O_RDONLY|O_NOCTTY|O_NONBLOCK) = 3
 fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
 ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x77470b70) = -1 ENOTTY
 (Inappropriate ioctl for device)

This is to test whether the file is a terminal.

 select(4, [3], [], NULL, {0, 0})= 0 (Timeout)
 select(4, [3], [], NULL, {134, 217727} unfinished ...

Here's the real issue: select() doesn't work on /proc entries (or at
least not that one). Here's a small C program to illustrate the
behaviour:



#include sys/select.h
#include sys/types.h
#include fcntl.h
#include stdio.h

int
main(int argc, char** argv)
{
char*  filename;
intfd;
struct timeval tv;
fd_set read_fds, write_fds;
intretval;

if (argc  2) return 1;

filename = argv[1];

fd = open(filename, O_RDONLY | O_NOCTTY | O_NONBLOCK);

FD_ZERO(read_fds);
FD_SET(fd, read_fds);
FD_ZERO(write_fds);

tv.tv_sec = 0;
tv.tv_usec = 0;

retval = select(fd+1, read_fds, write_fds, NULL, tv);

printf(select() returned %d\n, retval);
printf(FD_ISSET returns %d\n, FD_ISSET(fd, read_fds));
}



Running this program on /proc/mounts shows that select() will never
report it as readable:

~/tmp/select $ gcc -o test_select test_select.c
~/tmp/select $ ./test_select /bin/ls
select() returned 1
FD_ISSET returns 1
~/tmp/select $ ./test_select /proc/mounts 
select() returned 0
FD_ISSET returns 0
~/tmp/select $ 


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


Re[2]: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Bulat Ziganshin
Hello John,

Thursday, January 22, 2009, 8:50:39 PM, you wrote:

thanks, support of over-internet and intranet collaboration looks very
promising these days (even if not saying about ability to highlight error place 
;)

btw, i was unable to download mp4 video from http://vimeo.com/1653402
(online players doesn't work in my browser)

 Not that you're looking to switch editors, but if you want something a
 little more hassle-free:

  http://www.n-brain.net/unashots/Haskell/ErrorHighlighting.png

 Regards,

 John

 On Jan 22, 2009, at 10:17 AM, Peter Verswyvelen wrote:

 I have a silly problem.

 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the  
 current directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching  
 to the parent directory of src instead of src itself, and how to fix  
 this?

 Thanks a lot,
 Peter

 ___
 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


-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

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


Re: Re[2]: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Miguel Mitrofanov

http://depositfiles.com/files/4565hs7vl

On 22 Jan 2009, at 21:14, Bulat Ziganshin wrote:


Hello John,

Thursday, January 22, 2009, 8:50:39 PM, you wrote:

thanks, support of over-internet and intranet collaboration looks very
promising these days (even if not saying about ability to highlight  
error place ;)


btw, i was unable to download mp4 video from http://vimeo.com/1653402
(online players doesn't work in my browser)

Not that you're looking to switch editors, but if you want  
something a

little more hassle-free:



http://www.n-brain.net/unashots/Haskell/ErrorHighlighting.png



Regards,



John



On Jan 22, 2009, at 10:17 AM, Peter Verswyvelen wrote:



I have a silly problem.

I'm using Emacs with the Haskell mode extension on Windows

I have a source file in say

c:/foo/src/main.hs

main.hs is importing some other modules in that same src directory

When I invoke GHCi from within Emacs, the first thing it does is

:cd c:/foo

and then

:load src/main.hs

But of course GHCi won't find the imported modules now, since the
current directory is wrong.

If I type in GHCi

:cd src
:load main.hs

then it compiles fine.

Does anyone have an idea why Emacs or the Haskell mode is switching
to the parent directory of src instead of src itself, and how to fix
this?

Thanks a lot,
Peter

___
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



--
Best regards,
Bulatmailto:bulat.zigans...@gmail.com

___
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] Error in HTTP 4.004 + CouchDB?

2009-01-22 Thread Alex Ott
Hello

(i sent this message to the mail of author, specified at hackage, but it
returned to me, so i decided to resend it here)

I found strange thing during work with latest versions of CouchDB  HTTP
module on my Mac OS X 10.4. The problem is, that when i send document to
the couchdb server, it name was cut to the 2 characters.

After some investigation i found, that this is problem in combination of
the CouchDB + HTTP usage.  CouchDB module fills out the Request structure,
and specify scheme  authority fields.  This lead that i see (in network
dumps) following data:

PUT http://127.0.0.1:5984/test1/Users_ott_tmp_1_tst HTTP/1.1
Content-Type: ...
...
Host: 127.0.0.1:5984
...

instead of proper 

PUT /test1/Users_ott_tmp_1_tst HTTP/1.1

I can eliminate this by explicitly setting of the scheme  authority into
empty values, but this lead to improper creation of the  Host header in
request:

PUT /test1/Users_ott_tmp_1_tst HTTP/1.1
Content-Type: ...
...
Host: 
...

I tried to fix this problem myself, but I'm novice in the industrial
Haskell programming ;-)

P.S. this code from (CouchDB/HTTP.hs) will restore proper behaviour of the
code, but break Host header

makeURL path query = CouchMonad $ \conn - do
  return ( (ccURI conn) { uriPath = '/':path
, uriQuery = if null query then  else 
'?':(urlEncodeVars query)
, uriScheme = 
, uriAuthority = Nothing
}
 ,conn )

-- 
With best wishes, Alex Ott, MBA
http://alexott.blogspot.com/http://xtalk.msk.su/~ott/
http://alexott-ru.blogspot.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANN: STM-IO-Hooks-0.0.1

2009-01-22 Thread Peter Robinson
This library provides an STM monad with commit and retry IO hooks. A
retry-action is run (once) in a separate thread if the transaction retries,
while commit-actions are executed iff the transaction commits. The code is
based on the AdvSTM Monad [1] by Chris Kuklewicz, but in addition also
ensures some atomicity guarantees for commit-actions, see documentation
for details.

Cheers,
Peter

[1] http://www.haskell.org/haskellwiki/New_monads/MonadAdvSTM
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monoids and newtypes

2009-01-22 Thread David Menendez
On Thu, Jan 22, 2009 at 10:11 AM, Ketil Malde ke...@malde.org wrote:

 I was just wondering if not phantom types might serve here as an
 alternative way to go about that.  Here's a small example illustrating
 it:
...
 *Monoids mconcat [1,2::Foo Additive]
 Foo 3
 *Monoids mconcat [1,2::Foo Multiplicative]
 Foo 2

 (This can of course be prettified a bit by omitting the constructor
 from the Show instance).

 Any thought about this, pro/contra the newtype method?

I'm not sure that requiring type annotations is less intrusive than
using a wrapper or an explicit dictionary. But there may be types
where this sort of thing makes sense to do.


My favorite alternative to Monoid uses labeled instances.

data Proxy l   -- empty, to ensure that labels are never examined

class LMonoid label where
type Carrier label :: *
unit :: Proxy label - Carrier label
mult :: Proxy label - Carrier label - Carrier label - Carrier label

data Sum a
sum_ :: Proxy (Sum a)
sum_ = undefined

instance Num a = LMonoid (Sum a) where
type Carrier (Sum a) = a
unit _ = 0
mult _ = (+)

-- this works nicely with the writer monad

data Writer l a = W (Carrier l) a

instance (LMonoid l) = Monad (Writer l) where
return a = W (unit (undefined :: Proxy l)) a
(W o1 a) = f = let W o2 b = f a in W (mult (undefined :: Proxy l) o1 o2) b

tell :: Carrier l - Writer l ()
tell x = W x ()

-- and with Foldable

class Foldable f where
fold :: (LMonoid l) = Proxy l - f (Carrier l) - Carrier l

-- e.g., fold sum_ [1,2,3]

-- and it works well with Monoid

data Std a
instance (Monoid a) = LMonoid (Std a) where
unit _ = mempty
mult _ = mappend

newtype WrapL l = WrapL (Carrier l)

instance LMonoid l = Monoid (WrapL l) where
mempty = WrapL (unit (undefined :: Proxy l))
mappend (Wrap x) (Wrap y) = WrapL (mult (undefined::l) x y)

-- 
Dave Menendez d...@zednenem.com
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Factoring into type classes

2009-01-22 Thread Patai Gergely
Hello again,

 I think that I have done all of the above in different situations, and
 so I don't think that there is a single correct answer.  I usually
 avoid using the newtype trick as I find it inconvenient:  usually
 the newtype does not have the same operations as the underlying type
 and so it cannot be used directly, and if you are going to wrap thing
 just when you use the class methods, then you may as well use the
 non-overloaded operations.
Yes, I had the same thought. If I have to explicitly convert between
various wrappers, that's basically the same as defining separate
functions from the start. The newtype trick is certainly nice when you
don't want to mix the different uses on the same piece of data, but that
was exactly my problem. I'd say your posts as well as wren ng thornton's
answer my question as thoroughly as possible at this point, although
wren's lengthy letter could probably even be extended and turned into a
tutorial on the topic.

Of course type classes are not only important just for making dictionary
passing implicit, but also because of their interactions, which is
nicely demonstrated by the sigfpe blog entry that someone also linked
from this thread. That's probably why I feel kind of uncomfortable when
not taking advantage of standard classes wherever possible.

Thanks for the answers,

Gergely

-- 
http://www.fastmail.fm - Access all of your messages and folders
  wherever you are

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


[Haskell-cafe] Processor availability

2009-01-22 Thread Louis Wasserman
How might I go about finding out how many processors are available in a
concurrent GHC program?  I have some code I'd like to parallelize, but I
don't want to spawn a separate (even lightweight) thread for each of
thousands of minor tasks.

Louis Wasserman
wasserman.lo...@gmail.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Processor availability

2009-01-22 Thread Don Stewart
wasserman.louis:
How might I go about finding out how many processors are available in a
concurrent GHC program?  I have some code I'd like to parallelize, but I
don't want to spawn a separate (even lightweight) thread for each of
thousands of minor tasks.
 
Louis Wasserman
[1]wasserman.lo...@gmail.com

You set the number of OS threads with +RTS -N at runtime. This value
is accessible from Haskell via:

GHC.Conc:

-- | the value passed to the @+RTS -N@ flag.  This is the number of
-- Haskell threads that can run truly simultaneously at any given
-- time, and is typically set to the number of physical CPU cores on
-- the machine.
numCapabilities :: Int

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


Re: [Haskell-cafe] Processor availability

2009-01-22 Thread Thomas DuBuisson
2009/1/22 Louis Wasserman wasserman.lo...@gmail.com:
 How might I go about finding out how many processors are available in a
 concurrent GHC program?  I have some code I'd like to parallelize, but I
 don't want to spawn a separate (even lightweight) thread for each of
 thousands of minor tasks.

Use a thread pool and feed it tasks.  Control.Concurrent.Chan makes a
good queue.

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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Peter Verswyvelen
It's too bad Visual Haskell was not continued, since a free version of the
Visual Studio platform is available now.
I felt Visual Haskell was very promising, like on the fly type inference
with tool tips, code completion, built in Cabal support, etc...


On Thu, Jan 22, 2009 at 6:50 PM, John A. De Goes j...@n-brain.net wrote:


 Not that you're looking to switch editors, but if you want something a
 little more hassle-free:

http://www.n-brain.net/unashots/Haskell/ErrorHighlighting.png

 Regards,

 John


 On Jan 22, 2009, at 10:17 AM, Peter Verswyvelen wrote:

  I have a silly problem.

 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the current
 directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching to the
 parent directory of src instead of src itself, and how to fix this?

 Thanks a lot,
 Peter

 ___
 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] Question about allocaArray and friends

2009-01-22 Thread Patrick Perry
In C, if you try to alloca too much memory, then the stack gets  
overwritten and bad things happen.  Does GHC exhibit the same behavior  
with allocaArray and the like?  Is there a way to find out how much is  
safe to allocate?


Thanks in advance for the help,


Patrick


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


Re: [Haskell-cafe] Question about allocaArray and friends

2009-01-22 Thread Bulat Ziganshin
Hello Patrick,

Friday, January 23, 2009, 1:22:21 AM, you wrote:

 In C, if you try to alloca too much memory, then the stack gets  
 overwritten and bad things happen.  Does GHC exhibit the same behavior
 with allocaArray and the like?  Is there a way to find out how much is
 safe to allocate?

alloca allocs memory in heap, so it should be safe if you are not
going to allocate lots of megabytes. you can use usual binary
division algorithm to find how much you can allocate


-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

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


Re: [Haskell-cafe] Re: GHCi Memory Leak in Windows Vista

2009-01-22 Thread Duncan Coutts
On Tue, 2009-01-20 at 10:22 +, Gracjan Polak wrote:
 Same here:
 
 Vista, GHC 6.8.3
 
 Tested a bit changed scenario: instead of 20 separate compilations it is
 worthwhile to run single, longer build, e.g. ghc --make of same package.
 
 Seems like GHCi does not run garbage collection when machine is busy. And then
 it accumulates memory. This renders Vista totally unresponsive and even can 
 lead
 to automatic reboot (happened once to me).

Did either of you file a ghc ticket about this issue?

Does the same happen with 6.10 ?

Duncan

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


Re: [Haskell-cafe] Big endian vs little endian in Haskell land?

2009-01-22 Thread Galchin, Vasili
Hi Tom,

 What is an example of some software in Hackage that reads/writes things
like integers to persistent store ... i.e. where endian-ness is an issue?

Regards, Vasili

On Thu, Jan 22, 2009 at 7:24 AM, Thomas DuBuisson 
thomas.dubuis...@gmail.com wrote:

 Sure, I've had to deal with this frequently.  Luckily, Data.Binary has
 functions like getWord32be, putWord64le, etc.  I've never had any
 problems and typically don't worry about the wire format after making
 the Binary instances.

 Or, if your question was what types of programs might be concerned you
 can include any program that writes data to a file where the file
 might be read on a different system and networking programs,
 obviously.

 Tom

 2009/1/22 Galchin, Vasili vigalc...@gmail.com:
  Hello,
 
  Are there applications that have to deal with both(!!!) big
 endian
  and little endian on persistent store?? I.e. when marshalling out and
  unmarshalling in endian-ness has to be considered??
 
  Regards, Vasili
 
  ___
  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] Processor availability

2009-01-22 Thread Sebastian Sylvan
2009/1/22 Louis Wasserman wasserman.lo...@gmail.com

 How might I go about finding out how many processors are available in a
 concurrent GHC program?  I have some code I'd like to parallelize, but I
 don't want to spawn a separate (even lightweight) thread for each of
 thousands of minor tasks.


Consider using Contorl.Parallel.Strategies which allows you to spark of
lightweight jobs that get run on a pool of threads.


-- 
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: how to implement daemon start and stop directives?

2009-01-22 Thread Ertugrul Soeylemez
Luke Palmer lrpal...@gmail.com wrote:

 On Thu, Jan 22, 2009 at 9:04 AM, Ertugrul Soeylemez e...@ertes.de wrote:

  Sometimes this is inevitable, but I've never seen a case, where
  IORefs couldn't be replaced by a more elegant State/StateT-based
  solution.  And if you need to do multi-threading, Chans, MVars and
  semaphores are better anyway.

 Please define better.  For the function in question, what advantages
 do they give us?

It gives you thread-safety for free, which IORefs don't give you.  It's
the same purpose, the same amount of code, but threadsafe by concept.
Of course, for simple variables, IORefs will likely be thread-safe as
well, but there is no guarantee here.  With MVars you have that
guarantee.


 Just to be clear, I wouldn't dare argue that IORefs can do everything
 MVars and TVars can do.  I'm just perplexed why you say MVars and
 TVars are better, when an IORef does the trick just fine for our
 function.

What I'm saying is:  Even if IORefs suffice, why would you want to use
them, if MVar does the job as well and likely better?


  There is no reason to prefer an IORef over an MVar to signal
  something to another thread.

 Well, I usually don't go here, but benchmarks show that IORefs are the
 fastest of any of the mutable variable primitives, by at least a
 factor of 2.  I wish I remembered where I saw that.

Yes, that's a good point, but I think, you can safely disregard that for
signalling a thread to quit.


  By the way, IORefs are by themselves not thread-safe.  You need to
  use a special function, when using it in a multi-threaded manner.

 You mean atomicModifyIORef?

Yes.


 IORefs *are* thread-safe by themselves: you will not make your program
 segfault by using them in a multithreaded program.  So it all comes
 down to invariants.  IORefs have no synchronization concepts, so code
 like:

 x - readIORef ref
 writeIORef ref (x+1)

 Is not threadsafe by most standards.  That doesn't mean IORefs
 themselves are not threadsafe, just that you have to be careful how
 you use them.

That's exactly my point.  In the above case they do just the same, but
need more care.


 And I will reiterate:  *in this case* the use of IORef is fully
 encapsulated in this function and *is threadsafe!* Which is the basis
 of my argument: in imperative code, when you can limit the scope of an
 IORef to a small abstraction that is threadsafe, there is no advantage
 of TVars or MVars over them.  I don't think they deserve bad style
 sledgehammer.  (An instance of use the right tool for the job)

 daemon :: IO () - IO (IO ())
 daemon action = do
 stopvar - newIORef False
 let run = do
   stop - readIORef stopvar
   if stop then return () else (action  run)
 forkIO run
 return (writeIORef stopvar True)

In this case, it's simply a coincidence that it's safe.  It's because
you're using an IORef Bool, and because writes to a Bool variable are
atomic on virtually all platforms.  An Integer may already fail to be
thread-safe.  You need more care and the payoff is zero.  If you still
insist on using IORefs, at least use the atomic function above, but that
destroys the little performance benefit of using IORefs, unless GHC does
some intelligent optimization here, which I doubt.


Greets,
Ertugrul.


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://blog.ertes.de/


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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Andrew Wagner
Hmm, strange. This doesn't appear to fix my problem. Perhaps I have
something bigger broken locally :(

On Thu, Jan 22, 2009 at 12:44 PM, Peter Verswyvelen bugf...@gmail.comwrote:

 indeed, that works! the comment above those lines is:
 ;; Not sure if it's useful/needed and if it actually works.

 :-)

 On Thu, Jan 22, 2009 at 6:41 PM, Miguel Mitrofanov 
 miguelim...@yandex.ruwrote:

 On my Mac I've had the same problem. Commenting out lines

  (unless (equal default-directory root)
(setq default-directory root)
(inferior-haskell-send-command
 proc (concat :cd  default-directory)))

 solved it for me.



 On 22 Jan 2009, at 20:23, Andrew Wagner wrote:

  Interesting. I have a similar, but worse problem. For me, ':load'ing
 main.hs would fail to find the imported files. The only thing I appear to be
 able to :load is files that don't import from local directories.

 2009/1/22 Peter Verswyvelen bugf...@gmail.com
 I have a silly problem.

 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the current
 directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching to
 the parent directory of src instead of src itself, and how to fix this?

 Thanks a lot,
 Peter


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


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




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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-22 Thread Peter Verswyvelen
After emacs started your GHCi session, when you manually type
:cd the full path of the directory of your Main.hs
:load Main.hs

Does it work then?

Can you use GHCi from outside Emacs?


On Fri, Jan 23, 2009 at 1:09 AM, Andrew Wagner wagner.and...@gmail.comwrote:

 Hmm, strange. This doesn't appear to fix my problem. Perhaps I have
 something bigger broken locally :(


 On Thu, Jan 22, 2009 at 12:44 PM, Peter Verswyvelen bugf...@gmail.comwrote:

 indeed, that works! the comment above those lines is:
 ;; Not sure if it's useful/needed and if it actually works.

 :-)

 On Thu, Jan 22, 2009 at 6:41 PM, Miguel Mitrofanov miguelim...@yandex.ru
  wrote:

 On my Mac I've had the same problem. Commenting out lines

  (unless (equal default-directory root)
(setq default-directory root)
(inferior-haskell-send-command
 proc (concat :cd  default-directory)))

 solved it for me.



 On 22 Jan 2009, at 20:23, Andrew Wagner wrote:

  Interesting. I have a similar, but worse problem. For me, ':load'ing
 main.hs would fail to find the imported files. The only thing I appear to 
 be
 able to :load is files that don't import from local directories.

 2009/1/22 Peter Verswyvelen bugf...@gmail.com
 I have a silly problem.

 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the
 current directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching to
 the parent directory of src instead of src itself, and how to fix this?

 Thanks a lot,
 Peter


 ___
 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] Employment

2009-01-22 Thread Andrew Coppin

Jonathan Cast wrote:

On Mon, 2009-01-19 at 21:04 +, Andrew Coppin wrote:
  
I mean, heck, *I* use Haskell at work - and I'm not even supposed to be 
coding things!



/me feels slightly relieved, if you'll forgive my saying so :)


Damn... I didn't think I was *that* bad at using Haskell? o_O


Also, if you don't mind my asking, what *is* your job title?
  


Technically, system administrator. An equally valid description might 
be the whole computer department.


But in reality, my job involves swapping the backup tapes each day, and 
rebooting people's computers when Word crashes. Obviously, I'd like to 
be doing something a *tad* more interesting. (Not to mention better 
paid...!)


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


Re: [Haskell-cafe] Employment

2009-01-22 Thread Andrew Coppin

Paul Johnson wrote:
So next time I hear the you can't get the programmers line I'm going 
to respond with something like this:


   If you post an advert for a Haskell developer you will get 20
   applicants.  All of those people will be the kind of developer who
   learns new programming languages to improve their own abilities and
   stretch themselves, because nobody yet learns Haskell just to get a 
job.


   If you post an advert for a Java developer you will get 200
   applicants.  Most of them will be the kind of developer who learned
   Java because there are lots of Java jobs out there, and as long as
   they know enough to hold down a job then they see no reason to learn
   anything.


If this isn't an elevator pitch for using Haskell then I don't know 
what the hell *is*!


Seriously, this is a pretty damned persuasive argument...

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


Re: [Haskell-cafe] Elevator pitch for functional programming

2009-01-22 Thread Andrew Coppin

Jim Burton wrote:

Parallelism! Something based on dons' blog
http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking-4core will be a
good start.
  


+3

Ever tried to do anything like this in Java?

Even Smalltalk makes it relatively hard compared to Haskell's 
parallelism primitives. (I do *mean* parallelism, not concurrency - 
although Haskell does that pretty damned impressively too...)


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


Re: [Haskell-cafe] Employment

2009-01-22 Thread Jonathan Cast
On Tue, 2009-01-20 at 21:01 +, Andrew Coppin wrote:
 Paul Johnson wrote:
  So next time I hear the you can't get the programmers line I'm going 
  to respond with something like this:
 
 If you post an advert for a Haskell developer you will get 20
 applicants.  All of those people will be the kind of developer who
 learns new programming languages to improve their own abilities and
 stretch themselves, because nobody yet learns Haskell just to get a 
  job.
 
 If you post an advert for a Java developer you will get 200
 applicants.  Most of them will be the kind of developer who learned
 Java because there are lots of Java jobs out there, and as long as
 they know enough to hold down a job then they see no reason to learn
 anything.
 
 If this isn't an elevator pitch for using Haskell then I don't know 
 what the hell *is*!
 
 Seriously, this is a pretty damned persuasive argument...

Not really.  My company *advertises* for Haskell developers, and then
when they come in to interview, informs them that the code base is
actually written in Perl.  Works, too --- we have several Haskellers
working here.  If all you care about is the quality of the developers,
and not their productivity once you've got them, you don't actually need
to let them use Haskell after the interview is over...

jcc


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


Re: [Haskell-cafe] Employment

2009-01-22 Thread Jonathan Cast
On Tue, 2009-01-20 at 19:14 +, Andrew Coppin wrote:
 Jonathan Cast wrote:
  On Mon, 2009-01-19 at 21:04 +, Andrew Coppin wrote:

  I mean, heck, *I* use Haskell at work - and I'm not even supposed to be 
  coding things!

  /me feels slightly relieved, if you'll forgive my saying so :)

 Damn... I didn't think I was *that* bad at using Haskell? o_O

You have expressed continued bafflement on any number of subjects that
have been repeatedly explained to you, so yes.

  Also, if you don't mind my asking, what *is* your job title?

 Technically, system administrator. An equally valid description might 
 be the whole computer department.

 But in reality, my job involves swapping the backup tapes each day, and 
 rebooting people's computers when Word crashes. Obviously, I'd like to 
 be doing something a *tad* more interesting. (Not to mention better 
 paid...!)

Ah, you poor thing.  No *wonder* you're driven to coding!

jcc


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


Re: [Haskell-cafe] Employment

2009-01-22 Thread Andrew Wagner
That's..evil

On Thu, Jan 22, 2009 at 7:56 PM, Jonathan Cast jonathancc...@fastmail.fmwrote:

 On Tue, 2009-01-20 at 21:01 +, Andrew Coppin wrote:
  Paul Johnson wrote:
   So next time I hear the you can't get the programmers line I'm going
   to respond with something like this:
  
  If you post an advert for a Haskell developer you will get 20
  applicants.  All of those people will be the kind of developer who
  learns new programming languages to improve their own abilities and
  stretch themselves, because nobody yet learns Haskell just to get a
   job.
  
  If you post an advert for a Java developer you will get 200
  applicants.  Most of them will be the kind of developer who learned
  Java because there are lots of Java jobs out there, and as long as
  they know enough to hold down a job then they see no reason to learn
  anything.
 
  If this isn't an elevator pitch for using Haskell then I don't know
  what the hell *is*!
 
  Seriously, this is a pretty damned persuasive argument...

 Not really.  My company *advertises* for Haskell developers, and then
 when they come in to interview, informs them that the code base is
 actually written in Perl.  Works, too --- we have several Haskellers
 working here.  If all you care about is the quality of the developers,
 and not their productivity once you've got them, you don't actually need
 to let them use Haskell after the interview is over...

 jcc


 ___
 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] Moving nobench towards HaBench

2009-01-22 Thread Andy Georges

Hello,


A while back, we had a discussion on #haskell about assembling a  
Haskell benchmark suite, that is suitable for doing performance tests.  
A preliminary page was erected athttp://www.haskell.org/haskellwiki/HaBench 
. In the meantime, Donald Steward extended the original nofib suite  
with some shootout benchmarks afaik, resulting in nobench. The code  
base for the latter currently resides at http://code.haskell.org/nobench/ 
.


I have been trying to get it running on GHC 6.10.1. For now, I added a  
number of type definitions to the code, causing the build/runtime  
system to compile. The same probably ought to be done for the  
benchmarks themselves, unless there is a cheat around this using some  
language extension. Anyhow, I'll post a patch against the current  
repository as soon as I have a number of benchmarks running.


The main issue that still remains is the availability of real life  
benchmarks. I agree with the fact that micro-benchmarks can be useful  
for testing purposes or measures the efficacy and effectiveness of  
certain optimisations, yet I firmly believe any community has need of  
a set of benchmarks that actually reflects the real life usage of the  
language. I am think along the lines of something alike to the DaCapo  
projects, which assembled a number of very good benchmarks for the  
Java language and its VM. So the question basically boils down to  
this. Is there anybody interested in making the move toward HaBench,  
and if so, do you know of real life benchmarks that can serve for this  
exact purpose?


The benchmarks should preferably execute for  10s on modern machines,  
using a decent amount of RAM (say somewhere between 50 and 500MB),  
thus exercising all parts of a modern computing system. The code  
should not be trivial and the set of benchmarks should eventually  
cover the most uses of Haskell in the industry. Of course, the  
benchmarks themselves should be open source. If possible, they should  
come with multiple inputs, allowing a short (test) run as well as  
longer measurement runs.



If you are able and willing to help out, drop by at the HaBench page  
and drop a line,



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


Re: [Haskell-cafe] Employment

2009-01-22 Thread Jonathan Cast
On Thu, 2009-01-22 at 20:02 -0500, Andrew Wagner wrote:
 That's..evil

I know.  I'm evil too, though.  So it's cool.

jcc


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


Re: [Haskell-cafe] Employment

2009-01-22 Thread Toby Hutton
On Fri, Jan 23, 2009 at 11:56 AM, Jonathan Cast
jonathancc...@fastmail.fm wrote:

 Not really.  My company *advertises* for Haskell developers, and then
 when they come in to interview, informs them that the code base is
 actually written in Perl.  Works, too --- we have several Haskellers
 working here.  If all you care about is the quality of the developers,
 and not their productivity once you've got them, you don't actually need
 to let them use Haskell after the interview is over...

I saw this trick recently for a job advertised locally to me, in
Melbourne.  I was initially pretty excited that someone in this city
was actually advertising for Haskell programmers, until I realised
they needed to be good at Javascript and Perl so they could work on
their web apps.  Argh, I didn't bother applying.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] MySQL and HDBC?

2009-01-22 Thread Galchin, Vasili
Hello,

 Real World Haskell seems to say that the abstraction layer HDBC
doesn't support MySQL. If so, in what sense doesn't HDBC support
MySQL??

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


Re: [Haskell-cafe] Re: GHCi Memory Leak in Windows Vista

2009-01-22 Thread Alexandr N. Zamaraev

Duncan Coutts wrote:

Does the same happen with 6.10 ?

Yes. In 6.10.1 also leak.

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


[Haskell-cafe] Is it possible to model eventually consistent side effects?

2009-01-22 Thread Daryoush Mehrtash
I am trying to figure out if there is a way to model cloud computing
computations in Haskell.

My specific problems is that in   cloud computing, as in Amazon
WebServices,  side effects (writes to storage,  simple database, queue)
follow the eventually consistent model.  Which means even if your writes
succeeds, it may or may not be immediately available for reads.  Each call
to the services may also temporarily experience network errors or end-system
unavailability.   Virtual machines can mount a local disk that does offers
consistent storage, but the storage wont survive a reboot (after a crash).

I am trying to find out if I can model computation (and its compositions)
where I can hide reliability and consistency issues. And also be able to
reason about a computation to make sure no combination of errors and
inconsistencies would break my logic.

Is it possible?  If so is there a good starting point?

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


Re: [Haskell-cafe] Error in HTTP 4.004 + CouchDB?

2009-01-22 Thread Sigbjorn Finne

Thanks Alex,

contacting the maintainer of a package rather than author is probably
the best course of action in general. They may both be out of date,
but the former maybe less so. :)

As verified offline, you issue this request via sendHTTP when experiencing
this misbehavior.

A couple of suggestions on what to do:

* Use Network.Browser instead and send it via (browse $ request req),
   which will normalize the path and Host: headers as you expect for 
(non-proxy)

   use.
* pull down the latest bits from the repository and normalize your request
   prior to calling sendHTTP by using

(Network.HTTP.Base.normalizeRequest False{-no proxy-} req)

   (we're in a tight spot wrt. backwards compatibility for sendHTTP, so 
having
it perform this normalization step by default would break code that 
now interacts

   with proxies via sendHTTP.)

The repository version also has support for custom request verbs, which 
might be

of interestuse to some.

Let me know how it goes -- git repository URL available via 
http://projects.haskell.org/http/


hth
--sigbjorn


On 1/22/2009 11:32, Alex Ott wrote:

Hello

(i sent this message to the mail of author, specified at hackage, but it
returned to me, so i decided to resend it here)

I found strange thing during work with latest versions of CouchDB  HTTP
module on my Mac OS X 10.4. The problem is, that when i send document to
the couchdb server, it name was cut to the 2 characters.

After some investigation i found, that this is problem in combination of
the CouchDB + HTTP usage.  CouchDB module fills out the Request structure,
and specify scheme  authority fields.  This lead that i see (in network
dumps) following data:
  




I tried to fix this problem myself, but I'm novice in the industrial
Haskell programming ;-)

P.S. this code from (CouchDB/HTTP.hs) will restore proper behaviour of the
code, but break Host header

makeURL path query = CouchMonad $ \conn - do
  return ( (ccURI conn) { uriPath = '/':path
, uriQuery = if null query then  else 
'?':(urlEncodeVars query)
, uriScheme = 
, uriAuthority = Nothing
}
 ,conn )

  


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