[Haskell-cafe] trying to understand monad transformers....

2008-09-09 Thread Daryoush Mehrtash
The MaybeT transformer is defined as:

newtype MaybeT m a = MaybeT {runMaybeT :: m (Maybe
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Maybe
a)}

instance Functor
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Functor
m = Functor 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Functor
(MaybeT m) where
  fmap 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap
f x = MaybeT $ 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.
fmap 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap
(fmap 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap
f) $ http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.
runMaybeT x




Question:  What does runMaybeT x mean?


Thanks,

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


Re: [Haskell-cafe] trying to understand monad transformers....

2008-09-09 Thread Magnus Therning
2008/9/9 Daryoush Mehrtash [EMAIL PROTECTED]:
 The MaybeT transformer is defined as:

 newtype MaybeT m a = MaybeT {runMaybeT :: m (Maybe a)}


 instance Functor m = Functor (MaybeT m) where

   fmap f x = MaybeT $ fmap (fmap f) $ runMaybeT x


 

 Question:  What does runMaybeT x mean?

If you mean what does it do? then the answer is that it unwraps the
MaybeT so that you can get to the inner value.  If you mean how does
it do it? then I believe the best thing is to read some of the
chapters in RWH because I think I recognise a rather common
Haskell-pattern here.  I don't remember which ones, but I'm sure
others on this list have better memory than I do ;-)

If this isn't what you were looking for, then I haven't understood the
question :-)

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


Re: [Haskell-cafe] haskell job offer.

2008-09-09 Thread Lionel Barret De Nazaris

Thank you for the warm welcome.

About the use of Haskell, it will be for our (urban) rule-based 
generation engines (there is a recursive stack of them).

Think about a declarative geographic compiler and you're on the right track.

This engines are not in Haskell right now but it *should* be because for 
it we have reproduced many Haskell features (monads, lazy evaluation and 
so on).

Greenspun's Tenth Rule (for Haskell) is really at work there.

The first task on the job will be to port one of the engine. But this is 
only the tip of the iceberg...


The final goal is to generate in real time an infinite city with as much 
detail as the current top games.

And, obviously, to able to create that in an afternoon :).

So you see, there is many interesting things to do.

-- Lionel

--
Best Regards,
lionel Barret de Nazaris,
Gamr7 Founder  CTO
=
Gamr7 : Cities for Games
http://www.gamr7.com




Don Stewart wrote:

And for those who didn't see the original release announcement, check
out their website..

http://gamr7.com/

That's kind of awesome. Could you say more about what you're using
Haskell for, Lionel?

-- Don

dons:
  

Welcome to the community!

I've added details about Gamr7 to the industry page,

http://haskell.org/haskellwiki/Haskell_in_industry

-- Don

lionel:

We (Gamr7, see at the bottom) are looking from a senior dev/Technical 
director.
We don't really care about the title but we want someone good (who 
doesn't ?).
We need someone able to model *and* code well (No architect who never 
codes).

The ability to communicate well with a team is also a big plus.
You don't need to speak French (we are in France) but a reasonably good 
English is mandatory.


If You :
• like coding 4+ hours straight.
• like to solve a coding problem elegantly (and are bothered if can't)
• like and read *real* CS books (SICP, EGB, TAOCP, etc...)
• code in Haskell, python and c++.
• are a gamer (this one is optional)
• are interested in computer graphics (optional too)

You fit the bill. We would like to talk to you. Contact us (contact at 
gamr7 dot com).



What we offer:
• interesting problems and creative freedom
• quality of life (no overtime, sunny countryside, French food and low 
rent)

• a pay in Euros
• comfortable workplace, etc...
• coding in Haskell, python.

The boss *really * codes . He likes Haskell, Python, Reddit, and wants 
the team to be there for the long run (i.e happy).

He also modestly wrote and posted this jobs offer.

About :
Gamr7 is a startup focused on procedural city generation for the game 
and simulation market.

We are located in France, near Lyon.

--
Best Regards,
lionel Barret de Nazaris,
Gamr7 Founder  CTO
=
Gamr7 : Cities for Games
http://www.gamr7.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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] trying to understand monad transformers....

2008-09-09 Thread Ryan Ingram
2008/9/8 Daryoush Mehrtash [EMAIL PROTECTED]:
 The MaybeT transformer is defined as:

  newtype MaybeT m a = MaybeT {runMaybeT :: m (Maybe a)}

 Question:  What does runMaybeT x mean?

This is just shorthand for the following:

 newtype MaybeT m a = MaybeT (m (Maybe a))
 runMaybeT :: MaybeT m a - m (Maybe a)
 runMaybeT (MaybeT x) = x

(with some minor differences to automated deriving of Show instances)

At runtime, runMaybeT and MaybeT are just really fast identity
functions (they should get optimized out of existence, even!)

So, if you have x :: MaybeT m a at runtime, you really just have
runMaybeT x :: m (Maybe a)

 instance Functor m = Functor (MaybeT m) where
   fmap f x = MaybeT $ fmap (fmap f) $ runMaybeT x

This code is a bit confusing at first because each fmap is at a different type.

The first (in the function declaration) is
 fmap :: Functor m = (a - b) - MaybeT m a - MaybeT m b

The second (*fmap* (fmap f)) is
 fmap :: Functor m = (Maybe a - Maybe b) - m (Maybe a) - m (Maybe b)

The third (fmap (*fmap* f)) is
 fmap :: (a - b) - Maybe a - Maybe b

When you work with functors a lot you start to be able to read this
stuff more easily.

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


Re: [Haskell-cafe] STM and FFI

2008-09-09 Thread Ryan Ingram
What are you trying to do?

(1) Call a foreign function from inside an STM transaction?

If the function is pure, this is trivial, just declare it as a pure
function in the foreign import statement.  You do need to be a bit
careful, however, as it is possible the function will get called with
invalid arguments, and I believe that GHC won't interrupt a thread
inside of a foreign function call.  So you need to make sure that the
function never fails to terminate, even when given bad input.
(There's an example code being called with improper arguments in
Simon's STM paper).

If the function isn't pure, you need to do a lot more proofs to assure
that this is safe.  In particular, the function must be able to be
called with invalid input.  If you are confident that this is the
case, you can use unsafeIOToSTM to convert a call to that function
into an STM primitive.

(2) Have a foreign function use transactional memory primitives?

I'm not sure that this is possible.

(3) something else?

  -- ryan

On Mon, Sep 8, 2008 at 2:56 PM, Mauricio [EMAIL PROTECTED] wrote:
 Hi,

 Is it possible to use foreign function
 interface with STMs? If so, where can I
 find examples?

 Thanks,
 Maurício

 ___
 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 and Java

2008-09-09 Thread Maurí­cio

Hi,

I use Haskell, and my friends at
work use Java. Do you think it
could be a good idea to use Haskell
with Java, so I could understand
and cooperate with them? Is there a
a Haskell to Java compiler that's
already ready to use?

Thanks,
Maurício

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


Re: [Haskell-cafe] STM and FFI

2008-09-09 Thread Arnar Birgisson
On Tue, Sep 9, 2008 at 11:36, Jules Bean [EMAIL PROTECTED] wrote:
 ...not only must it be safe to be called with invalid inputs, but it most
 not have any long-term effects, whether the input is valid or invalid, since
 I do not believe that there is any way for the function to 'undo' its effect
 at 'retry' time.

Maybe this is an idea for an extension to the STM system, adding
something like unsafeIOToSTM, except that in addition to the main IO
action, it also takes two more IO actions that are invoked on rollback
and commit, respectively.

This might allow for integration with transactional systems (e.g. a
remote transaction on an rdbms), although to support two-phased commit
we'd need a third action for the prepare step.

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


Re: [Haskell-cafe] STM and FFI

2008-09-09 Thread Jules Bean

Arnar Birgisson wrote:

On Tue, Sep 9, 2008 at 11:36, Jules Bean [EMAIL PROTECTED] wrote:

...not only must it be safe to be called with invalid inputs, but it most
not have any long-term effects, whether the input is valid or invalid, since
I do not believe that there is any way for the function to 'undo' its effect
at 'retry' time.


Maybe this is an idea for an extension to the STM system, adding
something like unsafeIOToSTM, except that in addition to the main IO
action, it also takes two more IO actions that are invoked on rollback
and commit, respectively.

This might allow for integration with transactional systems (e.g. a
remote transaction on an rdbms), although to support two-phased commit
we'd need a third action for the prepare step.


That would be an absolutely killer feature.

A common problem in large systems is that the underlying RDBMS supports 
transactionality, but then the software layer has to handle its own 
rollbacks. I've seen some nasty bugs when the DB rolled back and the 
software didn't.


If we could have a transactional RDBMS linked into STM with matching 
semantics, that would be a very nice thing.


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


Re: [Haskell-cafe] STM and FFI

2008-09-09 Thread Arnar Birgisson
On Tue, Sep 9, 2008 at 11:58, Jules Bean [EMAIL PROTECTED] wrote:
 Maybe this is an idea for an extension to the STM system, adding
 something like unsafeIOToSTM, except that in addition to the main IO
 action, it also takes two more IO actions that are invoked on rollback
 and commit, respectively.

 This might allow for integration with transactional systems (e.g. a
 remote transaction on an rdbms), although to support two-phased commit
 we'd need a third action for the prepare step.

 That would be an absolutely killer feature.

 A common problem in large systems is that the underlying RDBMS supports
 transactionality, but then the software layer has to handle its own
 rollbacks. I've seen some nasty bugs when the DB rolled back and the
 software didn't.

 If we could have a transactional RDBMS linked into STM with matching
 semantics, that would be a very nice thing.

I think this is entirely doable. For comparison we already have done
this with another STM framework, the DSTM2 library for Java. I.e. we
hooked into prepare, commit and rollback and integrated with both
MySQL transactions and a transactional file system library from Apache
Commons.

I'm not yet involved enough with the GHC library code, but I guess
this would require the addition of a prepare phase to the STM code.

There's also the question of what to do when the remote TX system
indicates failure, should the transaction be retried or aborted? In
the DSTM2 case we make it abort and throws an exception encapsulating
the remote error to the code that initiated the TX (in Haskell's case,
the caller of atomically).

On a related note, we do have a paper on utilizing the STM system for
authorization and policy enforcement in general. The paper is to be
presented at CCS'08, and has an implementation on top of DSTM2, but we
have a technical report in the works that implements this on top of
the Haskell STM and gives operational semantics for the whole thing.

You can find the conference paper on my website:
http://www.hvergi.net/arnar/publications

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


Re: [Haskell-cafe] Haskell and Java

2008-09-09 Thread C.M.Brown
Hi,

The only thing I can think of is GCJNI:

http://www.haskell.org/gcjni/

This makes use of the FFI and a Greencarded Java JNI interface. It does
allow you to call Java programs from Haskell. However, I'm not sure if it
is still supported.

hth,
Chris.


On Tue, 9 Sep 2008, [ISO-8859-1] Maurí­cio wrote:

 Hi,

 I use Haskell, and my friends at
 work use Java. Do you think it
 could be a good idea to use Haskell
 with Java, so I could understand
 and cooperate with them? Is there a
 a Haskell to Java compiler that's
 already ready to use?

 Thanks,
 Maurício

 ___
 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] Can you do everything without shared-memory concurrency?

2008-09-09 Thread Sebastian Sylvan
On Mon, Sep 8, 2008 at 8:33 PM, Bruce Eckel [EMAIL PROTECTED] wrote:

 As some of you on this list may know, I have struggled to understand
 concurrency, on and off for many years, but primarily in the C++ and
 Java domains. As time has passed and experience has stacked up, I have
 become more convinced that while the world runs in parallel, we think
 sequentially and so shared-memory concurrency is impossible for
 programmers to get right -- not only are we unable to think in such a
 way to solve the problem, the unnatural domain-cutting that happens in
 shared-memory concurrency always trips you up, especially when the
 scale increases.

 I think that the inclusion of threads and locks in Java was just a
 knee-jerk response to solving the concurrency problem. Indeed, there
 were subtle threading bugs in the system until Java 5. I personally
 find the Actor model to be most attractive when talking about
 threading and objects, but I don't yet know where the limitations of
 Actors are.

 However, I keep running across comments where people claim they must
 have shared memory concurrency. It's very hard for me to tell whether
 this is just because the person knows threads or if there is truth to
 it.


For correctness, maybe not, for efficiency, yes definitely!

Imagine a program where you have a huge set of data that needs to be
modified (in some sense) over time by thousands of agents. E.g. a game
simulation.
Now, also imagine that every agent could *potentially* modify every single
piece of data, but that every agent *typically* only touches two or three
varibles here and there. I.e. the collisions between the potential
read/write sets is 100%, while the collisions for the actual read/write sets
is very very low.

How would you do this with threads and message passing? Well you could have
one big thread owning all of your data that takes update messages, and
then updates the world for you (immutably if you wish, by just replacing
its world variable with a new one containing your update), but now you've
effectively serialized all your interactions with the world, so you're not
really concurrent anymore!

So you could decompose the world into multiple threads using some
application-specific logical sudivision, but then you're effectively just
treating each thread as a mutable variable with an implicit lock (with the
risks of deadlock that comes with it - remember we don't know the read/write
set in advance - it could be the entire world - so we can't just order our
updates in some global way here), so you're really just doing shared mutable
state again, and gain little from having threads simulate your mutable
cells...

What you really need for this is some way for each agent to update this
shared state *in parallel*, without having to block all other agents
pessimistically, but instead only block other agents if there was an
*actual* conflict. STM seems to be the only real hope for that sort of thing
right now.
IMO my list of preferred methods goes like this:
1. Purely functional data parallelism
2. Purely functional task parallelism (using e.g. strategies)
3. Message passing with no (or very minimal) shared state (simulated using
threads as data servers or otherwise)
(3.5. Join patterns? Don't have enough experience with this, but seems sort
of nice?)
4. Shared state concurrency using STM
5. Shared state concurrency using locks
6. Lockless programming.

So while I wouldn't resort to any shared state concurrency unless there are
good reasons for why the other methods don't work well (performance is a
good reason!), there are still situations where you need it, and a general
purpose language had better supply a way of accessing those kinds of
facilities.

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


