[Haskell-cafe] replicateM over vectors

2010-04-01 Thread Scherrer, Chad
Hi, I'd like to be able to do replicateM, but over a vector instead of a list. Right now I'm doing this: import qualified Data.Vector.Generic as G import qualified Data.Vector.Unboxed.Mutable as M replicateM n action = do mu - M.unsafeNew n let go !i | i n = action = M.unsafeWrite mu i

RE: [Haskell-cafe] mapping unfreeze over an IntMap of IOUArrays

2008-11-11 Thread Scherrer, Chad
Bulat wrote: Hello Chad, Tuesday, November 11, 2008, 10:23:09 PM, you wrote: using unsafeFreeze. I'm getting stuck here, since the IntMap library is not so monad-friendly. Data.Hashtable is Well, I need mutable update for a while... after that, I prefer a pure interface, which is

[Haskell-cafe] Trouble with Cabal

2006-05-22 Thread Scherrer, Chad
Thanks to all who responded about the benefits of using Cabal. After trying out Bulat's Streams library, I thought I would download ByteString (aka FPS) to compare the wc demos. To compile something using Streams, I need to use a -i flag (thanks Bulat). When I followed the README that comes with

RE: [Haskell-cafe] Trouble with Cabal

2006-05-22 Thread Scherrer, Chad
-Original Message- From: Henning Thielemann [mailto:[EMAIL PROTECTED] Install locally after configuring this way: ./Setup.lhs configure --user --prefix=$HOME/yourlocalhaskelllibsdir That seemed to do fine until it came to registering the package, which I don't permission for.

RE: [Haskell-cafe] Trouble with Cabal

2006-05-22 Thread Scherrer, Chad
AM To: Scherrer, Chad Cc: Henning Thielemann; haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Trouble with Cabal On 5/22/06, Scherrer, Chad [EMAIL PROTECTED] wrote: -Original Message- From: Henning Thielemann [mailto:[EMAIL PROTECTED] Install locally after configuring

[Haskell] parallel seq

2006-04-25 Thread Scherrer, Chad
I was thinking about the dynamic behavior of par, and there's something that's a little confusing to me. Am I right in understanding that (x `par` y) evaluates to y, and may or may not evaluate x along the way? I think it would be easier to reason about if we knew that x would be evaluated,

Re: [Haskell-cafe] Packed String parameters

2006-01-19 Thread Scherrer, Chad
Thanks, Bulat. Taking a look at Hal's FastIO library now... Hal, it looks like your library could be helpful, especially if there is a way to construct a FastIO.Handle from stdin. Can this be done, or do I need to start with an actual file? Thanks, Chad

[Haskell-cafe] Packed String parameters

2006-01-18 Thread Scherrer, Chad
To read a file using a packed string, I need to use this function, right? hGetPS :: Handle - Int - IO PackedString What's the Int? Do you have to specify the length in advance? I don't know how packed strings are implemented, and I'm having trouble finding much documentation. I'm trying to

[Haskell-cafe] RE: Haskell vs. Clean

2006-01-05 Thread Scherrer, Chad
Daniel, My knowledge of Clean is fairly limited (even more so than my knowledge of Haskell), but no one seems to be responding to this, so I'll take a crack at it. Here is why I've stuck with Haskell instead of Clean: 1. It runs well on Linux 2. The license is more open 3. There is a

RE: [Haskell-cafe] RE: Haskell vs. Clean

2006-01-05 Thread Scherrer, Chad
PROTECTED] Sent: Thursday, January 05, 2006 1:58 PM To: Scherrer, Chad Cc: [EMAIL PROTECTED]; haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] RE: Haskell vs. Clean Hi My knowledge of Clean is fairly limited Mine too, but one of the biggest differences is that Clean has uniqueness types

[Haskell-cafe] Shootout favoring imperative code

2006-01-04 Thread Scherrer, Chad
Several people on this list have said that the shootout favors imperative code. Is this really the case? Why is it Clean seems to have no trouble (for the incomplete set of benchmarks that are written in it)? http://shootout.alioth.debian.org/clean.php How difficult would it be to translate

RE: [Haskell-cafe] Shootout favoring imperative code

