[Haskell-cafe] Re: Missing join and split

2007-12-29 Thread ChrisK
Albert Y. C. Lai wrote: Mitar wrote: I am really missing the (general) split function built in standard Haskell. I do not understand why there is something so specific as words and lines but not a simple split? The same goes for join. Don't forget Text.Regex.splitRegex. Which is just:

[Haskell-cafe] Re: what does @ mean?.....

2007-12-28 Thread ChrisK
Nicholls, Mark wrote: Hello, I wonder if someone could answer the following… The short question is what does @ mean in mulNat a b | a = b = mulNat' a b b | otherwise = mulNat' b a a where mulNat' x@(S a) y orig | x == one = y

[Haskell-cafe] Re: Wikipedia on first-class object

2007-12-28 Thread ChrisK
This thread is obviously a source of much fun. I will play too. Cristian Baboi wrote: On Fri, 28 Dec 2007 18:32:05 +0200, Jules Bean [EMAIL PROTECTED] wrote: Cristian Baboi wrote: Let me ask you 3 simple questions. Can one use Haskell to make dynamically linked libraries (DLL on Windows,

[Haskell-cafe] Re: Missing join and split

2007-12-28 Thread ChrisK
Lihn, Steve wrote: Programmer with perl background would think split like: list of string = split regex original string Since regex is involved, it is specific to (Byte)String, not a generic list. Also it appears one would need help from Text.Regex(.PCRE) to do that. intercalate a

[Haskell-cafe] Re: Doing some things right

2007-12-28 Thread ChrisK
Brian Sniffen wrote: On Dec 28, 2007 6:05 AM, Andrew Coppin [EMAIL PROTECTED] wrote: [I actually heard a number of people tell me that learning LISP would change my life forever because LISP has something called macros. I tried to learn it, and disliked it greatly. It's too messy. And what the

[Haskell-cafe] Re: data vs newtype

2007-12-18 Thread ChrisK
Jonathan Cast wrote: So there is a program (or, rather, type) you can write with newtype that can't be written with data: newtype T = T T That compiles, and anything of type T is ⊥. But it breaks my mental model of what the compiler does for newtypes. I always think of them as differently

[Haskell-cafe] Re: array documentation is missing

2007-12-17 Thread ChrisK
I have received patches which will help Cabal make ghc-6.6 and gc-6.8 friendly regex-tdfa. The problem below is from a change in STUArray from 3 to 4 parameters going from 6.6 to 6.8. I think adding another '_' to each pattern match makes it work for 6.8. Once I get these patches working

[Haskell-cafe] Re: Is StateT what I need?

2007-12-17 Thread ChrisK
Andre Nathan wrote: Hello (Newbie question ahead : I tried this for insertProc, but it obviously doesn't work... what would be the correct way to do this? insertProc :: Pid - StateT PsMap IO PsInfo insertProc pid = do proc - procInfo pid -- XXX this is obviously wrong... psMap - get

[Haskell-cafe] Re: IO is a bad example for Monads

2007-12-11 Thread ChrisK
Michael Vanier wrote: I haven't been following this thread closely, but would it be rude to suggest that someone who doesn't want to put the effort into learning the (admittedly difficult) concepts that Haskell embodies shouldn't be using the language? Sorry Michael, but I will take your

[Haskell-cafe] Re: Waiting for thread to finish

2007-12-06 Thread ChrisK
Jules Bean wrote: ChrisK wrote: A safer gimmick... Ben Franksen wrote: tickWhileDoing :: String - IO a - IO a tickWhileDoing msg act = do hPutStr stderr msg hPutChar stderr ' ' hFlush stderr start_time - getCPUTime tickerId - forkIO ticker ... an async exception here will leave

[Haskell-cafe] Re: regex package for yhc?

2007-12-06 Thread ChrisK
Thomas Hartman wrote: Is there some way to use any of the various regex packages on hackage via yhc? Has anyone installed one them successfully? I'd like regex-tdfa, but would settle for regex-posix, or really, anything that brings the convenience of regex to yhc. In general, is there a

[Haskell-cafe] Re: Looking for smallest power of 2 = Integer

2007-12-04 Thread ChrisK
Sterling Clover wrote: Actually, I suspect GHC's strictness analyzer will give you reasonable performance with even the naive version, but fancier ideas are at http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog If given an 'n' you are looking for the (2^x) such that 2^x = n

[Haskell-cafe] Re: Array copying

2007-12-03 Thread ChrisK
Reinier Lamers wrote: ChrisK wrote: For GHC 6.6 I created foreign import ccall unsafe memcpy memcpy :: MutableByteArray# RealWorld - MutableByteArray# RealWorld - Int# - IO () {-# INLINE copySTU #-} copySTU :: (Show i,Ix i,MArray (STUArray s) e (ST s)) = STUArray s i e

[Haskell-cafe] Re: Array copying

2007-12-03 Thread ChrisK
Andrew Coppin wrote: ChrisK wrote: For GHC 6.6 I created foreign import ccall unsafe memcpy memcpy :: MutableByteArray# RealWorld - MutableByteArray# RealWorld - Int# - IO () {-# INLINE copySTU #-} copySTU :: (Show i,Ix i,MArray (STUArray s) e (ST s)) = STUArray s i e

[Haskell-cafe] Re: Array copying

2007-12-02 Thread ChrisK
Andrew Coppin wrote: Andrew Coppin wrote: copy :: Word32 - IOUArray Word32 Bool - Word32 - IO (IOUArray Word32 Bool) copy p grid size = do let size' = size * p grid' - newArray (1,size') False mapM_ (\n - do b - readArray grid n if b then mapM_ (\x - writeArray

[Haskell-cafe] Re: Waiting for thread to finish

2007-11-28 Thread ChrisK
A safer gimmick... Ben Franksen wrote: tickWhileDoing :: String - IO a - IO a tickWhileDoing msg act = do hPutStr stderr msg hPutChar stderr ' ' hFlush stderr start_time - getCPUTime tickerId - forkIO ticker ... an async exception here will leave the ticker runnning res -

[Haskell-cafe] Re: Waiting for thread to finish

2007-11-27 Thread ChrisK
Maurí­cio wrote: Hi, After I have spawned a thread with 'forkIO', how can I check if that thread work has finished already? Or wait for it? Thanks, Maurício The best way to do this is using Control.Exception.finally: myFork :: IO () - IO (ThreadId,MVar ()) myFork todo = m -

[Haskell-cafe] Re: Dynamically find out instances of classes (pluginsystem for haskell)

2007-11-22 Thread ChrisK
the standard way to do that is use an existential wrapper: (This needs -fglasgow-exts or some flags) module Main where class Interface x where withName :: x - String data A = A String instance Interface A where withName (A string) = Interface A with ++ string ++ data B = B

[Haskell-cafe] Re: Dynamically find out instances of classes (pluginsystem for haskell)

2007-11-22 Thread ChrisK
Jason Dusek wrote: ChrisK [EMAIL PROTECTED] wrote: the standard way to do that is use an existential wrapper: Does this relate to the basket of fruit problem in object oriented languages? You created the existential wrapper to allow a multimorphic list type? When you access

ANNOUNCE: Important bug fix for regex-pcre ByteStrings.

2007-11-20 Thread ChrisK
Greetings, There are new version 0.82 and 0.93 of regex-posix. If you use regex-posix with Data.ByteString then you should upgrade to obtain a fix for a crash error. There are new version of regex-pcre available on hackage and the two darcs repositories:

[Haskell-cafe] Re: user error when using Text.Regex.PCRE

2007-11-20 Thread ChrisK
Thank you very much for the error report. I have tracked down the cause. You are searching against an empty Bytestring. This is now represented by -- | /O(1)/ The empty 'ByteString' empty :: ByteString empty = PS nullForeignPtr 0 0 And while the useAsCString and useAsCStringLen functions

[Haskell-cafe] ANNOUNCE: Important bug fix for regex-pcre ByteStrings.

2007-11-20 Thread ChrisK
Greetings, There are new version 0.82 and 0.93 of regex-posix. If you use regex-posix with Data.ByteString then you should upgrade to obtain a fix for a crash error. There are new version of regex-pcre available on hackage and the two darcs repositories:

[Haskell-cafe] Re: Knot tying vs monads

2007-11-19 Thread ChrisK
John D. Ramsdell wrote: On Nov 17, 2007 3:04 PM, apfelmus [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Unfortunately, I don't have Paulson's book (or any other ML book :) at home. I'm too lazy to figure out the specification from the source code, I guess the code is too opaque,

[Haskell-cafe] Re: Knot tying vs monads

2007-11-19 Thread ChrisK
The data dependency is circular. The case e of Str and Brk are not-circular: layout examines the input parameters to determine column'. Then column' is used to compute columnOut and s'. Then the current data is prepended to s'. The Blo case is the circular one. Pushing the circular

[Haskell-cafe] Re: Weird ghci behaviour?

2007-11-14 Thread ChrisK
' versus 'Main' prompt is a UI feature for experts, not for new users. Making this more obvious or verbose or better documented does not fix the lack of control the user feels. The only flags that the user can easily find are those listed by --help: chrisk$ ghci --help Usage: ghci

[Haskell-cafe] Re: let vs. where

2007-11-13 Thread ChrisK
Dan Piponi wrote: On Nov 13, 2007 1:24 PM, Ryan Ingram [EMAIL PROTECTED] wrote: I tend to prefer where, but I think that guards function declarations are more readable than giant if-thens and case constructs. Up until yesterday I had presumed that guards only applied to functions. But I

Odd error report against ghc-6.8.1

2007-11-09 Thread ChrisK
[EMAIL PROTECTED] has sent me a new bug report. Apparently he can crash ghc-6.8.1 when compiling regex-tdfa-0.93 (darcs under http://darcs.haskell.org/packages/regex-unstable/regex-tdfa/ ). Should I open a ticket for this? I darcs got the newest regex-tdfa (0.93 iirc) and made all the

[Haskell-cafe] Re: ByteString search code available in easy-to-digest form

2007-11-09 Thread ChrisK
Yeah, my code wants to open up the internals of Lazy bytestrings. Until recently this was possible toChunks, but it would be best to rewrite it for the newest Lazy representation (which comes with new shiny ghc 6.8.1). It is a trivial change, but I due to ghc-6.8.1 failing on ppc G4 OS X, I

[Haskell-cafe] Odd error report against ghc-6.8.1

2007-11-09 Thread ChrisK
[EMAIL PROTECTED] has sent me a new bug report. Apparently he can crash ghc-6.8.1 when compiling regex-tdfa-0.93 (darcs under http://darcs.haskell.org/packages/regex-unstable/regex-tdfa/ ). Should I open a ticket for this? I darcs got the newest regex-tdfa (0.93 iirc) and made all the

[Haskell-cafe] Re: checking regular expressions

2007-11-09 Thread ChrisK
Hi, I wrote the regex-base API you are looking at. Uwe Schmidt wrote: Hi all, what's the simplest way to check, whether a given string is a wellformed regular expression? import Text.Regex.Posix.String(compile) or import Text.Regex.Posix.ByteString(compile) etc.. In the API there's

[Haskell-cafe] Regex API ideas

2007-11-01 Thread ChrisK
Hi Bryan, I wrote the current regex API, so your suggestions are interesting to me. The also goes for anyone else's regex API opinions, of course. Bryan O'Sullivan wrote: Ketil Malde wrote: Python used to do pretty well here compared to Haskell, with rather efficient hashes and text

[Haskell-cafe] Re: Need help from a newby

2007-11-01 Thread ChrisK
karle wrote: My declaration is as followed:- type Address = Int data Port = C | D deriving(Eq,Show) data Payload = UP[Char] | RTDP(Address,Port) deriving(Eq,Show) data Pkgtype = RTD | U deriving(Eq,Show) type Pkg = (Pkgtype,Address,Payload) type Table = [(Address,Port)]

[Haskell-cafe] Re: Proposal: register a package asprovidingseveralAPI versions

2007-10-17 Thread ChrisK
I disagree with Simon Marlow here. In practice I think Claus' definition of compatible is good enough: Simon Marlow wrote: Claus Reinke wrote: - consider adding a new monad transformer to a monad transformer library, or a new regex variant to a regex library - surely the new package

[Haskell-cafe] Re: [Haskell] Re: Trying to install binary-0.4

2007-10-16 Thread ChrisK
Simon Marlow wrote: Ultimately when things settle down it might make sense to do this kind of thing, but right now I think an easier approach is to just fix packages when dependencies change, and to identify sets of mutually-compatible packages (we've talked about doing this on Hackage

[Haskell-cafe] Re: [Haskell] Re: Trying to install binary-0.4

2007-10-16 Thread ChrisK
Don Stewart wrote: stefanor: On Mon, Oct 15, 2007 at 10:57:48PM +0100, Claus Reinke wrote: so i wonder why everyone else claims to be happy with the status quo? We aren't happy with the status quo. Rather, we know that no matter how much we do, the situation will never improve, so most of us

[Haskell-cafe] Proposal: register a package as providing several API versions

2007-10-16 Thread ChrisK
Simon Marlow wrote: Several good points have been raised in this thread, and while I might not agree with everything, I think we can all agree on the goal: things shouldn't break so often. I have another concrete proposal to avoid things breaking so often. Let us steal from something that

[Haskell-cafe] Re: do

2007-10-15 Thread ChrisK
[EMAIL PROTECTED] wrote: Peter Verswyvelen writes about non-monadic IO, unique external worlds: But... isn't this what the Haskell compiler runtime do internally when IO monads are executed? Passing the RealWorld singleton from action to action? In GHC, yes. I never looked into any

[Haskell-cafe] Re: do

2007-10-15 Thread ChrisK
Brandon S. Allbery KF8NH wrote: On Oct 15, 2007, at 13:32 , Peter Verswyvelen wrote: [EMAIL PROTECTED] wrote: Yes, *different approach*. So, there *are* differences. Compilers, anyway, are special applications. I wanted to see - responding to Brandon - a normal Haskell program, which

[Haskell-cafe] Re: pi

2007-10-10 Thread ChrisK
[EMAIL PROTECTED] wrote: Yitzchak Gale writes: Dan Piponi wrote: The reusability of Num varies inversely with how many assumptions you make about it. A default implementation of pi would only increase usability, not decrease it. Suppose I believe you. (Actually, I am afraid, I have

[Haskell-cafe] Re: Manual constructor specialization

2007-10-09 Thread ChrisK
Johan Tibell wrote: On 10/9/07, David Benbennick [EMAIL PROTECTED] wrote: On 10/9/07, Johan Tibell [EMAIL PROTECTED] wrote: data Rope = Empty | Leaf | Node !Rope !Rope The point is that Empty can only appear at the top by construction How about indicating this in your

[Haskell-cafe] Re: Space and time leaks

2007-10-05 Thread ChrisK
Dan Weston wrote: Ronald Guida wrote: I need some help with space and time leaks. I know of two types of space leak. The first type of leak occurs when a function uses unnecessary stack or heap space. GHCi sum [1..10^6] *** Exception: stack overflow Apparently, the default definition

[Haskell-cafe] Re: PROPOSAL: New efficient Unicode string library.

2007-10-02 Thread ChrisK
Deborah Goldsmith wrote: UTF-16 is the native encoding used for Cocoa, Java, ICU, and Carbon, and is what appears in the APIs for all of them. UTF-16 is also what's stored in the volume catalog on Mac disks. UTF-8 is only used in BSD APIs for backward compatibility. It's also used in plain

[Haskell-cafe] Re: Troubles understanding memoization in SOE

2007-09-26 Thread ChrisK
Peter Verswyvelen wrote: Paul L wrote: We recently wrote a paper about the leak problem. The draft is at http://www.cs.yale.edu/~hl293/download/leak.pdf. Comments are welcome! I'm trying to understand the following in this paper: (A) repeat x = x : repeat x or, in lambdas: (B) repeat =

[Haskell-cafe] Re: Haskell Cheat Sheet?

2007-09-25 Thread ChrisK
I disagree -- see below Dan Weston wrote: I suggest that it be removed and the real Control.Monad.Fix.fix function be defined in its own section, with an side-by-side comparison with a named recursive function. This would be useful because the type fix :: (a - a) - a is highly

[Haskell-cafe] Re: Building production stable software in Haskell

2007-09-17 Thread ChrisK
Philippa Cowderoy wrote: On Mon, 17 Sep 2007, Adrian Hey wrote: Ideally the way to deal with this is via standardised interfaces (using type classes with Haskell), not standardised implementations. Even this level of standardisation is not a trivial clear cut design exercise. e.g we

[Haskell-cafe] Re: Is take behaving correctly?

2007-09-12 Thread ChrisK
Conor McBride wrote: Hi folks On 12 Sep 2007, at 00:38, Brent Yorgey wrote: On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. [..] If for some reason you want a version that does return an error in

[Haskell-cafe] Re: Extending the idea of a general Num to other types?

2007-09-07 Thread ChrisK
Dan Piponi wrote: On 9/5/07, Ketil Malde [EMAIL PROTECTED] wrote: On Wed, 2007-09-05 at 08:19 +0100, Simon Peyton-Jones wrote: Error message from GHCi: test/error.hs:2:8: No instance for (Num String) arising from use of `+' at test/error.hs:2:8-17 Possible fix:

[Haskell-cafe] Re: Are type synonym families really equivalent to fundeps?

2007-09-03 Thread ChrisK
Chris Smith wrote: The following code builds and appears to work great (assuming one allows undecidable instances). I have tried both a natural translation into type synonym families, and also the mechanical transformation in http://www.cse.unsw.edu.au/~chak/papers/tyfuns.pdf -- but I

[Haskell-cafe] Re: Are type synonym families really equivalent to fundeps?

2007-09-03 Thread ChrisK
Ah... I see that I have a bug in my proposal, perhaps corrected below. 2. In the second and fourth instances, the type variable x appears twice in the parameters of the type function built from the fundep (a b - c). This causes an error. If I try adding (x ~ x') to the context and

[Haskell-cafe] Re: Are type synonym families really equivalent to fundeps?

2007-09-03 Thread ChrisK
There is are two oddities with your example that I am confused by. Code with fundeps is: data Var a = Var Int (Maybe String) data RHS a b = RHS a b class Action t a b c | a - t, a b - c, a c - b instance Action t () y y instance

[Haskell-cafe] Re: [ANN] An efficient lazy suffix tree library

2007-08-27 Thread ChrisK
Gleb Alexeyev wrote: Bryan O'Sullivan wrote: I just posted a library named suffixtree to Hackage. http://www.serpentine.com/software/suffixtree/ It implements Giegerich and Kurtz's lazy construction algorithm, with a few tweaks for better performance and resource usage. API docs:

[Haskell-cafe] Re: Parsec is being weird at me

2007-08-25 Thread ChrisK
Andrew Coppin wrote: Anybody want to explain to me why this doesn't work? ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.6.1, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \/\/ /_/\/|_| Type :? for help.

[Haskell-cafe] Re: Remember the future

2007-08-24 Thread ChrisK
Benjamin Franksen wrote: Simon Peyton-Jones wrote: | It is unfortunate that the [ghc] manual does not give the translation rules, or at | least the translation for the given example. Hmm. OK. I've improved the manual with a URL to the main paper

[Haskell-cafe] Re: Tying the knot with unknown keys

2007-08-21 Thread ChrisK
David Ritchie MacIver wrote: I was playing with some code for compiling regular expressions to finite state machines and I ran into the following problem. I've solved it, but I'm not terribly happy with my solution and was wondering if someone could come up with a better one. :-)

[Haskell-cafe] Re: trouble compiling import GHC.Prim(MutableByteArray#, ..... (building regex-tdfa from darcs) -- what's that # sign doing?

2007-08-19 Thread ChrisK
Stefan O'Rear wrote: On Fri, Aug 17, 2007 at 04:27:29PM -0400, Thomas Hartman wrote: trying to compile regex-tdfa, I ran into another issue. (earlier I had a cabal problem but that's resolved.) there's a line that won't compile, neither for ghc 6.6.1 nor 6.7 import

[Haskell-cafe] Very fast searching of byte strings

2007-08-17 Thread ChrisK
Post the the library mailing list at [1] is the Boyer-Moore algorithm implemented for strict and lazy bytestrings (and combinations thereof). It finds all the overlapping instances of the pattern inside the target. I have performance tuned it. But the performance for searching a strict

[Haskell-cafe] Re: [Haskell] View patterns in GHC: Request?for?feedback

2007-08-01 Thread ChrisK
Discussion continues below quoted text... Stefan O'Rear wrote: On Tue, Jul 31, 2007 at 03:31:54PM -0700, David Roundy wrote: On Mon, Jul 30, 2007 at 11:47:46AM +0100, Jon Fairbairn wrote: ChrisK [EMAIL PROTECTED] writes: And the readability is destroyed because you cannot do any type

[Haskell-cafe] Re: Backpatching

2007-08-01 Thread ChrisK
Thomas Conway wrote: One of the things that gets messy is that in lots of places you can put either a thing or a reference to a thing (i.e. the name of a thing defined elsewhere). For example, consider the production: NamedNumber ::= identifier ( SignedNumber ) |

[Haskell-cafe] Re: Knuth Morris Pratt for Lazy Bytestrings implementation

2007-08-01 Thread ChrisK
Justin Bailey wrote: On 7/31/07, Donald Bruce Stewart [EMAIL PROTECTED] wrote: jgbailey: Also, be sure to compare against a naive search, optimised for strict and lazy bytestrings, http://hpaste.org/1803 If its not faster than those 2, then you're doing something wrong :) -- Don

[Haskell-cafe] Re: Knuth Morris Pratt for Lazy Bytestrings implementation

2007-08-01 Thread ChrisK
I am still working on improving your code. And I have a Is this a bug? question: The lookup = computeLookup pat defines lookup to take an Int which represents the index into pat, where this index is 0 based and the 0th item is the head of pat. Now look at matchLength :: Int; matchLength = let

[Haskell-cafe] Re: Knuth Morris Pratt for Lazy Bytestrings implementation

2007-08-01 Thread ChrisK
My optimized (and fixed) version of the code is attached. I benchmarked it with: module Main(main) where import KMPSeq import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy.Char8 as BC infile = endo.dna Modified by one character from the original copied from

[Haskell-cafe] Re: [Haskell] View patterns in GHC: Request?for?feedback

2007-07-29 Thread ChrisK
And the readability is destroyed because you cannot do any type inference in your head. If you see { Matrix m = ; Matrix x = m * y; ...; } Then you know very little about the possible types of y since can only conclude that: Matrix can be multiplied by one or more types 'sometype'

[Haskell-cafe] Re: Space usage and CSE in Haskell

2007-07-26 Thread ChrisK
Melissa O'Neill wrote: For example, consider yet another variant of power_list: power_list l = [] : pow [[]] l where pow acc [] = [] pow acc (x:xs) = acc_x ++ pow (acc ++ acc_x) xs where acc_x = map (++ [x]) acc By many standards, this version is inefficient, with plenty of

[Haskell-cafe] Re: [Haskell] View patterns in GHC: Request for feedback

2007-07-26 Thread ChrisK
Jon Fairbairn wrote: I currently only get f :: [t] - something, so if I later discover that I need to change the input representation to be more efficient than lists, I have to rewrite f. Wouldn't it be so much nicer if I could simply add a declaration f:: Stream s = s t - something and get

Re: [Haskell-cafe] Threads talking back to parent

2005-11-03 Thread ChrisK
Joel Reymont wrote: So when should I use a STM TChan instead of a regular Chan? On Oct 31, 2005, at 10:08 PM, ChrisK wrote: Or perhaps a TChan, if that is more appropriate: http://www.haskell.org/ghc/docs/latest/html/libraries/stm/Control- Concurrent-STM-TChan.html I like the curried

Re: [Haskell-cafe] Threads talking back to parent

2005-10-31 Thread ChrisK
Or perhaps a TChan, if that is more appropriate: http://www.haskell.org/ghc/docs/latest/html/libraries/stm/Control-Concurrent-STM-TChan.html I like the curried command idiom: do chan - newChan let logToParent = writeChan chan do tChan - newTChan let logToParentSTM = writeTChan tChan

Re: [Haskell-cafe] Monads as control structures?

2005-10-27 Thread ChrisK
Try this: This line is before the loop sequence_ $ replicate 10 $ do line 1 line 2 ... last line This line is after the loop Now you can use shorthand via loopN n block = sequence_ $ replicate n block So that you can write: This line is before the loop loopN 10 $ do line 1 line 2

Re: [Haskell-cafe] Trouble understanding NewBinary

2005-10-07 Thread ChrisK
In GHC.Exts are the definitions data Char = C# Char# data Int = I# Int# data Integer = S# Int# | J# Int# ByteArray# data Double = D# Double# data Float = F# Float# Found with ghci using :m + GHC.Exts :browse GHC.Exts Joel Reymont wrote: Folks, In

Re: [Haskell-cafe] Help wanted: Lazy multiway zipper with mismached intervals

2005-09-26 Thread ChrisK
Rene de Visser wrote: Hello, I need to zip together multiple lists. The lists are sorted by date, and each entry in the list represents data for a time interval. The time intervals between the lists may be missmatched from each other. Does a single list have only disjoint intervals?

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

2005-09-23 Thread ChrisK
Well...your recursion will fail if (a:r) is matched against the empty set. That will trigger your Exception. So does your code avoid this ? No, it does not. cus 2 [1,2,3,4,5] recurses to cus 1 [2,3,4,5] to cus 0 [3,4,5] to cus (-1) [4,5] to cus (-2) [5] to cus

Re: [Haskell-cafe] Eq Type Class: Overloading (==)

2005-09-16 Thread ChrisK
You would have to preempt the Standard Prelude. For ghc there is a command line switch I have neer used: -fno-implicit-prelude See section 7.3.5 in the GHC user's guide for more. There are some internal caveats: However, the standard Prelude Eq class is still used for the equality test

Re: [Haskell-cafe] How to use STArray?

2005-08-26 Thread ChrisK
Hi, There are also STArray examples on the wiki at http://haskell.org/hawiki/ImperativeHaskell This includes a very high performance use of STUArray example (from Autrijus), and a ST.Lazy example that I wrote that uses STArray. -- Chris ___

Re: [Haskell-cafe] How to use STArray?

2005-08-26 Thread ChrisK
Alistair Bayley wrote: There are also STArray examples on the wiki at http://haskell.org/hawiki/ImperativeHaskell This includes a very high performance use of STUArray example (from Autrijus), and a ST.Lazy example that I wrote that uses STArray. Thanks. I saw these, but couldn't quite

Re: [Haskell-cafe] Re: Coin changing algorithm

2005-07-14 Thread ChrisK
The combinator is really elegant, but I want to ask a question about the arrays that get built. The 3D array index is by (m,n,i) and a single array should be good for all of the results. If I say let {x=change 10 5; y=change 5 10;} then it looks like dp (10,5,8) and dp (5,10,8) get evaluated.

Re: [Haskell-cafe] Coin changing algorithm

2005-07-13 Thread ChrisK
Well, I don't have time to do more than comment, but here are few improvements: Sort the list of integers, highest at the front of the list. (And perhaps remove duplicates with nub) When you pop the first element you can already compute the range of quantity you will need, and can perhaps

Re: [Haskell-cafe] Coin changing algorithm

2005-07-13 Thread ChrisK
Okay, I like Cale's extra guard short circuit so much I must add it to my pseudo-example. Cale's guard: amount `div` maximum coins maxCoins = [] -- optimisation Mine, updated. partition (x:xs) m k | xm = partition xs m k-- x is too big parititon (x:_) m k | x*k m = []

Re: [Haskell-cafe] Coin changing algorithm

2005-07-13 Thread ChrisK
(= x coins)) over and over again. Radu Grigore wrote: On 7/13/05, ChrisK [EMAIL PROTECTED] wrote: Sort the list of integers, highest at the front of the list. (And perhaps remove duplicates with nub) The first time I wrote in the comments that 'partition' takes a decreasing list of integers

Re: [Haskell] Going nuts

2005-04-20 Thread ChrisK
On Apr 20, 2005, at 10:04 PM, Alexandre Weffort Thenorio wrote: As usual a beginner in Haskell. Trying to write a simple program in haskel shown below outputLine keyno key orgFile = do part1 - getLeft keyno orgFile part2 - getRight keyno orgFile total - part1 ++ (strUpper key) ++

[Haskell] Variable arity function (VarArg)

2005-04-20 Thread ChrisK
And while I'm posting to the list, I'll send something I wish I had found earlier. I had wanted to write show several things, and writing show 10 times was not clever. And so I initially created an infix operator to put between everything to do the showing, which was not much better. But

Re: [Haskell] Control.Monad.Writer as Python generator

2005-04-15 Thread ChrisK
compiling with optimisations turned on, there is no such problem with the continuation-based version, memory usage appears constant. - Cale On 4/14/05, ChrisK [EMAIL PROTECTED] wrote: Thanks for the Cont example, David. But... The MonadCont is clever and it works ... but then fails -- ghci does

Re: [Haskell] Control.Monad.Writer as Python generator

2005-04-15 Thread ChrisK
You are correct. Moand.Cont yield even runs without -O optimizing, just slower ... Anyone have an idea why ghci can't garbage collect it? Is this an actual bug or an innate quirk of the REPL ? GHCi does not compile with optimizations, without -O the strictness analyzer isn't run. The optimizer

Re: [Haskell] Control.Monad.Writer as Python generator

2005-04-14 Thread ChrisK
(1.22 secs, 0 bytes) *Main length $ take (10^8) zerosInf 1 (10.05 secs, 0 bytes) *Main length $ take (10^9) zerosInf 10 (109.83 secs, 6 bytes) -- Chris On Apr 14, 2005, at 1:05 AM, David Menendez wrote: ChrisK writes: I was thinking to myself: What in Haskell would give me a yield

[Haskell] Control.Monad.Writer as Python generator

2005-04-12 Thread ChrisK
Hi, I was thinking to myself: What in Haskell would give me a yield command like a Python generator? And the answer was tell in Control.Monad.Writer -- and I wrote some simple examples (see below). Most Python code using yield would be translated to something much more idiomatic in Haskell

<    1   2