Re: [Haskell-cafe] STM and FFI

2008-09-09 Thread Jules Bean

Ryan Ingram wrote:

If the function isn't pure, you need to do a lot more proofs to assure
that this is safe.  In particular, the function must be able to be
called with invalid input.  If you are confident that this is the
case, you can use unsafeIOToSTM to convert a call to that function
into an STM primitive.


...not only must it be safe to be called with invalid inputs, but it 
most not have any long-term effects, whether the input is valid or 
invalid, since I do not believe that there is any way for the function 
to 'undo' its effect at 'retry' time.


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


Re: [Haskell-cafe] STM and FFI

2008-09-09 Thread Sterling Clover
I've been playing with this, and on top of STM as it exists, managed  
to neatly interleave it with sqite3 and postgres. To do so with  
postgres, however, required setting the locking mode to be a bit more  
restrictive than it is out-of-the-box. Clever use of encapsulation  
and monad transformers gets you 90% of the way there quite easily.  
Note, however, that unsafeIOToSTM is *much* more unsafe at the moment  
than you would expect -- in fact there is no safe way to use it at  
all, due to the interaction of exceptions and rollbacks at the  
moment. The thread about this on glasgow-haskell-users[1], along with  
my initial note, has a very useful reply by Simon Marlow where he  
both explains some things about the STM implementation and logic  
behind it that I didn't understand, and also describes how the GHC  
team intends to fix this at some point in the future.


Regards,
Sterl.

[1] http://www.nabble.com/Where-STM-is-unstable-at-the-moment%2C-and- 
how-we-can-fix-it-tc19236082.html#a19236082



On Sep 9, 2008, at 6:08 AM, Arnar Birgisson wrote:

On Tue, Sep 9, 2008 at 11:58, Jules Bean [EMAIL PROTECTED]  
wrote:

Maybe this is an idea for an extension to the STM system, adding
something like unsafeIOToSTM, except that in addition to the main IO
action, it also takes two more IO actions that are invoked on  
rollback

and commit, respectively.

This might allow for integration with transactional systems (e.g. a
remote transaction on an rdbms), although to support two-phased  
commit

we'd need a third action for the prepare step.


That would be an absolutely killer feature.

A common problem in large systems is that the underlying RDBMS  
supports

transactionality, but then the software layer has to handle its own
rollbacks. I've seen some nasty bugs when the DB rolled back and the
software didn't.

If we could have a transactional RDBMS linked into STM with matching
semantics, that would be a very nice thing.


I think this is entirely doable. For comparison we already have done
this with another STM framework, the DSTM2 library for Java. I.e. we
hooked into prepare, commit and rollback and integrated with both
MySQL transactions and a transactional file system library from Apache
Commons.

I'm not yet involved enough with the GHC library code, but I guess
this would require the addition of a prepare phase to the STM code.

There's also the question of what to do when the remote TX system
indicates failure, should the transaction be retried or aborted? In
the DSTM2 case we make it abort and throws an exception encapsulating
the remote error to the code that initiated the TX (in Haskell's case,
the caller of atomically).

On a related note, we do have a paper on utilizing the STM system for
authorization and policy enforcement in general. The paper is to be
presented at CCS'08, and has an implementation on top of DSTM2, but we
have a technical report in the works that implements this on top of
the Haskell STM and gives operational semantics for the whole thing.

You can find the conference paper on my website:
http://www.hvergi.net/arnar/publications

cheers,
Arnar
___
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] packages and QuickCheck

2008-09-09 Thread Conal Elliott
How do folks like to package up QuickCheck tests for their libraries?  In
the main library?  As a separate repo  package?  Same repo  separate
package?  Keeping tests with the tested code allows testing of non-exported
functionality, but can add quite a lot of clutter.

My current leaning is to split a package foo into packages foo and
foo-test, but first I'd like to hear about others' experiences, insights,
and preferences.

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


Re: [Haskell-cafe] STM and FFI

2008-09-09 Thread Arnar Birgisson
On Tue, Sep 9, 2008 at 13:58, Sterling Clover [EMAIL PROTECTED] wrote:
 I've been playing with this, and on top of STM as it exists, managed to
 neatly interleave it with sqite3 and postgres. To do so with postgres,
 however, required setting the locking mode to be a bit more restrictive than
 it is out-of-the-box. Clever use of encapsulation and monad transformers
 gets you 90% of the way there quite easily. Note, however, that
 unsafeIOToSTM is *much* more unsafe at the moment than you would expect --
 in fact there is no safe way to use it at all, due to the interaction of
 exceptions and rollbacks at the moment. The thread about this on
 glasgow-haskell-users[1], along with my initial note, has a very useful
 reply by Simon Marlow where he both explains some things about the STM
 implementation and logic behind it that I didn't understand, and also
 describes how the GHC team intends to fix this at some point in the future.

This is very interesting, do you have any code to release?

Thanks for the ghu link, registering for that ML now :)

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


Re: [Haskell-cafe] Haskell and Java

2008-09-09 Thread Donnchadh Ó Donnabháin
It's not haskell to java compiler but you might find cohatoe and
eclipsefp interesting:

http://cohatoe.blogspot.com/
http://eclipsefp.sourceforge.net/

  Donnchadh

2008/9/9 Maurí­cio [EMAIL PROTECTED]:
 Hi,

 I use Haskell, and my friends at
 work use Java. Do you think it
 could be a good idea to use Haskell
 with Java, so I could understand
 and cooperate with them? Is there a
 a Haskell to Java compiler that's
 already ready to use?

 Thanks,
 Maurício

 ___
 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] packages and QuickCheck

2008-09-09 Thread Dougal Stanton
2008/9/9 Conal Elliott [EMAIL PROTECTED]:
 How do folks like to package up QuickCheck tests for their libraries?  In
 the main library?  As a separate repo  package?  Same repo  separate
 package?  Keeping tests with the tested code allows testing of non-exported
 functionality, but can add quite a lot of clutter.

If they're in a separate package it's less easy to wire quickcheck
tests into the commit procedure.


Cheers,


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


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Dougal Stanton
On Tue, Sep 9, 2008 at 2:05 PM, Dougal Stanton [EMAIL PROTECTED] wrote:

 If they're in a separate package it's less easy to wire quickcheck
 tests into the commit procedure.

