[Haskell-cafe] Proposal for adding finallyError to MonadError

2013-08-08 Thread David Sorokin

Hi, Café!

I have a proposal. I offer to add a new function to the MonadError type 
class:


  finallyError :: MonadError e m = m a - m b - m a

This is a generalization of the standard finally function that has the 
following signature:


  finally: IO a - IO b - IO a

Like function finally, the finallyError function runs the first 
computation and then runs the second computation regardless of whether 
an error might arise in the first computation. The first computation 
defines the result.


Introducing semantics of a possible cancellation of the m computation, 
the finallyError function accepts an additional meaning. The second 
computation must be performed even in case of cancelling the 
computation, while function catchError must be ignored. It literally 
means that the finallyError function cannot be expressed in terms of the 
catchError function.


This idea is essentially inspired by the F# async workflow that does 
allow cancelling the Async computation. I implemented a similar monad 
Simulation.Aivika.Cont.Cont for my simulation library Aivika [1]. My 
monad Cont is an extension of the standard monad with the same name. It 
uses continuations (namely, three different continuations within one 
computation). It supports the exception handling and it allows 
cancelling the computation (the liftIO function should also call 
finallyError to catch the possible cancellation event if my Cont was a 
generic monad transformer).


In the simulation the cancellation of the computation (actually, of the 
discontinuous process) is a typical use case. Therefore it should be 
executed as fast as possible. If I raised a specialized IOException for 
the cancellation event, then it would be a more costly operation. This 
is a practical point why the finallyError function cannot be expressed 
in terms of catchError.


Another reason is that the catchError function can eat the cancellation 
exception, which would be absolutely unacceptable. This is a theoretical 
reason for introducing finallyError.


The finallyError function is very useful for guaranteed releasing the 
external resources (such as the modeled entities in Aivika) in case of 
raising an exception and even in case of cancelling the active 
computation, which is important for simulation, for example.


Regarding the standard instances of MonadError, the finallyError 
function seems to be simple for implementing. It is difficult mainly for 
the Cont-based monads. So, in Aivika it is more difficult than 
catchError for my Cont monad.


The actual name of the function is not important but here it looks 
consistent with other functions of the MonadError type class.


Finally, the finallyError function can be actually defined in an 
additional type class, which would extend MonadError like that how the 
ArrowChoice type class extends Arrow.


Kind regards,
David Sorokin

[1] https://github.com/dsorokin/aivika

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


[Haskell-cafe] Dual-licensing the package on Hackage

2013-07-30 Thread David Sorokin
Hi, Cafe!

Probably, it was asked before but I could not find an answer with help of 
Google.

I have a library which is hosted on Hackage. The library is licensed under 
BSD3. It is a very specialized library for a small target group. Now I'm going 
to relicense it and release a new version already under the dual-license: GPLv3 
and commercial. In most cases GPL will be sufficient as this is not a library 
in common sense.

Can I specify the GPL license in the .cabal file, or should I write 
OtherLicense?

I'm going to add the information about dual-licensing in the description 
section of the .cabal file, though.

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


Re: [Haskell-cafe] Dual-licensing the package on Hackage

2013-07-30 Thread David Sorokin
Thanks Thu,

I agree with you. Just I don't know what to write in the license field of the 
.cabal file: GPL or OtherLicense. The both choices seem correct to me and 
misleading at the same time.

Cheers,
David

30.07.2013, в 12:53, Vo Minh Thu написал(а):

 2013/7/30 David Sorokin david.soro...@gmail.com:
 Hi, Cafe!
 
 Probably, it was asked before but I could not find an answer with help of 
 Google.
 
 I have a library which is hosted on Hackage. The library is licensed under 
 BSD3. It is a very specialized library for a small target group. Now I'm 
 going to relicense it and release a new version already under the 
 dual-license: GPLv3 and commercial. In most cases GPL will be sufficient as 
 this is not a library in common sense.
 
 Can I specify the GPL license in the .cabal file, or should I write 
 OtherLicense?
 
 I'm going to add the information about dual-licensing in the description 
 section of the .cabal file, though.
 
 Although you can indeed license your software under different
 licences, in the case of your question it doesn't seem to be a concern
 with Hackage:
 
 The license displayed on Hackage is the one for the corresponding
 .cabal file (or at least I think it is). So you issue your new version
 with the changed license, the new version is available with the new
 license, the old versions are still available with the old license.
 Everything is fine.
 
 Now about the dual licensing. It seems it is again not a problem with
 Hackage: you are not granting through Hackage such a commercial
 license. I guess you provide it upon request (for some money). I.e.
 when I download your library from Hackage, I receive it under the
 terms of the BSD (or GPL) license you have chosen, not under a
 commercial license that I would have to receive through other means.
 
 Otherwise the semantic of the license field on Hackage would mean the
 library is available under such and such licenses, which are not
 granted to you when you download the library on Hackage. Only when you
 download the package you can actually find the licensing terms (e.g.
 in the LICENSE file). But this seems unlikely to me.
 
 Cheers,
 Thu


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