2006-01-04 Thread Scherrer, Chad
--- Sebastian Sylvan [EMAIL PROTECTED] wrote: Some of the problems seem to be heavily geared towards an imperative *implementation*, meaning that a Haskell version is hardly idiomatic Haskell (and as such I , and I suspect otehrs, really have no inclination to work on it). This may be

RE: [Haskell-cafe] RE: module names

2005-12-29 Thread Scherrer, Chad
Yes, good point. I suppose there's really no need to re-declare main once it's been imported. Thanks! -Original Message- From: Remi Turk [mailto:[EMAIL PROTECTED] Sent: Thu 12/29/2005 4:34 PM To: Scherrer, Chad Cc: S Koray Can; haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] RE

[Haskell-cafe] Re: problems with square roots...

2005-12-21 Thread Scherrer, Chad
From: Daniel Carrera [EMAIL PROTECTED] Hey, The sqrt function is not doing what I want. This is what I want: round sqrt(2) --- Daniel, A lot of Haskell folks like to avoid parentheses as much as possible, and there's a really

[Haskell-cafe] RE: Haskell-Cafe Digest, Vol 28, Issue 66

2005-12-20 Thread Scherrer, Chad
From: Daniel Carrera [EMAIL PROTECTED] Robert Dockins wrote: -divides a b = (mod a b == 0) +divides a b = (mod b a == 0) Oh, thanks. My program assumed one way to define 'divides' and the example assumed the other. When I wrote it I was thinking of (divides a) being a function that

[Haskell-cafe] RE: module names

2005-12-16 Thread Scherrer, Chad
-Original Message- From: S Koray Can [mailto:[EMAIL PROTECTED] Why not do this: name none of those modules Main.hs, and have an empty module Main.hs with only import MainDeJour and main = MainDeJour.main so you can just edit just that file. Cheers, Koray

[Haskell-cafe] module names

2005-12-15 Thread Scherrer, Chad
Something about the way module names are specified in a file seems really strange to me. When I first started learning Haskell (I had used OCaml previously), I tried things like module Main where import A import B main = A.f B.f module A where f = ... module B where f =

[Haskell-cafe] STM reference?

2005-12-08 Thread Scherrer, Chad
Hi, Can anyone suggest some references to learn how to program using GHC with threads? I've read a little bit about STM, but it's still pretty mysterious to me. Is this the best approach to take? I've never used threads in any language, but monads are fairly comfortable for me. Thanks! Chad

[Haskell-cafe] Re: Verbosity of imperative code

2005-12-07 Thread Scherrer, Chad
On Tue, Dec 06, 2005 at 10:58:45PM +0300, Bulat Ziganshin wrote: the third-priority problem is language itself. in particular, i hate Haskell school of imperative manipulations: x' - readIORef x y' - readIORef y writeIORef z (x'*y') Here's a way to make some of this less messy:

[Haskell-cafe] Re: returning lists

2005-12-02 Thread Scherrer, Chad
raptor [EMAIL PROTECTED] writes, ]- that is the problem :), 'cause such functions should accept Char and String, but return a Tuple of Strings, but it is recursive (so that it fetch next,next,next char :)) i.e. it is own consumer and should return String --this is wrong, just tring grab char

[Haskell-cafe] syntactic sugar for comonads

2005-12-02 Thread Scherrer, Chad
Hi, I'm wondering about a syntactic sugar for comonads. These are still very new to me, but it seems like their usage will become much more common once manipulations are more convenient (I believe this was the case with monads and arrows, correct?). Here's an example for motivation. Consider

RE: [Haskell-cafe] Re: :t main