And by package there, I mean repo. Obviously ;-)

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


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Sean Leather
 How do folks like to package up QuickCheck tests for their libraries?  In
 the main library?  As a separate repo  package?  Same repo  separate
 package?  Keeping tests with the tested code allows testing of non-exported
 functionality, but can add quite a lot of clutter.


I have QuickCheck properties plus HUnit tests, but I think the question is
the same. For me, it's in the same repository and shipped with the package
source. I think that if you ship source (even via Hackage), you should also
ship tests. So, if somebody wants to modify the source, they can run the
tests. And making it convenient to test is very important, so I have cabal
test (or runhaskell Setup.hs test without cabal-install) configured to
run the tests. I don't think tests should (in general) be part of the
user-visible API, so I have them external to the module hierarchy.

Testing non-exported functionality without exporting the test interface
seems difficult in general. Is there a way to hide part of a module
interface with Cabal? Then, you could have a 'test' function exported from
each module for testing but hidden for release.

My current leaning is to split a package foo into packages foo and
 foo-test


What benefit does this provide?

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


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Conal Elliott
Thanks, Sean.

On Tue, Sep 9, 2008 at 3:46 PM, Sean Leather [EMAIL PROTECTED] wrote:


 How do folks like to package up QuickCheck tests for their libraries?  In
 the main library?  As a separate repo  package?  Same repo  separate
 package?  Keeping tests with the tested code allows testing of non-exported
 functionality, but can add quite a lot of clutter.


 I have QuickCheck properties plus HUnit tests, but I think the question is
 the same. For me, it's in the same repository and shipped with the package
 source. I think that if you ship source (even via Hackage), you should also
 ship tests. So, if somebody wants to modify the source, they can run the
 tests. And making it convenient to test is very important, so I have cabal
 test (or runhaskell Setup.hs test without cabal-install) configured to
 run the tests. I don't think tests should (in general) be part of the
 user-visible API, so I have them external to the module hierarchy.


How do you set up cabal to do these tests?

Do your libraries depend on HUnit?

Where do you like to place your tests?  In the functionality modules?  A
parallel structure?  A single Test.hs file somewhere?

Testing non-exported functionality without exporting the test interface
 seems difficult in general. Is there a way to hide part of a module
 interface with Cabal? Then, you could have a 'test' function exported from
 each module for testing but hidden for release.


My current leaning is to split a package foo into packages foo and
 foo-test


 What benefit does this provide?


It keeps the library and its dependencies small.  Probably some of the
alternatives do as well.  For testing, I'm using
checkershttp://haskell.org/haskellwiki/Checkersin addition to
QuickCheck, and I'd prefer not to make casual library users
have to pull in those libraries as well.

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


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Sean Leather
 How do folks like to package up QuickCheck tests for their libraries?  In
 the main library?  As a separate repo  package?  Same repo  separate
 package?  Keeping tests with the tested code allows testing of non-exported
 functionality, but can add quite a lot of clutter.


 I have QuickCheck properties plus HUnit tests, but I think the question is
 the same. For me, it's in the same repository and shipped with the package
 source. I think that if you ship source (even via Hackage), you should also
 ship tests. So, if somebody wants to modify the source, they can run the
 tests. And making it convenient to test is very important, so I have cabal
 test (or runhaskell Setup.hs test without cabal-install) configured to
 run the tests. I don't think tests should (in general) be part of the
 user-visible API, so I have them external to the module hierarchy.


 How do you set up cabal to do these tests?


I use the runTests hook in Distribution.Simple. The code below works on
Windows and Mac, because that's what we use.

\begin{code}
module Main (main) where

import Distribution.Simple
import System.Cmd (system)
import System.FilePath ((/))

main :: IO ()
main = defaultMainWithHooks hooks where
  hooks = simpleUserHooks { runTests = runTests' }

runTests' _ _ _ _ = system cmd  return ()
  where testdir = dist / build / test
testcmd = . / test
cmd = cd  ++ testdir ++++ testcmd
\end{code}

Do your libraries depend on HUnit?


No, because I use an ultra-secret trick. ;) I have a Library in my .cabal
file and an Executable for testing. Part of the test description follows.

\begin{cabal}
Executable test
  hs-source-dirs:   src, tests, examples
  main-is:  Main.hs

  -- Only enable the build-depends here if configured with -ftest. This
  -- keeps users from having to install QuickCheck 2 in order to use EMGM.
  if flag(test)
build-depends:  QuickCheck = 2.0, HUnit = 1.2
  else
buildable:  False
\end{cabal}

With that last flag-based if/else, I hide the dependencies for normal
building ('test' by default is False). If 'test' is False, then the
executable also cannot be built.

Where do you like to place your tests?  In the functionality modules?  A
 parallel structure?  A single Test.hs file somewhere?


In a separate tests directory at the same level as the src directory
containing the module hierarchy. It has a number of files, mostly one per
module tested.


 Testing non-exported functionality without exporting the test interface
 seems difficult in general. Is there a way to hide part of a module
 interface with Cabal? Then, you could have a 'test' function exported from
 each module for testing but hidden for release.


 My current leaning is to split a package foo into packages foo and
 foo-test


 What benefit does this provide?


 It keeps the library and its dependencies small.  Probably some of the
 alternatives do as well.  For testing, I'm using 
 checkershttp://haskell.org/haskellwiki/Checkersin addition to QuickCheck, 
 and I'd prefer not to make casual library users
 have to pull in those libraries as well.


Ah, so you're handling the same problem we are in a different way. Nice!

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


Re: [Haskell-cafe] Hackage - MacPorts?

2008-09-09 Thread Bjorn Bringert
On Wed, Sep 3, 2008 at 10:14 PM, John MacFarlane [EMAIL PROTECTED] wrote:
 It would be great if there were an automated or semi-automated way
 of generating a MacPorts Portfile from a HackageDB package, along
 the lines of dons' cabal2arch. Has anyone been working on such a thing?
 And, are any haskell-cafe readers MacPorts committers?

I seem to remember that Eric Kidd started working on something like
this at the Hackathon in Freiburg.

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


Re: [Haskell-cafe] Re: Field names

2008-09-09 Thread Justin Bailey
2008/9/8 Daryoush Mehrtash [EMAIL PROTECTED]

 Thanks.

 Pattern matching and memory management in Haskell (or may be GHC 
 implementation of it) is somewhat of a mystery to me.  Are there any 
 references that explains the underlying implementation?

 Daryoush

Be careful what you ask for. This paper is 16 years old but fairly
relevant. Click the view or download link at the bottom:

  Implementing Lazy Functional Languages on Stock Hardware: The
Spineless Tagless G-Machine
  http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.3729

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


Re: [Haskell-cafe] haskell core definition

2008-09-09 Thread Justin Bailey
This paper is a bit old but still very relevant:

   An External Representation for the GHC Core Language
   http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.25.1755

Click view or download at the bottom to see the paper. Also, I
haven't used this utility myself yet but it pages and colorizes GHC
core for you:

  http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ghc-core

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


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Conal Elliott
Hi Sean.

Thanks a bunch for these tips.  I haven't used the flags feature of cabal
before, and i don't seem to be able to get it right.  I have:

Flag test
  Description: Enable testing
  Default: False

And I get Warning: unamb.cabal: Unknown section type: flag ignoring
If I indent, I instead get These flags are used without having been
defined: test.  Any idea what I'm doing wrong here?

  - Conal


On Tue, Sep 9, 2008 at 4:32 PM, Sean Leather [EMAIL PROTECTED] wrote:


  How do folks like to package up QuickCheck tests for their libraries?  In
 the main library?  As a separate repo  package?  Same repo  separate
 package?  Keeping tests with the tested code allows testing of non-exported
 functionality, but can add quite a lot of clutter.


 I have QuickCheck properties plus HUnit tests, but I think the question
 is the same. For me, it's in the same repository and shipped with the
 package source. I think that if you ship source (even via Hackage), you
 should also ship tests. So, if somebody wants to modify the source, they can
 run the tests. And making it convenient to test is very important, so I have
 cabal test (or runhaskell Setup.hs test without cabal-install)
 configured to run the tests. I don't think tests should (in general) be part
 of the user-visible API, so I have them external to the module hierarchy.


 How do you set up cabal to do these tests?


 I use the runTests hook in Distribution.Simple. The code below works on
 Windows and Mac, because that's what we use.

 \begin{code}
 module Main (main) where

 import Distribution.Simple
 import System.Cmd (system)
 import System.FilePath ((/))

 main :: IO ()
 main = defaultMainWithHooks hooks where
   hooks = simpleUserHooks { runTests = runTests' }

 runTests' _ _ _ _ = system cmd  return ()
   where testdir = dist / build / test
 testcmd = . / test
 cmd = cd  ++ testdir ++++ testcmd
 \end{code}

 Do your libraries depend on HUnit?


 No, because I use an ultra-secret trick. ;) I have a Library in my .cabal
 file and an Executable for testing. Part of the test description follows.

 \begin{cabal}
 Executable test
   hs-source-dirs:   src, tests, examples
   main-is:  Main.hs

   -- Only enable the build-depends here if configured with -ftest. This
   -- keeps users from having to install QuickCheck 2 in order to use EMGM.
   if flag(test)
 build-depends:  QuickCheck = 2.0, HUnit = 1.2
   else
 buildable:  False
 \end{cabal}

 With that last flag-based if/else, I hide the dependencies for normal
 building ('test' by default is False). If 'test' is False, then the
 executable also cannot be built.

 Where do you like to place your tests?  In the functionality modules?  A
 parallel structure?  A single Test.hs file somewhere?


 In a separate tests directory at the same level as the src directory
 containing the module hierarchy. It has a number of files, mostly one per
 module tested.


 Testing non-exported functionality without exporting the test interface
 seems difficult in general. Is there a way to hide part of a module
 interface with Cabal? Then, you could have a 'test' function exported from
 each module for testing but hidden for release.


 My current leaning is to split a package foo into packages foo and
 foo-test


 What benefit does this provide?


 It keeps the library and its dependencies small.  Probably some of the
 alternatives do as well.  For testing, I'm using 
 checkershttp://haskell.org/haskellwiki/Checkersin addition to QuickCheck, 
 and I'd prefer not to make casual library users
 have to pull in those libraries as well.


 Ah, so you're handling the same problem we are in a different way. Nice!

 Sean

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


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Ketil Malde
Conal Elliott [EMAIL PROTECTED] writes:

 Thanks a bunch for these tips.  I haven't used the flags feature of cabal
 before, and i don't seem to be able to get it right. 