Re: [Haskell-cafe] Dual-licensing the package on Hackage

2013-07-30 Thread David Sorokin
I am inclined to use value OtherLicense but state in the description 
that the package is available either under GPL or a commercial license. 
The latter must be requested to me. Then there would be no required 
additional steps to use the package under GPL. Only the LICENSE file 
must be appropriate. Probably, I will need two files LICENSE and 
LICENSE-GPLv3. In the former I will have add my copyright and write in a 
simple form that the license is dual and everyone is free to use the 
library under GPLv3 (which is the main use case) according the terms 
provided in the corresponded second file.


Thanks,
David

On 30.07.2013 13:57, Vo Minh Thu wrote:

Unless you want to provide multiple open source licenses, I don't see the point:

Anybody that needs a commercial license (and has some money) will
simply ask for such a commercial license when seeing that the code is
available under GPL.

Another reason it is pointless is that you will certainly not want to
list all the commercial licenses you have used/will use with different
clients (there are virtually infinite commercial licenses that you can
invent as needs arise: per seat, per core, per year, and so on
depending on the clients/projects).

I.e. you don't need to state upfront that commercial licences exist
(although I understand that you think it is better to advertise your
willingness to provide such commercial license, but a comment is
enough, the fact is that license is not provided through Hackage).

2013/7/30 Krzysztof Skrzętnicki gte...@gmail.com:

Perhaps it would be best if .cabal allowed to have more than one license
listed.

Another solution would be to use custom field, for example:

License: GPL
x-Other-License: Commercial, see License-Commercial.txt

All best,
Krzysztof Skrzętnicki

On Tue, Jul 30, 2013 at 11:44 AM, David Sorokin david.soro...@gmail.com
wrote:

Thanks Thu,

I agree with you. Just I don't know what to write in the license field of
the .cabal file: GPL or OtherLicense. The both choices seem correct to me
and misleading at the same time.

Cheers,
David

30.07.2013, в 12:53, Vo Minh Thu написал(а):


2013/7/30 David Sorokin david.soro...@gmail.com:

Hi, Cafe!

Probably, it was asked before but I could not find an answer with help
of Google.

I have a library which is hosted on Hackage. The library is licensed
under BSD3. It is a very specialized library for a small target group. Now
I'm going to relicense it and release a new version already under the
dual-license: GPLv3 and commercial. In most cases GPL will be sufficient as
this is not a library in common sense.

Can I specify the GPL license in the .cabal file, or should I write
OtherLicense?

I'm going to add the information about dual-licensing in the
description section of the .cabal file, though.

Although you can indeed license your software under different
licences, in the case of your question it doesn't seem to be a concern
with Hackage:

The license displayed on Hackage is the one for the corresponding
.cabal file (or at least I think it is). So you issue your new version
with the changed license, the new version is available with the new
license, the old versions are still available with the old license.
Everything is fine.

Now about the dual licensing. It seems it is again not a problem with
Hackage: you are not granting through Hackage such a commercial
license. I guess you provide it upon request (for some money). I.e.
when I download your library from Hackage, I receive it under the
terms of the BSD (or GPL) license you have chosen, not under a
commercial license that I would have to receive through other means.

Otherwise the semantic of the license field on Hackage would mean the
library is available under such and such licenses, which are not
granted to you when you download the library on Hackage. Only when you
download the package you can actually find the licensing terms (e.g.
in the LICENSE file). But this seems unlikely to me.

Cheers,
Thu


___
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] Dual-licensing the package on Hackage

2013-07-30 Thread David Sorokin

This is already another question what license to use :)

On 30.07.2013 14:56, Vo Minh Thu wrote:

Again I haven't seen a reason to do what you propose: virtually every
single GPL library author would gladly accept money for their work to
be used in a closed source setting, no need to use OtherLicense to
reach that effect.

On the other hand, you will stop people interested in open source to
look further into your project if they see OtherLicense instead of a
well-known open-source license.

2013/7/30 David Sorokin david.soro...@gmail.com:

I am inclined to use value OtherLicense but state in the description that
the package is available either under GPL or a commercial license. The
latter must be requested to me. Then there would be no required additional
steps to use the package under GPL. Only the LICENSE file must be
appropriate. Probably, I will need two files LICENSE and LICENSE-GPLv3. In
the former I will have add my copyright and write in a simple form that the
license is dual and everyone is free to use the library under GPLv3 (which
is the main use case) according the terms provided in the corresponded
second file.