2005-12-02 Thread Scherrer, Chad
From: Cale Gibbard [mailto:[EMAIL PROTECTED] See: http://haskell.org/pipermail/haskell-cafe/2003-January/003794.html The OI comonad as previously envisioned breaks referential transparency. I/O just doesn't seem to be something which one can easily do comonadically, since once

[Haskell-cafe] :t main

2005-11-29 Thread Scherrer, Chad
I've been reading some of the articles about comonads, and I thought the idea of giving main the type OI () - () was pretty interesting. So I was wondering, would it be possible to allow the type of main to be inferred? It seems like IO () OI () - () OI () - IO () all make sense (at least I

RE: [Haskell-cafe] Function application like a Unix pipe

2005-11-23 Thread Scherrer, Chad
Henning Thielemann [EMAIL PROTECTED] writes: Since (a . b) x a $ b x a (b x) are equivalent, do you also want to reverse function and argument in order to match argument order of . and $ ? That is x (b . a) x b $ a (x b) a ? I'm sorry, I'm not sure I understand your

RE: [Haskell-cafe] Function application like a Unix pipe

2005-11-23 Thread Scherrer, Chad
Henning Thielemann [EMAIL PROTECTED] writes: I want to say, that the order of symbols for ($), (.) and function application is consistent. This is a fine thing. I think that shall not be distroyed by giving ($) and (.) reversed argument order. I see. I like the argument order also,

RE: [Haskell-cafe] Function application like a Unix pipe

2005-11-23 Thread Scherrer, Chad
Udo Stenzel [EMAIL PROTECTED] writes: The unix pipe is actually function composition. Its argument (standard input) isn't explicitly mentioned Then it seems Unix must overload the | operator. I typically use it to do things like grep . *.hs | wc So I think of the types as being grep .

Re: [Haskell-cafe] Function application like a Unix pipe

2005-11-22 Thread Scherrer, Chad
Albert Lai [EMAIL PROTECTED] writes: I offer a simpler, more direct, and pre-existing correspondence between a functional programming construct and unix pipes: Maybe my point wasn't clear. Of course this idea of comparing lazy evaluation to Unix pipes is very old (long before July 2004, I'm

[Haskell-cafe] Function application like a Unix pipe

2005-11-18 Thread Scherrer, Chad
I'm still trying to settle on a feel for good programming style in Haskell. One thing I've been making some use of lately is (\|) = flip ($) infixl 0 \| Then expressions like f4 $ f3 $ f2 $ f1 $ x become x \| f1 \| f2 \| f3 \| f4 I've seen something like this on haWiki using (#), but I

RE: [Haskell] specification of sum

2005-11-02 Thread Scherrer, Chad
Surely not... sum is defined by Haskell 98 as: sum = foldl (+) 0 and this is exactly what GHC provides. Furthermore we have specialised strict versions for Int and Integer. I'd been using ghci for testing along the way and getting terrible results; does the specialization only

[Haskell] specification of sum

2005-11-01 Thread Scherrer, Chad
I was wondering... In my experience, it's worked much better to use sum' = foldl' (+) 0 than the built-in sum function, which leaks memory like crazy for large input lists. I'm guessing the built-in definition is sum = foldr (+) 0 But as far as I know, (+) is always strict, so foldl' seems

RE: [Haskell] specification of sum

2005-11-01 Thread Scherrer, Chad
You don't always want (+) to be strict. Consider working with the ring of formal power series over, say, the integers. You don't want (+) to force the evaluation of an infinite formal summation which is passed to it, since that's an infinite loop, so it will have to be non-strict,

[Haskell] RE: specification of sum

2005-11-01 Thread Scherrer, Chad
The solution would be to bring 'sum' and 'product' into the Num class so the most efficient version for each type can be used and the default is no worse than the current non-class versions. (this is even pretty much completly backwards compatable so could be considered for haskell 06) I'd

[Haskell-cafe] Nice way to calculate character frequency in a string

2005-10-26 Thread Scherrer, Chad
Sorry to drag this thread out, but here's one more thing you might try... I was thinking, if we just wanted something like intTable :: [Int] - [(Int, Int)] we could just replace Map with IntMap in the previous solution: intTable xs = IntMap.assocs $! foldl' f IntMap.empty xs where f m x =

[Haskell-cafe] Re: Nice way to calculate character frequency in a string

2005-10-25 Thread Scherrer, Chad
Hello, I need to calculate the frequency of each character in a String. And if I can do this really well in C, I don't find a nice (and fast) answer in haskell. I tried several functions, listed below, and even the fastest do a lot of unnecessary things : A while back, I was trying to

[Haskell-cafe] RE: Typing problems with basic arithmetic - help!

2005-09-24 Thread Scherrer, Chad
For some reason the following code is producing an error message from ghci that the the patterns are non-exhaustive. Does anyone have any idea why that could be, given that the patterns are, at least in my meaning, provably exhaustive? You forgot to match against the empty list. Try

Re: [Haskell] Mixing monadic and non-monadic functions

2005-09-08 Thread Scherrer, Chad
One of Mark Jones's articles suggests something like class Plus a b c | a b - c where (+) :: a - b - c Would instance (Plus a b c, Monad m) = Plus (m a) (m b) (m c) where mx + my = do x - mx y - my return (x + y) do what you're looking for? Chad Scherrer

[Haskell] FunDeps and MArray

2005-09-05 Thread Scherrer, Chad
Hi, I'm trying to use functionally dependent typeclasses to create an overloaded (+=) function. A simplified example of a first bit of code is... class PlusEq a b c | a b - c where (+=) :: a - b - c instance (MArray a e m, Num e, Ix i) = PlusEq (a i e) (a i e) (m ()) where (+=) x y

[Haskell] reading call graphs

2005-08-23 Thread Scherrer, Chad
When I compile with ghc -prof -auto-all, I end up with a .prof file that starts out like this: individualinherited COST CENTRE MODULE no.entries %time %alloc %time %alloc MAIN MAIN 1 0 0.00.0 100.0 100.0

[Haskell-cafe] RE: Random matrices

2005-08-22 Thread Scherrer, Chad
Ah ha. That'll do. Lesson: avoid hidden space leaks in monads. Hmm, I'm still missing something. It seems a good lesson, but practically speaking, it doesn't help me any more than saying write efficient programs. What could I have looked for in the original code to predict it may be leaky? Is

RE: [Haskell] Random matrices

2005-08-21 Thread Scherrer, Chad
in general? Or maybe some gains were made by switching from using StdGen with a specified seed to using the OS-supplied random number generator? -Chad -Original Message- From: Donald Bruce Stewart [mailto:[EMAIL PROTECTED] Sent: Fri 8/19/2005 7:42 PM To: Scherrer, Chad Cc: haskell

RE: [Haskell] stack overflow - nonobvious thunks?

2005-07-29 Thread Scherrer, Chad
Thanks! I was confused at first because ghci still runs into memory problems, though no longer stack overflows. ghc runs it beautifully, though. -Chad -Original Message- From: Amanda Clare [mailto:[EMAIL PROTECTED] Sent: Thursday, July 28, 2005 3:20 AM To: Dean Herington Cc: Scherrer

[Haskell] stack overflow - nonobvious thunks?

2005-07-27 Thread Scherrer, Chad
Title: stack overflow - nonobvious thunks? I'm trying to write a function to build a table of values from a list. Here's my current attempt: table :: (Ord a) = [a] - [(a,Int)] table xs = Map.assocs $! foldl' f Map.empty xs where f m x = Map.insertWith (+) x 1 m The ($!) and the

RE: [Haskell] combining IntMaps

2005-07-27 Thread Scherrer, Chad
? The distinction between the two lists is still vague to me. -Chad -Original Message- From: Adrian Hey [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 27, 2005 12:04 AM To: Scherrer, Chad Cc: haskell@haskell.org Subject: Re: [Haskell] combining IntMaps Hello, On Tuesday 26 Jul 2005 7:58 pm, Scherrer

RE: [Haskell] stack overflow - nonobvious thunks?

2005-07-27 Thread Scherrer, Chad
for very large n like this. -Chad -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 27, 2005 11:02 AM To: Scherrer, Chad Cc: haskell@haskell.org Subject: Re: [Haskell] stack overflow - nonobvious thunks? Scherrer, Chad wrote: f m x

RE: [Haskell] combining IntMaps

2005-07-26 Thread Scherrer, Chad
functionality could not have otherwise been provided in an efficient way without going into the guts of Data.Set? Chad Scherrer -Original Message- From: Adrian Hey [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 20, 2005 10:57 PM To: Scherrer, Chad; haskell@haskell.org Subject: Re: [Haskell

[Haskell] combining IntMaps

2005-07-19 Thread Scherrer, Chad
Title: combining IntMaps I'm using the (IntMap Int) type to implement functions (Int - Int), by treating non-keys as values that map to zero. I'd like to be able to add two of these pointwise, and delete the key from the resulting map when the sum of the values is zero. My specification is