Another option might be to have the test command build via 'ghc
--make' instead of Cabal - this way, you can avoid mentioning testing
libraries altogether in the cabal file.

-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] packages and QuickCheck

2008-09-09 Thread Max Bolingbroke
2008/9/9 Conal Elliott [EMAIL PROTECTED]:
 Hi Sean.

 Thanks a bunch for these tips.  I haven't used the flags feature of cabal
 before, and i don't seem to be able to get it right.  I have:

 Flag test
   Description: Enable testing
   Default: False

 And I get Warning: unamb.cabal: Unknown section type: flag ignoring
 If I indent, I instead get These flags are used without having been
 defined: test.  Any idea what I'm doing wrong here?

I don't know exactly what your problem is, but perhaps you have not
specified Cabal-Version: = 1.2?

For another example .cabal file that uses something like the technique
Sean describes you can look at my edit-distance library on GitHub:
http://github.com/batterseapower/edit-distance/tree/master/edit-distance.cabal.
It exports a library with the edit distance algorithms and a test
executable which is only buildable when configured with -ftests. I
haven't made use of the Cabal test hook, but you can run the tests
just by running that single executable: the procedure is described in
my README: 
http://github.com/batterseapower/edit-distance/tree/master/README.textile

My tests are making use of a nice console test runner I wrote that
supports both HUnit and QuickCheck (and is extensible to other test
providers by the user):
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/test-framework.

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


Re: [Haskell-cafe] haskell core definition

2008-09-09 Thread Andrew Coppin

Justin Bailey wrote:

This paper is a bit old but still very relevant:

   An External Representation for the GHC Core Language
   http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.25.1755

Click view or download at the bottom to see the paper. Also, I
haven't used this utility myself yet but it pages and colorizes GHC
core for you:

  http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ghc-core
  


IIRC, wasn't there a plan a while back to make GHC compile *from* Core 
as well as just outputting it? Did this ever go anywhere?


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


[Haskell-cafe] Windows details

2008-09-09 Thread Andrew Coppin

I rather doubt anybody will know the answer to this, but I'll ask anyway...

Under MS Windows, if you right-click on an executable file and select 
properties, sometimes there's a Version tab that tells you the 
version number of the program. And sometimes there isn't. (Most 
especially, GHC-compiled programs do not have this tab.) Anybody know 
how to go about adding this?


Also, anybody know how to give a GHC-compiled program a custom icon?

If it's going to be really difficult then I won't bother, but it'd be 
interesting to know.


(In other news, today I discovered that applying UPX to my 2.8 MB 
GHC-compiled executable shrinks it down to 800 KB and it still 
functions. And WinZip shrinks it down to just 300 KB. 2.8 MB for a 
program that just does a little text parsing does seem a touch excessive 
to me...)


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


Re: [Haskell-cafe] Windows details

2008-09-09 Thread Steve Schafer
On Tue, 09 Sep 2008 18:13:50 +0100, you wrote:

Under MS Windows, if you right-click on an executable file and select 
properties, sometimes there's a Version tab that tells you the 
version number of the program. And sometimes there isn't. (Most 
especially, GHC-compiled programs do not have this tab.) Anybody know 
how to go about adding this?

Also, anybody know how to give a GHC-compiled program a custom icon?

Version information and application icons are both stored in data
structures called resources; these are appended to the executable
portion of the application, inside the EXE file. There are a number of
predefined resource types, such as the aforementioned version info and
icon, which follow specific data formats, and you can also define custom
resources to store just about anything you want. (For example, in an
application I wrote recently, I used custom resources to embed a set of
TrueType fonts into the EXE.)

There are a gazillion resource editors available for modifying the
resources linked into an EXE; go to the Wikipedia page for a reasonable
starting point:

 http://en.wikipedia.org/wiki/Resource_(Windows)

Steve Schafer
Fenestra Technologies Corp
http://www.fenestra.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] trying to understand monad transformers....

2008-09-09 Thread Paul Johnson

Daryoush Mehrtash wrote:

The MaybeT transformer is defined as:
newtype MaybeT m a = MaybeT {runMaybeT :: m (Maybe 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Maybe 
a)}

 
instance Functor http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Functor m = Functor http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Functor (MaybeT m) where


  fmap http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap f x = MaybeT $ 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:. fmap 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap (fmap 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap f) $ 
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:. runMaybeT x



  


Question:  What does runMaybeT x mean?

All monads (except IO) have a run function.  E.g. runST for the ST 
monad, runState for the state function, and so on.  A monadic action 
is actually a function that (typically) takes extra arguments and 
returns extra results.  In the monadic action form these extra data are 
hidden, and its up to the monad bind function to thread them from one 
action to the next.  The runX function for some monad X converts a 
monadic action into the underlying function with that data exposed.  In 
most cases the monad is defined as a newtype wrapper around the 
function, so the run function is just the inverse of the constructor.


In the case of a monad transformer the result of the function is not a 
value, its an action in another monad.  Thats what you see in the case 
of MaybeT.  A MaybeT action is actually a monadic action that itself 
returns a Maybe value.  So you use runMaybeT to turn your MaybeT action 
into an action in the inner monad, and then run that action using its 
run function to finally get a Maybe result.


Make sense?

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


Re: [Haskell-cafe] Can you do everything without shared-memory concurrency?

2008-09-09 Thread Bruce Eckel
So this is the kind of problem I keep running into. There will seem to be
consensus that you can do everything with isolated processes message passing
(and note here that I include Actors in this scenario even if their
mechanism is more complex). And then someone will pipe up and say well, of
course, you have to have threads and the argument is usually for
efficiency.
I make two observations here which I'd like comments on:

1) What good is more efficiency if the majority of programmers can never get
it right? My position: if a programmer has to explicitly synchronize
anywhere in the program, they'll get it wrong. This of course is a point of
contention; I've met a number of people who say well, I know you don't
believe it, but *I* can write successful threaded programs. I used to think
that, too. But now I think it's just a learning phase, and you aren't a
reliable thread programmer until you say it's impossible to get right
(yes, a conundrum).

2) What if you have lots of processors? Does that change the picture any?
That is, if you use isolated processes with message passing and you have as
many processors as you want, do you still think you need shared-memory
threading?

A comment on the issue of serialization -- note that any time you need to
protect shared memory, you use some form of serialization. Even optimistic
methods guarantee serialization, even if it happens after the memory is
corrupted, by backing up to the uncorrupted state. The effect is the same;
only one thread can access the shared state at a time.

On Tue, Sep 9, 2008 at 4:03 AM, Sebastian Sylvan [EMAIL PROTECTED]
 wrote:



 On Mon, Sep 8, 2008 at 8:33 PM, Bruce Eckel [EMAIL PROTECTED] wrote:

 As some of you on this list may know, I have struggled to understand
 concurrency, on and off for many years, but primarily in the C++ and
 Java domains. As time has passed and experience has stacked up, I have
 become more convinced that while the world runs in parallel, we think
 sequentially and so shared-memory concurrency is impossible for
 programmers to get right -- not only are we unable to think in such a
 way to solve the problem, the unnatural domain-cutting that happens in
 shared-memory concurrency always trips you up, especially when the
 scale increases.

 I think that the inclusion of threads and locks in Java was just a
 knee-jerk response to solving the concurrency problem. Indeed, there
 were subtle threading bugs in the system until Java 5. I personally
 find the Actor model to be most attractive when talking about
 threading and objects, but I don't yet know where the limitations of
 Actors are.

 However, I keep running across comments where people claim they must
 have shared memory concurrency. It's very hard for me to tell whether
 this is just because the person knows threads or if there is truth to
 it.


 For correctness, maybe not, for efficiency, yes definitely!

 Imagine a program where you have a huge set of data that needs to be
 modified (in some sense) over time by thousands of agents. E.g. a game
 simulation.
 Now, also imagine that every agent could *potentially* modify every single
 piece of data, but that every agent *typically* only touches two or three
 varibles here and there. I.e. the collisions between the potential
 read/write sets is 100%, while the collisions for the actual read/write sets
 is very very low.

 How would you do this with threads and message passing? Well you could have
 one big thread owning all of your data that takes update messages, and
 then updates the world for you (immutably if you wish, by just replacing
 its world variable with a new one containing your update), but now you've
 effectively serialized all your interactions with the world, so you're not
 really concurrent anymore!

 So you could decompose the world into multiple threads using some
 application-specific logical sudivision, but then you're effectively just
 treating each thread as a mutable variable with an implicit lock (with the
 risks of deadlock that comes with it - remember we don't know the read/write
 set in advance - it could be the entire world - so we can't just order our
 updates in some global way here), so you're really just doing shared mutable
 state again, and gain little from having threads simulate your mutable
 cells...

 What you really need for this is some way for each agent to update this
 shared state *in parallel*, without having to block all other agents
 pessimistically, but instead only block other agents if there was an
 *actual* conflict. STM seems to be the only real hope for that sort of thing
 right now.
  IMO my list of preferred methods goes like this:
 1. Purely functional data parallelism
 2. Purely functional task parallelism (using e.g. strategies)
 3. Message passing with no (or very minimal) shared state (simulated using
 threads as data servers or otherwise)
 (3.5. Join patterns? Don't have enough experience with this, but seems sort
 of nice?)
 4. Shared state 

Re: [Haskell-cafe] Windows details

2008-09-09 Thread Andrew Coppin

Steve Schafer wrote:

Version information and application icons are both stored in data
structures called resources; these are appended to the executable
portion of the application, inside the EXE file. There are a number of
predefined resource types, such as the aforementioned version info and
icon, which follow specific data formats, and you can also define custom
resources to store just about anything you want. (For example, in an
application I wrote recently, I used custom resources to embed a set of
TrueType fonts into the EXE.)

There are a gazillion resource editors available for modifying the
resources linked into an EXE; go to the Wikipedia page for a reasonable
starting point:

 http://en.wikipedia.org/wiki/Resource_(Windows)
  


Thanks for your input. I'm now playing with XN Resource Editor. Getting 
the version information to work correctly appears to be tricky, but 
everything else seems quite straight forward...


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


