Re: [Haskell-cafe] How to implement the mean function

2011-06-30 Thread Ruohao Li
Thanks for the SO link, change the Num a constraint to Real a and using realToFrac then it just works. On Fri, Jul 1, 2011 at 2:11 PM, Jack Henahan wrote: > Additionally, this SO question[0] is nearly identical, and provides a > little more elaboration. > > [0]: > http://stackoverflow.com/questi

Re: [Haskell-cafe] Patterns for processing large but finite streams

2011-06-30 Thread Eugene Kirpichov
Plain old lazy lists do not allow me to combine multiple concurrent computations, e.g. I cannot define average from sum and length. 2011/7/1 Heinrich Apfelmus : > Eugene Kirpichov wrote: >> >> I'm rewriting timeplot to avoid holding the whole input in memory, and >> naturally a problem arises: >>

Re: [Haskell-cafe] Patterns for processing large but finite streams

2011-06-30 Thread Heinrich Apfelmus
Eugene Kirpichov wrote: I'm rewriting timeplot to avoid holding the whole input in memory, and naturally a problem arises: How to represent large but finite streams and functions that process them, returning other streams or some kinds of aggregate values? Examples: * Adjacent differences of a

Re: [Haskell-cafe] Patterns for processing large but finite streams

2011-06-30 Thread dm-list-haskell-cafe
At Fri, 1 Jul 2011 09:39:32 +0400, Eugene Kirpichov wrote: > > Hi, > > I'm rewriting timeplot to avoid holding the whole input in memory, and > naturally a problem arises: > > How to represent large but finite streams and functions that process > them, returning other streams or some kinds of ag

Re: [Haskell-cafe] How to implement the mean function

2011-06-30 Thread Lyndon Maydwell
The problem is that you need to convert (length xs) to a Num, then return a Fractional. On Fri, Jul 1, 2011 at 2:07 PM, Nathan Howell wrote: > (/) operates on a Fractional instance... but length returns an Int, which is > not a Fractional. > You can convert the Int to a Fractional instance: > mea

Re: [Haskell-cafe] How to implement the mean function

2011-06-30 Thread Jack Henahan
Additionally, this SO question[0] is nearly identical, and provides a little more elaboration. [0]:http://stackoverflow.com/questions/2376981/haskell-types-frustrating-a-simple-average-function On Jul 1, 2011, at 2:07 AM, Ruohao Li wrote: > For mean xs = sum xs / length xs, I got the following:

Re: [Haskell-cafe] How to implement the mean function

2011-06-30 Thread Ruohao Li
For mean xs = sum xs / fromIntegral (length xs), I got the following: test.hs:8:10: Could not deduce (Fractional a) from the context (Num a, Fractional b) arising from a use of `/' at test.hs:8:10-42 Possible fix: add (Fractional a) to the context of the type signature fo

Re: [Haskell-cafe] How to implement the mean function

2011-06-30 Thread Nathan Howell
(/) operates on a Fractional instance... but length returns an Int, which is not a Fractional. You can convert the Int to a Fractional instance: mean xs = sum xs / fromIntegral (length xs) or try an integer division: mean xs = sum xs `div` length xs -n On Thu, Jun 30, 2011 at 10:55 PM, Ruohao L

Re: [Haskell-cafe] How to implement the mean function

2011-06-30 Thread Ruohao Li
For mean xs = sum xs / length xs, I got the following: test.hs:8:10: No instance for (Fractional Int) arising from a use of `/' at test.hs:8:10-27 Possible fix: add an instance declaration for (Fractional Int) In the expression: sum xs / length xs In the definition of `mean':

Re: [Haskell-cafe] How to implement the mean function

2011-06-30 Thread aditya siram
What compiler errors are you getting? -deech On Fri, Jul 1, 2011 at 12:55 AM, Ruohao Li wrote: > Hi guys, > I just started learning some Haskell. I want to implement a mean function to > compute the mean of a list. The signature of the function is: > mean :: (Num a, Fractional b) => [a] -> b > Bu

[Haskell-cafe] How to implement the mean function

2011-06-30 Thread Ruohao Li
Hi guys, I just started learning some Haskell. I want to implement a mean function to compute the mean of a list. The signature of the function is: mean :: (Num a, Fractional b) => [a] -> b But when I implement this simple function, the compiler keep whining at me on type errors. I know this is wr

[Haskell-cafe] Patterns for processing large but finite streams

2011-06-30 Thread Eugene Kirpichov
Hi, I'm rewriting timeplot to avoid holding the whole input in memory, and naturally a problem arises: How to represent large but finite streams and functions that process them, returning other streams or some kinds of aggregate values? Examples: * Adjacent differences of a stream of numbers * G