Thanks,
David


On 30.07.2013 13:57, Vo Minh Thu wrote:

Unless you want to provide multiple open source licenses, I don't see the
point:

Anybody that needs a commercial license (and has some money) will
simply ask for such a commercial license when seeing that the code is
available under GPL.

Another reason it is pointless is that you will certainly not want to
list all the commercial licenses you have used/will use with different
clients (there are virtually infinite commercial licenses that you can
invent as needs arise: per seat, per core, per year, and so on
depending on the clients/projects).

I.e. you don't need to state upfront that commercial licences exist
(although I understand that you think it is better to advertise your
willingness to provide such commercial license, but a comment is
enough, the fact is that license is not provided through Hackage).

2013/7/30 Krzysztof Skrzętnicki gte...@gmail.com:

Perhaps it would be best if .cabal allowed to have more than one license
listed.

Another solution would be to use custom field, for example:

License: GPL
x-Other-License: Commercial, see License-Commercial.txt

All best,
Krzysztof Skrzętnicki

On Tue, Jul 30, 2013 at 11:44 AM, David Sorokin david.soro...@gmail.com
wrote:

Thanks Thu,

I agree with you. Just I don't know what to write in the license field
of
the .cabal file: GPL or OtherLicense. The both choices seem correct to
me
and misleading at the same time.

Cheers,
David

30.07.2013, в 12:53, Vo Minh Thu написал(а):


2013/7/30 David Sorokin david.soro...@gmail.com:

Hi, Cafe!

Probably, it was asked before but I could not find an answer with help
of Google.

I have a library which is hosted on Hackage. The library is licensed
under BSD3. It is a very specialized library for a small target group.
Now
I'm going to relicense it and release a new version already under the
dual-license: GPLv3 and commercial. In most cases GPL will be
sufficient as
this is not a library in common sense.

Can I specify the GPL license in the .cabal file, or should I write
OtherLicense?

I'm going to add the information about dual-licensing in the
description section of the .cabal file, though.

Although you can indeed license your software under different
licences, in the case of your question it doesn't seem to be a concern
with Hackage:

The license displayed on Hackage is the one for the corresponding
.cabal file (or at least I think it is). So you issue your new version
with the changed license, the new version is available with the new
license, the old versions are still available with the old license.
Everything is fine.

Now about the dual licensing. It seems it is again not a problem with
Hackage: you are not granting through Hackage such a commercial
license. I guess you provide it upon request (for some money). I.e.
when I download your library from Hackage, I receive it under the
terms of the BSD (or GPL) license you have chosen, not under a
commercial license that I would have to receive through other means.

Otherwise the semantic of the license field on Hackage would mean the
library is available under such and such licenses, which are not
granted to you when you download the library on Hackage. Only when you
download the package you can actually find the licensing terms (e.g.
in the LICENSE file). But this seems unlikely to me.

Cheers,
Thu


___
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] catching IO errors in a monad transformer stack

2013-07-18 Thread David Sorokin
Hi!

The exception handling is a difficult thing. It is usually simple enough but 
sometimes it can be very difficult, especially when using continuations within 
the monadic computation. To feel it, I often remember how the exceptions are 
handled in the F# async workflow (the sources are open), but their approach 
should be slightly adopted for Haskell what I did in one my simulation library 
(as far as I understand, the IO exception cannot arise in a pure value; 
therefore IOException should be caught in another place, namely in the liftIO 
function). 

I'm not sure whether there is a common pattern for handling the exceptions (the 
mentioned MonadCatchIO instance contains a warning regarding ContT). Therefore 
it is reasonable to allow the programmer himself/herself to define these 
handlers through the type class.

Thanks,
David

19.07.2013, в 3:23, Alberto G. Corona написал(а):

 Hi Eric:
  
 The pattern may be the MonadCatchIO class:
  
 http://hackage.haskell.org/package/MonadCatchIO-transformers
 
 
 2013/7/18 Eric Rasmussen ericrasmus...@gmail.com
 Hello,
 
 I am writing a small application that uses a monad transformer stack, and I'm 
 looking for advice on the best way to handle IO errors. Ideally I'd like to 
 be able to perform an action (such as readFile file_that_does_not_exist), 
 catch the IOError, and then convert it to a string error in MonadError. 
 Here's an example of what I'm doing now:
 
 {-# LANGUAGE FlexibleContexts #-}
 
 import Control.Monad.Error
 import Control.Monad.State
 
 import System.IO.Error (tryIOError)
 
 catcher :: (MonadIO m, MonadError String m) = IO a - m a
 catcher action = do
   result - liftIO $ tryIOError action
   case result of
 Left  e - throwError (show e)
 Right r - return r
 
 This does work as expected, but I get the nagging feeling that I'm missing an 
 underlying pattern here. I have tried catch, catchError, and several others, 
 but (unless I misused them) they don't actually help here. The tryIOError 
 function from System.IO.Error is the most helpful, but I still have to 
 manually inspect the result to throwError or return to my underlying monad.
 
 Since this has come up for me a few times now, I welcome any advice or 
 suggestions on alternative approaches or whether this functionality already 
 exists somewhere.
 
 Thanks!
 Eric
 
 
 
 
 
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 
 
 
 -- 
 Alberto.
 ___
 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] ANNOUNCE: Aivika v0.6, Aivika Experiment v0.3, Aivika Experiment Chart v0.3

