[Haskell-cafe] Re: Problematic irrefutable pattern matching of existentials

2006-10-02 Thread Ross Paterson
On Sun, Oct 01, 2006 at 08:05:15PM -0700, [EMAIL PROTECTED] wrote: I have come to realize that irrefutable pattern matching of existentials may indeed be problematic. Let us consider the following existential data type data FE = forall a. Typeable a = Foo a | forall a. Typeable a =

[Haskell-cafe] Re: [Haskell] Replacing and improving pattern guards with PMC syntax

2006-10-02 Thread Brandon Moore
[EMAIL PROTECTED] wrote: ... So far I never considered it important to devise a concrete syntax for PMC, but triggered by the current pattern guards thread on haskell-prime, I now try to give a PMC syntax that blends well with Haskell. I think with some alterations your syntax would blend

Re: [Haskell-cafe] How can I redirect stdout?

2006-10-02 Thread Krasimir Angelov
Hi Matthew, On Windows stdout/stderr/stdin exists only when your application is using the Console OS subsystem. All GUI applications doesn't have console window and they don't have stdout/stderr/stdin. When you are building DLLs then the subsystem is determined from the type of the application

Re: [Haskell-cafe] non lazy io

2006-10-02 Thread Bulat Ziganshin
Hello Matt, Friday, September 29, 2006, 10:31:10 AM, you wrote: I would like a non-lazy alternative to readFile is there such a thing in the libraries? i recommend you to use readFile from FPS library. it's strict (unles you use Lazy module) and then you can either use returned ByteString

Re: [Haskell-cafe] How would you replace a field in a CSV file?

2006-10-02 Thread Bulat Ziganshin
Hello tpledger, Monday, October 2, 2006, 3:11:29 AM, you wrote: For such a small self-contained task, I don't think Haskell is any better than Python. i disagree. while it's hard to beat Python version in number of lines, Haskell version may have the same length and better performance. for

[Haskell-cafe] Typeclass vs. Prolog programming

2006-10-02 Thread Martin Sulzmann
[EMAIL PROTECTED] writes: There is a great temptation to read the following declarations class Pred a b instance (Ord b, Eq b) = Pred [Int] b instance Pred Bool Bool as a Prolog program: pred([int],B) - ord(B),eq(B). pred(bool,bool). (In

Re: [Haskell-cafe] non lazy io

2006-10-02 Thread Matt Roberts
Cheers mate, That was exactly what I was looking for matt On 02/10/2006, at 4:18 PM, Bulat Ziganshin wrote: Hello Matt, Friday, September 29, 2006, 10:31:10 AM, you wrote: I would like a non-lazy alternative to readFile is there such a thing in the libraries? i recommend you to

Re: [Haskell-cafe] question - which monad to use?

2006-10-02 Thread Matthias Fischmann
hi, i don't fully understand your problem, but perhaps you could use iterate to produce a list or type [Result a], ie, of all computation steps, and then use this function to extract either result or error from the list: type Failmessage = Int data Result a = Root a | Failure Failmessage

Re: [Haskell-cafe] question - which monad to use?

2006-10-02 Thread Tamas K Papp
Matthias, Sorry if I was not clear in stating the problem. Your solution works nicely, but I would like to try writing a monad. This is what I came up with: type Failure = String data Computation a = Computation (Either Failure a) [a] instance Monad Computation where (Computation (Left e)

Re: [Haskell-cafe] question - which monad to use?

2006-10-02 Thread Tamas K Papp
On Mon, Oct 02, 2006 at 11:35:40AM -0400, Tamas K Papp wrote: Matthias, Sorry if I was not clear in stating the problem. Your solution works nicely, but I would like to try writing a monad. This is what I came up with: type Failure = String data Computation a = Computation (Either

[Haskell-cafe] cumulative sum

2006-10-02 Thread Tamas K Papp
Hi, I have two lists, p and lambda (both are finite). I would like to calculate 1) the cumulative sum of lambda, ie if lambda = [lambda1,lambda2,lambda3,...] then csum lambda = [lambda1,lambda1+lambda2,lambda1+lambda2+lambda3,...] 2) the cumulative sum of p*lambda (multiplication

Re: [Haskell-cafe] cumulative sum

2006-10-02 Thread Michael Shulman
On 10/2/06, Tamas K Papp [EMAIL PROTECTED] wrote: Hi, I have two lists, p and lambda (both are finite). I would like to calculate 1) the cumulative sum of lambda, ie if lambda = [lambda1,lambda2,lambda3,...] then csum lambda = [lambda1,lambda1+lambda2,lambda1+lambda2+lambda3,...] Try

Re: [Haskell-cafe] question - which monad to use?

2006-10-02 Thread Matthias Fischmann
On Mon, Oct 02, 2006 at 11:42:22AM -0400, Tamas K Papp wrote: To: haskell-cafe@haskell.org From: Tamas K Papp [EMAIL PROTECTED] Date: Mon, 2 Oct 2006 11:42:22 -0400 Subject: Re: [Haskell-cafe] question - which monad to use? On Mon, Oct 02, 2006 at 11:35:40AM -0400, Tamas K Papp wrote:

Re: [Haskell-cafe] cumulative sum

2006-10-02 Thread Chad Scherrer
Tamas, try scanl (+) 0 for the cumulative sum From there the zipWith idea you mentioned seems like the way to go. -Chad Hi, I have two lists, p and lambda (both are finite). I would like to calculate 1) the cumulative sum of lambda, ie if lambda = [lambda1,lambda2,lambda3,...] then