[Haskell-cafe] Re: Munging wiki articles with tagsoup

2008-09-09 Thread Neil Mitchell
Hi Gwern,

Sorry for not noticing this sooner, my haskell-cafe@ reading is
somewhat behind right now!


  After an hour, I came up with a nice clean little script:

  

  import Text.HTML.TagSoup.Render
  import Text.HTML.TagSoup

  main :: IO ()
  main = interact convertPre

  convertPre :: String - String
  convertPre = renderTags . map convertToHaskell . canonicalizeTags . parseTags

  convertToHaskell :: Tag - Tag
  convertToHaskell x
| isTagOpenName  pre x = TagOpen  haskell (extractAttribs 
 x)
| isTagCloseName pre x = TagClose haskell
| otherwise  = x
  where
extractAttribs :: Tag - [Attribute]
extractAttribs (TagOpen _ y) = y
extractAttribs _ = error The 
 impossible happened.


convertToHaskell (TagOpen pre atts) = TagOpen haskell atts
convertToHaskell (TagClose pre) = TagClose haskell
convertToHaskell x = x

Direct pattern matching is much easier and simpler.

  Anyway, so my script seems to work. I ran the wiki output through it and 
 this is the diff: 
 http://haskell.org/haskellwiki/?title=User%3AGwern%2Fkenndiff=22827oldid=22811.

  Ok, good, it replaces all the tags... But wait, what's all this other stuff? 
 It is replacing all my apostrophes with apos;! No doubt this has something 
 to do with XML/HTML/SGML or whatever, but it's not ideal. Even if it doesn't 
 break the formatting (as I think it does), it's still cluttering up the 
 source.

The escaping of ' is caused by renderTags, so instead call:


renderTagsOptions (renderOptions{optEscape = (:[])})

For no escaping of any characters, or more likely do something like ,
 and  conversions. See the docs:
http://hackage.haskell.org/packages/archive/tagsoup/0.6/doc/html/Text-HTML-TagSoup-Render.html

 Am I just barking up the wrong tree and should be writing a simple-minded 
 search-and-replace sed script which replaces pre with haskell, /pre 
 with /haskell...?

Not necessarily. If you literally just want to replace haskell
with pre then sed is probably the easy choice. However, its quite
likely you'll want to make more fixes, and tagsoup gives you the
flexibility to extend in that direction.

Thanks

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


[Haskell-cafe] Windows console

2008-09-09 Thread Andrew Coppin
When coding in a POSIX-compliant environment, you can usually write 
special escape codes to the console to change the text colour and so 
forth. However, this does not work on Windows.


(Ignore all references you see to enabling ANSI.SYS in your config.sys 
file; this applies only to 16-bit MS-DOS programs, *not* to 32-bit 
Windows programs.)


However - to my surprise - apparently the Win32 API provides a set of 
function calls that do in fact allow 32-bit applications to change the 
colours of the console on a character-by-character basis. However - wait 
for it - those *particular* functions aren't in Haskell's 
System.Win32.Console module. :-(


Obviously, I know nothing about C. However, after much hunting around, 
it turns out that for some reason, GHC appears to ship with a complete 
set of C header files for the Win32 API. (In other words, the necessary 
header file for accessing the functions I want is there.) After 
staggering through the (very unhelpful) FFI language specification, I 
was able to make it so that I can apparently call these functions from 
Haskell. I was not, however, able to find any way at all to import the 
symbolic constants necessary, so I was forced to reading through the 
source code of the raw C header files to find out what the numeric 
values of these are (!!!)


The long and short of it is, I now have a small Haskell library that 
enables me to print things in trippy colours on the screen from a normal 
Haskell CLI program. Yay for me! (Actually, you can also change the 
title on the window - so you can make your program say My Fantastic 
Tool instead of C:\Documents and 
Settings\foo\Haskell\MyTool\MyTool.exe in the titlebar. Again, this is 
for a normal Haskell console application with nothing done to it.)


Would anybody else be interested in having this code? (Obviously, it's 
pretty tiny.) For that matter, would the maintainer of 
System.Win32.Console be interested in adding the necessary dozen lines 
of code to that module?


Actually, now that I think about it, it would be kind of nice to have a 
magic package that writes out escape codes or calls the Win32 API 
depending on which platform your program is compiled on - in the style 
of System.FilePath. I don't know how to do that though... A nice idea, guys?


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


Re: [Haskell-cafe] haskell core definition

2008-09-09 Thread Tim Chevalier
On Tue, Sep 9, 2008 at 8:34 AM, Justin Bailey [EMAIL PROTECTED] wrote:
 This paper is a bit old but still very relevant:

   An External Representation for the GHC Core Language
   http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.25.1755


Or: http://www.haskell.org/ghc/docs/papers/core.ps.gz
Note that External Core, as specified in this paper, is similar to but
not entirely the same as the version of Core that GHC prints out for
debugging purposes.

GHC 6.10 will be able to produce External Core with a flag again, and
at that point Section 5.15 of the users' guide will point to a new
version of the documentation -- so if you upgrade to 6.10 when it is
released and are still poring over Core code then, be sure to get the
new documentation.

Cheers,
Tim

-- 
Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
Just enough: Obama/Biden '08.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Can you do everything without shared-memory concurrency?

2008-09-09 Thread Jed Brown
On Tue 2008-09-09 12:30, Bruce Eckel wrote:
 So this is the kind of problem I keep running into. There will seem to be
 consensus that you can do everything with isolated processes message passing
 (and note here that I include Actors in this scenario even if their mechanism
 is more complex). And then someone will pipe up and say well, of course, you
 have to have threads and the argument is usually for efficiency.

Some pipe up and say ``you can't do global shared memory because it's
inefficient''.  Ensuring cache coherency with many processors operating
on shared memory is a nightmare and inevitably leads to poor
performance.  Perhaps some optimizations could be done if the programs
were guaranteed to have no mutable state, but that's not realistic.
Almost all high performance machines (think top500) are distributed
memory with very few cores per node.  Parallel programs are normally
written using MPI for communication and they can achieve nearly linear
scaling to 10^5 processors BlueGene/L for scientific problems with
strong global coupling.

I encourage you to browse these slides for some perspective on very
large scale coupled computation.  Most problems commercial/industrial
tasks are much easier since the global coupling is much looser.

http://www.xergi.no/upload/IKT/9011/SimOslo/eVITA/2008/PetaflopsGeilo.pdf

Jed


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


Re: [Haskell-cafe] [Fwd: profiling in haskell]

2008-09-09 Thread Tim Chevalier
2008/9/8 Vlad Skvortsov [EMAIL PROTECTED]:
 Posting to cafe since I got just one reply on [EMAIL PROTECTED] I was 
 suggested to
 include more SCC annotations, but that didn't help. The 'serialize' function
 is still reported to consume about 32% of running time, 29% inherited.
 However, functions called from it only account for about 3% of time.


If serialize calls standard library functions, this is probably
because the profiling libraries weren't built with -auto-all -- so the
profiling report won't tell you how much time standard library
functions consume.

You can rebuild the libraries with -auto-all, but probably much easier
would be to add SCC annotations to each call site. For example, you
could annotate your locally defined dumpWith function like so:

dumpWith f = {-# SCC foldWithKey #-} Data.Map.foldWithKey f []
docToStr k (Doc { docName=n, docVectorLength=vl}) =
(:) (d  ++ show k ++   ++ n ++   ++ (show vl))

Then your profiling report will tell you how much time/memory that
particular call to foldWithKey uses.

By the way, using foldl rather than foldl' or foldr is almost always a
performance bug.

Cheers,
Tim

-- 
Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
Just enough: Obama/Biden '08.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Windows console

2008-09-09 Thread Jonathan Cast
On Tue, 2008-09-09 at 20:15 +0100, Andrew Coppin wrote:
 When coding in a POSIX-compliant environment, you can usually write 
 special escape codes to the console to change the text colour and so 
 forth. However, this does not work on Windows.
 
 (Ignore all references you see to enabling ANSI.SYS in your config.sys 
 file; this applies only to 16-bit MS-DOS programs, *not* to 32-bit 
 Windows programs.)
 
 However - to my surprise - apparently the Win32 API provides a set of 
 function calls that do in fact allow 32-bit applications to change the 
 colours of the console on a character-by-character basis. However - wait 
 for it - those *particular* functions aren't in Haskell's 
 System.Win32.Console module. :-(
 
 Obviously, I know nothing about C. However, after much hunting around, 
 it turns out that for some reason, GHC appears to ship with a complete 
 set of C header files for the Win32 API. (In other words, the necessary 
 header file for accessing the functions I want is there.) After 
 staggering through the (very unhelpful) FFI language specification, I 
 was able to make it so that I can apparently call these functions from 
 Haskell. I was not, however, able to find any way at all to import the 
 symbolic constants necessary, so I was forced to reading through the 
 source code of the raw C header files to find out what the numeric 
 values of these are (!!!)

c2hs can do this; check out #const CONSTANT_NAME

jcc


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


Re: [Haskell-cafe] Windows console

2008-09-09 Thread Max Bolingbroke
2008/9/9 Andrew Coppin [EMAIL PROTECTED]:
 Actually, now that I think about it, it would be kind of nice to have a
 magic package that writes out escape codes or calls the Win32 API depending
 on which platform your program is compiled on - in the style of
 System.FilePath. I don't know how to do that though... A nice idea, guys?

I wrote this package a few weeks ago: check out
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ansi-terminal
and it's companion
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ansi-wl-pprint

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


Re: [Haskell-cafe] Windows console

2008-09-09 Thread Bulat Ziganshin
Hello Andrew,

Tuesday, September 9, 2008, 11:15:08 PM, you wrote:

 Haskell. I was not, however, able to find any way at all to import the
 symbolic constants necessary, so I was forced to reading through the 
 source code of the raw C header files to find out what the numeric 
 values of these are (!!!)

look into Win32 package sources, small example is:

#{enum LoadLibraryFlags,
 , lOAD_LIBRARY_AS_DATAFILE  = LOAD_LIBRARY_AS_DATAFILE
 , lOAD_WITH_ALTERED_SEARCH_PATH = LOAD_WITH_ALTERED_SEARCH_PATH
 }

(in File.hsc)

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Haskell and Java

2008-09-09 Thread Bulat Ziganshin
Hello Mauri­cio,

Tuesday, September 9, 2008, 1:36:09 PM, you wrote:

 I use Haskell, and my friends at
 work use Java. Do you think it
 could be a good idea to use Haskell
 with Java, so I could understand
 and cooperate with them?

http://haskell.org/haskellwiki/Applications_and_libraries/Interfacing_other_languages

in particular, GreenCard doesn't work with ghc = 6.2


 Is there a
 a Haskell to Java compiler that's
 already ready to use?

CAL

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


[Haskell-cafe] Haskell stacktrace

2008-09-09 Thread Pieter Laeremans
Hello,
I've written a cgi script in haskell, it crashes sometimes  with the error
message Prelude . tail  : empty list

In Java we would use this approach to log the erro

try {

} catch (Exception e) {


}


-- 
Pieter Laeremans [EMAIL PROTECTED]

The future is here. It's just not evenly distributed yet. W. Gibson
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Haskell stacktrace

2008-09-09 Thread Pieter Laeremans
Woops , I hit the  send button to early.
The java approach to locate the error would be

try {   ... }catch(Exception e ){
// log error
throw new RuntimeException(e);
}

...

What 's the best equivalent haskell approach ?

thanks in advance,

Pieter


On Tue, Sep 9, 2008 at 10:30 PM, Pieter Laeremans [EMAIL PROTECTED]wrote:

 Hello,
 I've written a cgi script in haskell, it crashes sometimes  with the error
 message Prelude . tail  : empty list

 In Java we would use this approach to log the erro

 try {

 } catch (Exception e) {


 }


 --
 Pieter Laeremans [EMAIL PROTECTED]

 The future is here. It's just not evenly distributed yet. W. Gibson




-- 
Pieter Laeremans [EMAIL PROTECTED]

The future is here. It's just not evenly distributed yet. W. Gibson
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Haskell stacktrace

2008-09-09 Thread Pieter Laeremans
This :
Prelude let f = (\x - return something went wrong)  ::   IOError - IO
String
Prelude let t = return $ show $ too short list !! 100 :: IO String
Prelude catch t f
*** Exception: Prelude.(!!): index too large

doesn't work.

kind regards,

Pieter



On Tue, Sep 9, 2008 at 10:35 PM, Pieter Laeremans [EMAIL PROTECTED]wrote:

 Woops , I hit the  send button to early.
 The java approach to locate the error would be

 try {   ... }catch(Exception e ){
 // log error
 throw new RuntimeException(e);
 }

 ...

 What 's the best equivalent haskell approach ?

 thanks in advance,

 Pieter


 On Tue, Sep 9, 2008 at 10:30 PM, Pieter Laeremans [EMAIL PROTECTED]wrote:

 Hello,
 I've written a cgi script in haskell, it crashes sometimes  with the error
 message Prelude . tail  : empty list

 In Java we would use this approach to log the erro

 try {

 } catch (Exception e) {


 }


 --
 Pieter Laeremans [EMAIL PROTECTED]

 The future is here. It's just not evenly distributed yet. W. Gibson




 --
 Pieter Laeremans [EMAIL PROTECTED]

 The future is here. It's just not evenly distributed yet. W. Gibson




-- 
Pieter Laeremans [EMAIL PROTECTED]

The future is here. It's just not evenly distributed yet. W. Gibson
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Haskell stacktrace

2008-09-09 Thread Justin Bailey
2008/9/9 Pieter Laeremans [EMAIL PROTECTED]:
 What 's the best equivalent haskell approach ?
 thanks in advance,
 Pieter

The preferred approach is to look at your code, figure out where you
are using tail (or could be calling something that uses tail) and use
the trace function to output logging info. Don't forget that output
is buffered with trace so you might get some strange ordering. A quick
search of the API docs should show you where trace lives.

Techniques that worked for Java don't work very well when debugging
haskell. Others will tell you about flags and possibly using the
debugger but I would count on eyeballing and printing as the least
painful method.

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


Re: [Haskell-cafe] Re: Haskell stacktrace

2008-09-09 Thread Ketil Malde
Justin Bailey [EMAIL PROTECTED] writes:

 are using tail (or could be calling something that uses tail) and use
 the trace function to output logging info.

Another cheap trick is to use CPP with something like:

#define head (\xs - case xs of { (x:_) - x ; _ - error(head failed at 
line++__FILE__++show __LINE__)})