2013-07-17 Thread David Sorokin

Hi!

I’m glad to announce new versions of the Aivika [1] simulation library 
and its additional packages Aivika Experiment [2] and Aivika Experiment 
Chart [3]. The library is divided to decrease the dependency on GTK, 
although all three were tested on Linux, Windows and OS X.


They allow developing the wide range of simulation models (SD, DES, AM), 
simulating them and saving the results in form of charts, tables and so 
on, automating many routine procedures. The architecture is quite flexible.


This is a result of my 4-years work since 2009. I finally find the 
library a quite mature. Among many languages I tried, Haskell was the 
most suitable. Many simulation concepts can be naturally expressed in 
terms of Haskell. Many technical details are hidden either under the 
façade of monads, or similar structures.


So, the ordinary differential equations can be elegantly defined using 
the recursive do-notation. But the discontinuous processes are well 
expressed using the continuations, if more precisely, three 
continuations in one computation.


I prepared a 55-page PDF document An Introduction to Aivika Simulation 
Library [4]. For demonstration, it contains some charts prepared with 
help of Aivika Experiment Chart. There are the deviation charts and 
histograms.


Thanks,
David

[1] http://hackage.haskell.org/package/aivika
[2] http://hackage.haskell.org/package/aivika-experiment
[3] http://hackage.haskell.org/package/aivika-experiment-chart
[4] https://github.com/dsorokin/aivika/blob/master/doc/aivika.pdf

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


Re: [Haskell-cafe] Modeling the performance of a non-trivial software app

2011-05-10 Thread David Sorokin

On 05/11/2011 07:55 AM, C K Kashyap wrote:

Hi,
I was wondering if it would be a good idea to model a software app's 
performance using Haskell. The idea is a little abstract in my mind 
right now. I'll try and illustrate it with an example - Let's say, I 
want to model a web app - to, model it, I could think of the following 
entities -


1. One or more clients and as many connections (essentially bandwidth 
of each connection)

2. A Load balancer ( and bandwidths to the webservers)
3. Bunch of webservers (and bandwidths to the database server)
4. A database server

Using the model, I could generate performance characteristics and 
figure out if database is the bottleneck or not ... if so, what level 
of  sharding would be useful etc


Is there already a wheel I am trying to re-invent? Has anyone 
attempted this?


Regards,
kashyap


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Sometimes it is possible to write the corresponded model. Then the model 
can be simulated to receive the performance characteristics. Much 
depends on that how precise the model is. The keywords are Discrete 
Event Simulation (DES) and Theory of Queue. It may require some maths.


I wrote a small library called Aivika[1]. Perhaps it might be helpful.

David

[1]http://hackage.haskell.org/package/aivika

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


Re: [Haskell-cafe] Computational Physics in Haskell

2011-03-30 Thread David Sorokin

31.03.2011 08:57, Mihai Maruseac пишет:

On Thu, Mar 31, 2011 at 1:50 AM, KCkc1...@gmail.com  wrote:

I'd also like to know of any Haskell programs for
theoretical/computational physics.

H!

Maybe converting such programs to Haskell.


On Wed, Mar 30, 2011 at 11:23 AM, Azeem -ul-Hasanaze...@live.com  wrote:

I started learning Haskell a little while ago. Although I am a novice I am
still in love with it.
I am physics major and primarily interested in Theoretical Physics and would
like to use Haskell in this area. So, I just know to what has been done in
this area, are there any libraries for simulating physical process in
Haskell etc.

Don't know if this is what you're looking for but I found this pages:
[1], [2], [3]. Maybe one of them will contain what you're looking for.

[1]: http://hackage.haskell.org/packages/archive/pkg-list.html#cat:physics
[2]: 
http://hackage.haskell.org/packages/archive/pkg-list.html#cat:scientific%20simulation
[3]: http://hackage.haskell.org/packages/archive/pkg-list.html#cat:simulation



I think that Aivika[3] doesn't suit this task, although it can integrate 
the ordinary differential equations but they are relatively slow as the 
focus was mainly on the hybrid simulation and DES. As far as I 
understand, the fields are quite different.


David

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