Re: [Haskell-cafe] cumulative sum

2006-10-02 Thread Matthias Fischmann
try scanl (+) 0 for the cumulative sum and it is probably worth pointing out once more that (as i have learned only recently :-) Hoogle can help you even quicker than this list with questions like these: scanl is the fifth answer if you ask for a - [a] - [a]. also, the url is easy to

[Haskell-cafe] Re: question - which monad to use?

2006-10-02 Thread apfelmus
Tamas K Papp wrote: Hi, I have a computation where a function is always applied to the previous result. However, this function may not return a value (it involves finding a root numerically, and there may be no zero on the interval). The whole problem has a parameter c0, and the function

[Haskell-cafe] Re: How would you replace a field in a CSV file?

2006-10-02 Thread apfelmus
Pete Kazmier wrote: import Data.ByteString.Lazy.Char8 as B hiding (map,foldr) import Data.List (map) import Data.Map as M hiding (map) -- This will be populated from a file dict = M.singleton (B.pack Pete) (B.pack Kazmier) main = B.interact $ B.unlines . map doline . B.lines where

[Haskell-cafe] Re: Problematic irrefutable pattern matching of existentials

2006-10-02 Thread apfelmus
[EMAIL PROTECTED] wrote: I have come to realize that irrefutable pattern matching of existentials may indeed be problematic. Let us consider the following existential data type data FE = forall a. Typeable a = Foo a | forall a. Typeable a = Bar a The following tests type and run

[Haskell-cafe] DiffTime in Data.Time

2006-10-02 Thread Chad Scherrer
I'm trying to use Data.Time, and I'm totally confused. DiffTime is abstract, and I don't see anything that maps into it. How do I construct one? I would like to then use the result to create a value of type UTCTime, but it seems (currently) like this might be easier. Thanks, -- Chad Scherrer

Re: [Haskell-cafe] irrefutable patterns for existential types / GADTs

2006-10-02 Thread John Meacham
On Sat, Sep 30, 2006 at 01:38:28AM -0700, [EMAIL PROTECTED] wrote: It seems that irrefutable pattern match with existentials is safe. The fact that irrefutable pattern match with GADT is unsafe has been demonstrated back in September 2004. it is safe in that you can't express coerce, but

[Haskell-cafe] Either as a Monad instance

2006-10-02 Thread Thomas Conway
Hi All, I've been [trying to] grapple with the various monads and transformers, and it occurs to me that the standard instance for Either as a monadic type is unnecessarily restrictive. Is there a compelling reason that it is not just instance Monad (Either e) where return = Right (Left

[Haskell-cafe] Re: DiffTime in Data.Time

2006-10-02 Thread Ashley Yakeley
Chad Scherrer wrote: I'm trying to use Data.Time, and I'm totally confused. DiffTime is abstract, and I don't see anything that maps into it. How do I construct one? I would like to then use the result to create a value of type UTCTime, but it seems (currently) like this might be easier. It's

[Haskell-cafe] Re: DiffTime in Data.Time

2006-10-02 Thread Chad Scherrer
Ok, that's much simpler than I was making it. fromIntegral or fromRational does the trick. Obvious in hindsight, I guess. Thanks! -Chad On 10/2/06, Ashley Yakeley [EMAIL PROTECTED] wrote: Chad Scherrer wrote: I'm trying to use Data.Time, and I'm totally confused. DiffTime is abstract, and I