-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] Re: Haskell stacktrace

2008-09-09 Thread C.M.Brown
Or define your own ghead and gtail:

ghead msg [] = error ghead  ++ msg ++ []
ghead _ (x:xs)  = x


gtail msg [] = error gtail ++ msg ++ []
gtail msg (x:xs) = xs

and you can call them with a name of a function to give you an idea where
the error is occurring:

myHead = ghead myHead []

Chris.


On Tue, 9 Sep 2008, Ketil Malde wrote:

 Justin Bailey [EMAIL PROTECTED] writes:

  are using tail (or could be calling something that uses tail) and use
  the trace function to output logging info.

 Another cheap trick is to use CPP with something like:

 #define head (\xs - case xs of { (x:_) - x ; _ - error(head failed at 
 line++__FILE__++show __LINE__)})

 -k

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


Re: [Haskell-cafe] Re: Haskell stacktrace

2008-09-09 Thread Krzysztof Kościuszkiewicz
On Tue, Sep 09, 2008 at 11:06:43PM +0200, Pieter Laeremans wrote:
 This :
 Prelude let f = (\x - return something went wrong)  ::   IOError - IO
 String
 Prelude let t = return $ show $ too short list !! 100 :: IO String
 Prelude catch t f
 *** Exception: Prelude.(!!): index too large

How about:

 module Main where

 import Control.Exception
 import Prelude hiding (catch)

 f :: Exception - IO String
 f = const $ return sthg went wrong

 g :: String
 g = show $ too short list !! 100

 h :: IO String
 h = do
   print $ head [0 .. -1]
   return huh?

 main = do
   mapM_ print = sequence
   [ h `catch` f
   , evaluate g `catch` f
   , (return $! g) `catch` f
   , (return g) `catch` f
   ]

Output:

[EMAIL PROTECTED]:/tmp$ runhaskell test.lhs
sthg went wrong
sthg went wrong
sthg went wrong
test.lhs: Prelude.(!!): index too large

Check documentation of catch and evaluate functions in Control.Exception.

Regards,
-- 
Krzysztof Kościuszkiewicz
Skype: dr.vee,  Gadu: 111851,  Jabber: [EMAIL PROTECTED]
Simplicity is the ultimate sophistication -- Leonardo da Vinci
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Sean Leather
 Thanks a bunch for these tips.  I haven't used the flags feature of cabal
 before, and i don't seem to be able to get it right.


This is also my first time, so I'm not sure exactly what I'm doing right. ;)

I have:

 Flag test
   Description: Enable testing
   Default: False

 And I get Warning: unamb.cabal: Unknown section type: flag ignoring
 If I indent, I instead get These flags are used without having been
 defined: test.  Any idea what I'm doing wrong here?


No, but you can take a look at my .cabal file to see if you can figure out
what's different. The code's not yet released, but I'm fairly confident the
.cabal file does everything we need.

https://svn.cs.uu.nl:12443/viewvc/dgp-haskell/EMGM/emgm.cabal?view=markup

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


[Haskell-cafe] Unicode and Haskell