Re: [Haskell-cafe] Printing the empty list.

2011-06-30 Thread Ivan Lazar Miljenovic
On 1 July 2011 11:35, Brent Yorgey wrote: > On Fri, Jul 01, 2011 at 09:05:05AM +1000, Ivan Lazar Miljenovic wrote: >> On 1 July 2011 08:58, Joshua Ball wrote: >> > GHCi seems to be clever about some things: >> > >> > If I try to print the empty list in ghci, I encounter no problems: >> > >> > Pre

Re: [Haskell-cafe] Printing the empty list.

2011-06-30 Thread Brent Yorgey
On Fri, Jul 01, 2011 at 09:05:05AM +1000, Ivan Lazar Miljenovic wrote: > On 1 July 2011 08:58, Joshua Ball wrote: > > GHCi seems to be clever about some things: > > > > If I try to print the empty list in ghci, I encounter no problems: > > > > Prelude> [] > > [] > > Prelude> show [] > > "[]" > > P

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Philipp Schneider
On 06/30/2011 11:46 PM, Holger Siegel wrote: > Am 30.06.2011 um 22:57 schrieb Philipp Schneider: > >> On 06/30/2011 09:49 PM, Holger Siegel wrote: >>> (...) But that won't work: After you have evaluated an entry of the >>> environment, you store the resulting value but you throw away its updated

Re: [Haskell-cafe] Printing the empty list.

2011-06-30 Thread Ivan Lazar Miljenovic
On 1 July 2011 08:58, Joshua Ball wrote: > GHCi seems to be clever about some things: > > If I try to print the empty list in ghci, I encounter no problems: > > Prelude> [] > [] > Prelude> show [] > "[]" > Prelude> print [] > [] > > Even though the type of the list is clearly unknown, it must be >

Re: [Haskell-cafe] Printing the empty list.

2011-06-30 Thread Brandon Allbery
On Thu, Jun 30, 2011 at 18:58, Joshua Ball wrote: > GHCi seems to be clever about some things: GHCi uses extended defaulting rules unless told otherwise, so in the absence of anything else it uses () as the type. You can enable this in GHC as well, with -XExtendedDefaultRules. See http://www.ha

[Haskell-cafe] Printing the empty list.

2011-06-30 Thread Joshua Ball
GHCi seems to be clever about some things: If I try to print the empty list in ghci, I encounter no problems: Prelude> [] [] Prelude> show [] "[]" Prelude> print [] [] Even though the type of the list is clearly unknown, it must be picking SOME type. (why does it print [] instead of "")? If I w

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Holger Siegel
Am 30.06.2011 um 22:57 schrieb Philipp Schneider: > On 06/30/2011 09:49 PM, Holger Siegel wrote: >> (...) But that won't work: After you have evaluated an entry of the >> environment, you store the resulting value but you throw away its updated >> environment. That means, you lose the results o

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Philipp Schneider
On 06/30/2011 09:49 PM, Holger Siegel wrote: > Am 30.06.2011 um 20:23 schrieb Philipp Schneider: > >> On 06/30/2011 02:36 PM, Holger Siegel wrote: >>> Am 29.06.2011 um 23:50 schrieb Philipp Schneider: >>> Hi cafe, in my program i use a monad of the following type newtype M

Re: [Haskell-cafe] ANNOUNCING: Hac PDX II - A Portland Haskell Hackathon

2011-06-30 Thread Alexander Solla
On Thu, Jun 30, 2011 at 12:55 PM, Thomas DuBuisson < thomas.dubuis...@gmail.com> wrote: > WHAT: A Haskell Hackathon > > WHEN: > July 22-24 (Friday, Saturday, Sunday) > 10:00 AM to 5:30 PM > > WHERE: > Forth Avenue Building (FAB, 1900 SW 4th Ave) Room 10 > Portland, Oregon 97201 > ... > Registratio

[Haskell-cafe] ANNOUNCING: Hac PDX II - A Portland Haskell Hackathon

2011-06-30 Thread Thomas DuBuisson
WHAT: A Haskell Hackathon WHEN: July 22-24 (Friday, Saturday, Sunday) 10:00 AM to 5:30 PM WHERE: Forth Avenue Building (FAB, 1900 SW 4th Ave) Room 10 Portland, Oregon 97201 WHERE, take 2: FAB10 is a small auditorium just inside the west most Harrison Street entrance. URL: http://haskell.org/has

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Holger Siegel
Am 30.06.2011 um 20:23 schrieb Philipp Schneider: > On 06/30/2011 02:36 PM, Holger Siegel wrote: >> Am 29.06.2011 um 23:50 schrieb Philipp Schneider: >> >>> Hi cafe, >>> >>> in my program i use a monad of the following type >>> >>> newtype M a = M (State -> (a, State)) >>> >>> i use the monad