2008-09-09 Thread Mattias Bengtsson
Today i wrote some sample code after a Logic lecture at my university.
The idea is to represent the AST of propositional logic as an ADT with
some convenience functions (like read-/show instances) and then later
perhaps try to make some automatic transformations on the AST.
After construction of the Show instances i found the output a bit boring
and thought that some Unicode math symbols would spice things up. What
happens can be seen in the attached picture (only 3k, that's ok right?).
My terminal supports UTF-8 (when i do cat Logic.hs i can see the unicode
symbols properly).
What might be the problem?

regards
Mattias
module Logic where

infixr 5 :-:, :/\:, :\/:
infixr 5 --, /\, \/
infix 4 :|-:, :|=:
infix 4 |-, |=

data Logic = Formulae :|-: Formulae
   | Formulae :|=: Formulae

data Formulae = Formulae :-: Formulae
  | Formulae :/\: Formulae
  | Formulae :\/: Formulae
  | Formulae :-: Formulae
  | Not Formulae
  | P
  | Q
  | R
  | S


-- Operators
(--) = (:-:)
(/\)  = (:/\:)
(\/)  = (:\/:)
(-) = (:-:)
(|-)  = (:|-:)
(|=)  = (:|=:)
--a - b = (a -- b) /\ (b -- a)


-- Show

instance Show Logic where
showsPrec d (f1 :|-: f2) = shows f1 . showString  ⊢  . shows f2
showsPrec d (f1 :|=: f2) = shows f1 . showString  ⊨  . shows f2

p  = 5
p' = 6
instance Show Formulae where
showsPrec d (f1 :-: f2)  = showBinaryF d f1  →  f2
showsPrec d (f1 :/\: f2)  = showBinaryF d f1  ⋀  f2
showsPrec d (f1 :\/: f2)  = showBinaryF d f1  ⋁  f2
showsPrec d (f1 :-: f2) = showBinaryF d f1  ↔  f2
showsPrec d (Not f) = showString ¬
  . showsPrec p' f
showsPrec _ P = showString p
showsPrec _ Q = showString q
showsPrec _ R = showString r
showsPrec _ S = showString s

showBinaryF d f1 op f2 = showParen (d  p) 
 $ showsPrec p' f1
 . showString op 
 . showsPrec p' f2

import Logic
main = do print (P -- Q |- (Not P) -- (Not Q))

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


Re: [Haskell-cafe] Unicode and Haskell

2008-09-09 Thread Mattias Bengtsson
On Wed, 2008-09-10 at 00:01 +0200, Mattias Bengtsson wrote:
 [..]
 What happens can be seen in the attached picture[..]

And here it is...
attachment: Screenshot-Terminal2.jpg

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


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Sean Leather
 My tests are making use of a nice console test runner I wrote that
 supports both HUnit and QuickCheck (and is extensible to other test
 providers by the user):
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/test-framework.


The description looks great! I might have to try it out.

I used HUnit with QuickCheck 2, so that I could run QC properties as HUnit
tests. QC2 has the added ability (over QC1) to run a property and return a
Bool instead of just exiting with an error, and that works nicely within
HUnit. Does test-framework do something else to support QC running
side-by-side with HUnit?

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


Re: [Haskell-cafe] Unicode and Haskell

2008-09-09 Thread Thomas Davie


On 10 Sep 2008, at 00:01, Mattias Bengtsson wrote:


Today i wrote some sample code after a Logic lecture at my university.
The idea is to represent the AST of propositional logic as an ADT with
some convenience functions (like read-/show instances) and then later
perhaps try to make some automatic transformations on the AST.
After construction of the Show instances i found the output a bit  
boring

and thought that some Unicode math symbols would spice things up. What
happens can be seen in the attached picture (only 3k, that's ok  
right?).
My terminal supports UTF-8 (when i do cat Logic.hs i can see the  
unicode

symbols properly).
What might be the problem?


import Prelude hiding (print)
import System.IO.UTF8

main = print lots of UTF8

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


Re: [Haskell-cafe] Unicode and Haskell

2008-09-09 Thread Mattias Bengtsson
On Wed, 2008-09-10 at 00:07 +0200, Thomas Davie wrote:
 import Prelude hiding (print)
 import System.IO.UTF8
 
 main = print lots of UTF8
 

Thanks a lot!


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


[Haskell-cafe] Re: Windows console

2008-09-09 Thread Peter Hercek

Andrew Coppin wrote:
(Ignore all references you see to enabling ANSI.SYS in your config.sys 
file; this applies only to 16-bit MS-DOS programs, *not* to 32-bit 
Windows programs.)




You can add interpretation of ansi escape sequences to any win32
 program by launching the application through ansicon:

http://www.geocities.com/jadoxa/ansicon/index.html

Works on 32 bit windows. Works on 64 bit windows when running a
 32 bit application. Does not work for 64 bit application (since
 64 bit windows does not allow hooking of win64 api calls IIRC).
 For support of 32 bit programs on win64 you may need to apply
 a patch I sent to Jason. He probably did not apply it (he did
 not respond to my email). Check with me if you want it.

Peter.

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


Re: [Haskell-cafe] Re: Haskell stacktrace

2008-09-09 Thread Alec Berryman
Justin Bailey on 2008-09-09 14:12:38 -0700:

 2008/9/9 Pieter Laeremans [EMAIL PROTECTED]:
  What 's the best equivalent haskell approach ?
  thanks in advance,
  Pieter

 The preferred approach is to look at your code, figure out where you
 are using tail (or could be calling something that uses tail) and use
 the trace function to output logging info.

A nice way to automate that is using LocH from Hackage.  The original
announcement:

http://www.haskell.org/pipermail/haskell/2006-November/018729.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Haskell stacktrace

2008-09-09 Thread Peter Hercek

Justin Bailey wrote:

2008/9/9 Pieter Laeremans [EMAIL PROTECTED]:

What 's the best equivalent haskell approach ?
thanks in advance,
Pieter


The preferred approach is to look at your code, figure out where you
are using tail (or could be calling something that uses tail) and use
the trace function to output logging info. 


To find the specific tail call:
http://haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging

check the description for option -xc

Btw, is there any chance ghci debugger would ever print stack.
 It would be fine to see it in the same way as it exists
 when executing code ... I'm not interested in the stack as
 it would look if the program would not be lazy.

Peter.

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


Re: [Haskell-cafe] Haskell stacktrace

2008-09-09 Thread Donn Cave
 This :
 Prelude let f = (\x - return something went wrong)  ::   IOError - IO 
 String
 Prelude let t = return $ show $ too short list !! 100 :: IO String
 Prelude catch t f
 *** Exception: Prelude.(!!): index too large

 doesn't work.

You might be interested in the difference between Prelude.catch and
Control.Exception.catch

Though in an example like that, you'll need to force evaluation to
actually catch the exception.

  f _ = return something went wrong
  t = return $! show $ too short list !! 100
  ... Control.Exception.catch t f

(note $! instead of $ in t.)

Donn Cave, [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Functional references

2008-09-09 Thread Tim Docker
I've discussed the license of data-accessor with it's authors (Luke
Palmer  Henning Thieleman). They are ok with changing it to BSD3. So I
don't think the license will be a reason not to use it.

Tim

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ganesh
Sittampalam
Sent: Saturday, 6 September 2008 4:52 AM
To: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Functional references

On Fri, 5 Sep 2008, Jules Bean wrote:

 I think it would be worth spending some time (on this mailing list, 
 perhaps, or in another forum) trying to hash out a decent API which 
 meets most people's requirements, rather than ending up with 4 or 5 
 slightly different ones.

This sounds like a good plan, but please make sure the result is as free
as GHC, rather than GPL like data-accessor is. It's so simple that it
being GPL just drives people for whom licencing is an issue to write an
alternative rather than consider complying.

Ganesh
___
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] packages and QuickCheck

2008-09-09 Thread Jason Dagit
2008/9/9 Conal Elliott [EMAIL PROTECTED]:

 Where do you like to place your tests?  In the functionality modules?  A
 parallel structure?  A single Test.hs file somewhere?

The last time I had a chance to experiment with how to do this I used
a single Test.hs for the whole project and I think that is a bad idea
now.

I agree that you don't want to clutter your code with the test cases.
While it's good to have the tests accessible and near to the actual
code it can be distracting too.

The approach I used is here:
http://blog.codersbase.com/2006/09/01/simple-unit-testing-in-haskell/

Basically, I used the H98 parser plus TH to collect all the test cases
together and generate the test harness at compile time.  This meant
that any module that had a test case had to be plain H98 (but again,
only Test.hs had test cases).  On the other hand, specifying tests was
as simple as starting a function name with prop_.  You could also
modify my technique to look through all modules, or modules with
specific names.

Another approach is to use conditional compilation with something like
CPP.  This could allow you to export everything from modules only
while testing and then you could have Foo.hs and FooTests.hs for every
module.  The latter one would import everything from Foo.hs and define
the tests.

If you don't like conditional compilation, another approach I think is
decent is to have FooPrivate.hs (or FooInternal.hs), which is imported
into Foo.hs and FooTests.hs.  You could set things up so that only
Foo.hs and FooTests.hs are allowed to import FooPrivate.hs.  You could
of course write a script to enforce this, but something that tends to
be simpler and equally effective is just to politely ask that people
do not import FooPrivate.hs except in FooTests.hs and Foo.hs.

I hope that helps,
Jason
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Can you do everything without shared-memory concurrency?

2008-09-09 Thread Jason Dusek
Bruce Eckel [EMAIL PROTECTED] wrote:
 ...shared-memory concurrency is impossible for programmers to
 get right...

  Explicit locking is impractical to get right. Transactional
  interfaces take much of the pain out of that -- even web
  monkeys can get shared memory right with SQL!

  When two instances of a web app interact with the database,
  they are sharing the database's memory. So you have locking,
  mutual corruption and all that jazz -- yet you seem to be
  message passing! More generally, applications backed by
  network services -- which are presented through a message
  passing interface -- are shared memory applications much of
  the time (though a bright service can tell when modifications
  are unrelated and run them in parallel).

  Message passing certainly makes it easier to write parallel
  applications, but does it provide any help to manage shared
  state? No. None whatsoever. If you have a bunch of programs
  that never share state with one another, they are a single
  application in name only.

  Using locking as your default mode of IPC is harrowing, but
  you can do anything with it. Using message passing is simpler
  in most cases, but you'll have to implement locking yourself
  once in awhile. Language level, transactional interfaces to
  memory are going to cover all your bases, but are rare indeed
  -- as far as I'm aware, only Haskell's STM offers one.

 ...the unnatural domain-cutting that happens in shared-memory
 concurrency always trips you up, especially when the scale
 increases.

  This is true even with transactional interfaces. Message
  passing is _like the network_ and makes you think about the
  network -- so when it's time to get two servers and hook them
  together, you are already ready for it already. Transactional
  shared memory is not at all like the network. Why not? In a
  transactional system, a transaction can not both be approved
  and unwritten. On the network, though, these are separate
  messages, going in different directions -- they can fail
  independently.

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


Re: [Haskell-cafe] Haskell and Java

2008-09-09 Thread Daryoush Mehrtash
Why do you want to mix haskall and Java in one VM?  If there are
functionality within your code that is better implemented in haskell, then
why not  make that into a service (run it as haskell) with some api that
Java code can use.

Daryoush

On Tue, Sep 9, 2008 at 2:36 AM, Maurí­cio [EMAIL PROTECTED] wrote:

 Hi,

 I use Haskell, and my friends at
 work use Java. Do you think it
 could be a good idea to use Haskell
 with Java, so I could understand
 and cooperate with them? Is there a
 a Haskell to Java compiler that's
 already ready to use?

 Thanks,
 Maurício

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




-- 
Daryoush

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


Re: [Haskell-cafe] Hackage policy question

2008-09-09 Thread Duncan Coutts
On Mon, 2008-09-08 at 16:26 -0700, Iavor Diatchki wrote:
 Hi,
 I just noticed that hackage has introduced a new policy to disallow
 changes to a package without bumping the version.  I understand that
 this is probably a good idea for changes to the source code, but it
 really would be nice to have a backdoor that allows for other changes.
  For example, I just uploaded a package, and realized that I forgot to
 add a home-page entry in the cabal file.  I do not plan to increase
 the version number of my application, only so that I can upload a new
 version (the source code has not changed after all!).  I can imagine
 similar problems related to fixing typos in the description, and other
 fixes to the meta-data.

Yes. We've thought about this a bit. I'll tell you how I think it should
be managed, though I accept not everyone agrees with me.

The .tar.gz packages are pristine and must not change, however
the .cabal file that is kept in the hackage index could change and that
information will be reflected both in the hackage website and just as
importantly for tools like cabal-install. So not only could the
maintainer fix urls or whatever but also adjust dependencies in the
light of test results. Consider the analogy to pristine tarballs and
debian or gentoo meta-data files. The former never changes for a
particular version, but the meta-data can be adjusted as the
distributors see fit.

The difference here is that those two would be in the same format,
the .cabal file inside the tarball that never changes and the one in the
index which may do. This is also the objection that some people have,
that it would be confusing to have the two versions, especially that
unpacking the tarball gives the old unmodified version.

 So, could we please revert to the old policy?

No :-) But I hope with the above system that will not be necessary. I
hope to implement this feature in the new hackage server implementation
that I'll be announcing shortly.

Really it's essential that the md5sums of tarballs never change. Untold
chaos results if they are allowed to change. For one thing our urls
become unusable for distro systems like gentoo, fedora etc and they
would have to take snapshots and keep their own pristine mirrors rather
than using our url as the canonical reference (obviously they do their
own mirroring too but they usually refer back to a canonical source).
That would be a huge pain for them and a barrier to our acceptance into
distros.

 (if we really want to be fancy, the hackage upload script could check
 that the source code, and other fields, such as LICENSE have not
 changed, as these should really bump the version... in the mean time
 though, I think just being responsible members of the community would
 work just as well!).

Indeed we'll also have to check things carefully if we allow package or
distribution maintainers to adjust the .cabal files in the index. For
example changing exposed modules or the name or version number is right
out. We'll err on the restrictive side and gradually loosen as we decide
it's safe and acceptable.

Duncan

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


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Max Bolingbroke
2008/9/9 Sean Leather [EMAIL PROTECTED]:

 My tests are making use of a nice console test runner I wrote that
 supports both HUnit and QuickCheck (and is extensible to other test
 providers by the user):
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/test-framework.

 The description looks great! I might have to try it out.

Great!

 I used HUnit with QuickCheck 2, so that I could run QC properties as HUnit
 tests. QC2 has the added ability (over QC1) to run a property and return a
 Bool instead of just exiting with an error, and that works nicely within
 HUnit. Does test-framework do something else to support QC running
 side-by-side with HUnit?

You can see the approach I've taken in the QuickCheck test provider
source code: 
http://github.com/batterseapower/test-framework/tree/master/Test/Framework/Providers/QuickCheck.hs.
Basically, I just copy-pasted the relevant part of the QuickCheck
source code so I could customise it to my whim :-). I'm not familiar
with the QC2 API, but it's possible I would have had to do this anyway
in order to get progress reporting for QuickCheck tests without them
writing directly to the console (which is _bad_ when there are several
property running at once!) and to obtain the random seed.

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


Re: [Haskell-cafe] Re: Field names

2008-09-09 Thread wren ng thornton

Justin Bailey wrote:

2008/9/8 Daryoush Mehrtash [EMAIL PROTECTED]
 Thanks.

 Pattern matching and memory management in Haskell (or may be GHC
 implementation of it) is somewhat of a mystery to me.  Are there
 any references that explains the underlying implementation?

Be careful what you ask for. This paper is 16 years old but fairly
relevant. Click the view or download link at the bottom:

  Implementing Lazy Functional Languages on Stock Hardware: The
Spineless Tagless G-Machine
  http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.3729



That's an excellent paper for getting down to the gritty details of 
what's going on under the covers. However, I think it's not clear that 
that's what you're really looking for; you needn't know anything about 
the STG in order to know how pattern matching works enough to use it.



In short, a pattern is a (free) variable, or a data constructor applied 
to patterns. So if we have:


  data MyList = Nil | Cons Int MyList

Then we can have the patterns: Nil, (Cons x xs), (Cons 0 xs),..., (Cons 
x Nil), (Cons 0 Nil),..., (Cons x (Cons x2 xs)), etc.


Other notes:

* As demonstrated above, numeric literals count as data constructors.

* Since a data constructor can be an infix operator (either spelled with 
backticks or a symbolic name beginning with ':' ) we can also write our 
patterns with infix notation.


* Even though there is an intentional homoiconicity between patterns and 
an expression of data constructors, you can't use arbitrary expressions. 
 This falls out from only allowing data constructors in patterns, 
rather than any arbitrary function.


** In particular, you can't use partial application. You also can't use 
anything like (.), ($), flip,...


** (While n+k patterns exist for legacy reasons, they are an 
abomination. They should not be used and are slated for removal in 
haskell prime.)


** For record syntax this homoiconicity means that you get Foo{xpart=x} 
as a pattern binding the variable x. This follows because that's what 
the expression would look like to construct a Foo setting the xpart to a 
variable x. Perhaps confusingly, the '=' involved here is the one from 
record syntax, not the one from let bindings.



The homoiconicity generally makes code easier to read, though it can be 
somewhat confusing when discussing theoretical concerns. The reason is 
that a single lexeme, e.g. 'Cons', is being used both as a data 
constructor (in expressions) and as a data *de*structor (in patterns). 
Identically, a field name in a record is used both as an injector and as 
a projector. This conceptual overloading is perfectly valid, but it 
sometimes leads to people conflating the ideas which is invalid.


There are sometimes reasons to want to throw a wrench into the works, 
breaking up the homoiconicity. One particular example (which I believe 
will be available in 6.10 though it's not approved for haskell prime) is 
to allow view patterns. The idea behind view patterns is to allow 
functions to be called behind the scenes in order to convert the 
in-memory representation into a view type, and then do pattern matching 
on that view of the value rather than on the value itself. There are two 
primary uses of this: (1) improving legibility of pattern matching for 
complex datastructures, (2) allowing multiple types to all be pattern 
matched interchangeably, e.g. association lists, Maps, HashMaps,...


There are drawbacks to views (and anything else that breaks 
homoiconicity). First off is that it greatly complicates the story of 
what's going on during pattern matching. More importantly, however, is 
that it means that pattern matches are no longer in correspondence with 
the in-memory representations of values. This means that there is a 
hidden performance cost which can get quite high for deep patterns.


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


Re: [Haskell-cafe] trying to understand monad transformers....

2008-09-09 Thread wren ng thornton

Daryoush Mehrtash wrote:

The MaybeT transformer is defined as:

newtype MaybeT m a = MaybeT {runMaybeT :: m (Maybe a)}




Question:  What does runMaybeT x mean?


As for what does it do, I think everyone else has handled that pretty 
well. As far as what does it mean, it may help to think categorically.


For every monad |m| we have another monad |MaybeT m|. If we ignore some 
details, we can think of the transformed monad as |Maybe| composed with 
|m|, sic: |Maybe . m|. With this perspective, runMaybeT is inverting 
|MaybeT m| into |m . Maybe| by pushing the Maybe down over/through the 
monad m. Hence we can envision the function as:


 | runMaybeT   :: (MaybeT m) a - (m . Maybe) a
 | runMaybeT NothingT   = return Nothing
 | runMaybeT (JustT ma) = fmap Just ma

The reason this is useful at all is that Maybe is not just any monad, 
but is also a primitive value in the system. That is, once we have a 
Maybe value we can treat it as a normal pure value that we can pattern 
match on etc. For other monads like Set, [ ], and LogicMonad this means 
that we can iterate over their elements rather than just treating them 
as functors. Whereas a |MaybeT m| value can't be accessed directly.


This explanation is leaving out details about transformers in general. 
The Maybe/MaybeT type is defined by Maybe(a)=a+1, which is to say it's 
the same as the type |a| plus one additional value. Given this 
definition it's easy to define runMaybeT like above. For other monads 
and monad transformers this conversion might not be so trivial because 
we'll need to thread state through the computation.


This is also the reason why the ordering of your transformer stack is 
important. When converting from the transformer to the composition, how 
to thread the state is non-trivial. This is just the same as saying that 
we can't reorder function compositions and still have the same results. 
A large class of functions do have reorderable compositions[1] just like 
a large class of monads have trivial state, but in general that's not 
the case for either of them.



[1] 
http://haskell.org/haskellwiki/The_Monad.Reader/Issue4/Why_Attribute_Grammars_Matter


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


Re: [Haskell-cafe] Haskell and Java

2008-09-09 Thread wren ng thornton

Maurí­cio wrote:

Hi,

I use Haskell, and my friends at
work use Java. Do you think it
could be a good idea to use Haskell
with Java, so I could understand
and cooperate with them? Is there a
a Haskell to Java compiler that's
already ready to use?


Generally speaking, not really. There was a lot of work around the turn 
of the century, but all of it seems to have dried up and been replaced 
by Scala. I can give you some links on various projects, but so far as I 
know there's nothing that's still being maintained/developed so I 
wouldn't suggest any of them for work.


I don't know much about Scala, though there are a few folks on Planet 
Haskell who do. If you're looking for a Haskell-like functional language 
for the JVM, it may be for you.


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


Re: [Haskell-cafe] Re: Haskell stacktrace

2008-09-09 Thread wren ng thornton

Pieter Laeremans wrote:

This :
Prelude let f = (\x - return something went wrong)  ::   IOError - IO
String
Prelude let t = return $ show $ too short list !! 100 :: IO String
Prelude catch t f
*** Exception: Prelude.(!!): index too large

doesn't work.



As others've said, the right answer is to correct the bug rather than 
doing exception handling, but in as far as knowing how to do exception 
handling for pure functions, consider:


  http://code.haskell.org/~wren/wren-extras/Control/Exception/Extras.hs

The trickiest thing to watch out for is that you must strictly evaluate 
the expression or else the return/evaluate function will just lazily 
thunk up the expression. Which means that when you finally run the IO, 
you'll have already stripped off the IO wrapper that can catch the 
exception prior to evaluating the expression (which then throws an 
exception out past the catcher).


Another thing to watch out for is that Prelude.catch doesn't do what you 
want because the H98 spec declares these exceptions to be uncatchable. 
The Control.Exception.catch function does what you want and is portable 
even though it's not H98.


If you're doing the unsafePerformIO trick to purify your exception 
handling be sure to give a NOINLINE pragma to prevent potentially buggy 
inlining. You should also be sure that the handler is something which is 
actually safe to unsafePerformIO.


Finally, to ensure that other optimizations or evaluation orders don't 
accidentally mess you up, you should take the higher-order approach of 
`safely` to ensure that you don't accidentally apply the function prior 
to wrapping it up in a catcher.


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


Re: [Haskell-cafe] packages and QuickCheck

2008-09-09 Thread Johannes Waldmann

Jason Dagit wrote:


  On the other hand, specifying tests was
as simple as starting a function name with prop_ [...]


which of course reminds us of JUnit of the dark ages (up to 3.8),
before they finally used annotations to declare test cases.

Has there ever been a discussion of typed, user-definable,
user-processable source code annotations for Haskell?

J.W.




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