[Haskell-cafe] ANNOUNCE: mime-mail-ses 0.0.0

2011-06-30 Thread Michael Snoyman
Hi all, I'd like to announce the first release of mime-mail-ses[1]. This provides easy integration between the mime-mail package[2] and Amazon's Simple Email Service. This package was written for the Haskellers website[3], purely because I despise setting up mail servers. There aren't many more f

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Philipp Schneider
On 06/30/2011 08:25 PM, Philipp Schneider wrote: > On 06/30/2011 02:36 PM, Holger Siegel wrote: >> Am 29.06.2011 um 23:50 schrieb Philipp Schneider: >> >>> Hi cafe, >>> >>> in my program i use a monad of the following type >>> >>> newtype M a = M (State -> (a, State)) >>> >>> i use the monad in two

Re: [Haskell-cafe] what if two package contains same module?

2011-06-30 Thread Ertugrul Soeylemez
吴兴博 wrote: > it seems that cabal install different into different folders. if two > package contains same module name, can they all exist? since cabal > have no "remvoe" or "uninstall". how can I hide some packages? Alternatively for small programs for which you don't use a Cabal file you can

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Philipp Schneider
On 06/30/2011 02:36 PM, Holger Siegel wrote: > Am 29.06.2011 um 23:50 schrieb Philipp Schneider: > >> Hi cafe, >> >> in my program i use a monad of the following type >> >> newtype M a = M (State -> (a, State)) >> >> i use the monad in two different ways. The type variable "a" can be a >> pair as i

Re: [Haskell-cafe] Confused about my IterIO code

2011-06-30 Thread dm-list-haskell-cafe
At Thu, 30 Jun 2011 23:53:02 +1000, John Ky wrote: > > But all I've done is: > > enum |$ inumReverseLines .| iter > > inumReverseLines = mkInum $ do >   line <- lineI >   return (L.reverse (L.concat [line, C.pack "\n"])) mkInum repeatedly invokes its iter argument so as to ke

Re: [Haskell-cafe] Confused about my IterIO code

2011-06-30 Thread Brandon Allbery
On Thu, Jun 30, 2011 at 09:53, John Ky wrote: > enum |$ inumReverseLines .| iter > inumReverseLines = mkInum $ do >   line <- lineI >   return (L.reverse (L.concat [line, C.pack "\n"])) > > No attempt was made to reverse more than one line - at least as far as I can > see.  What have I done wrong

[Haskell-cafe] Confused about my IterIO code

2011-06-30 Thread John Ky
Hi Hakell Cafe, I'm struggling to understand my unambitious IterIO code that somehow manages to work. Basically I run an echo server that is supposed to read from a socket line by line and write back to the socket with all the characters in the line reversed: import Control.Exception import Cont

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Wolfgang Braun
"An environment contains local variable bindings, so no subcomputation will ever need to return its environment. " - That is not true. A subcomputation can possible modify an environment except the language forbids such a case. On 06/30/2011 02:36 PM, Holger Siegel wrote: > Am 29.06.2011 um 2

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Holger Siegel
Am 29.06.2011 um 23:50 schrieb Philipp Schneider: > Hi cafe, > > in my program i use a monad of the following type > > newtype M a = M (State -> (a, State)) > > i use the monad in two different ways. The type variable "a" can be a > pair as in > > interp :: Term -> Environment -> M (Value,Env

Re: [Haskell-cafe] what if two package contains same module?

2011-06-30 Thread Heinrich Apfelmus
吴兴博 wrote: it seems that cabal install different into different folders. if two package contains same module name, can they all exist? since cabal have no "remvoe" or "uninstall". how can I hide some packages? The ghc-pkg program organizes GHC's package database. You want to run the command

Re: [Haskell-cafe] what if two package contains same module?

2011-06-30 Thread Ivan Lazar Miljenovic
On 30 June 2011 17:40, 吴兴博 wrote: > it seems that cabal install different into different folders. > if two package contains same module name, can they all exist? > since cabal have no "remvoe" or "uninstall". how can I hide some packages? ghc-pkg hide foo-1.2.3 This will work for using them in g

[Haskell-cafe] what if two package contains same module?

2011-06-30 Thread 吴兴博
it seems that cabal install different into different folders. if two package contains same module name, can they all exist? since cabal have no "remvoe" or "uninstall". how can I hide some packages? Cheers! 吴兴博  Wu Xingbo ___ H