[Haskell-cafe] Record updates

2009-03-29 Thread Andrew Coppin
Haskell's record syntax is quite nice, for a number of reasons. However, suppose I have some record: data Foobar = Foobar {foo1, foo2, foo3...} Now suppose that foo3 :: [Int], and I want to prepend 5 to it. I end up having to write something like let v1 = v0 {foo3 = 5 : (foo3 v0)} If the

Re: [Haskell-cafe] Record updates

2009-03-29 Thread Ryan Ingram
Take a look at Data.Accessor on hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor-template -- ryan On Sun, Mar 29, 2009 at 2:13 AM, Andrew Coppin andrewcop...@btinternet.com wrote:

[Haskell-cafe] ANN: cmonad 0.1.1

2009-03-29 Thread Lennart Augustsson
I've uploaded my CMonad package to Hackage. It allows you to write Haskell code in a C style. Unfortunately, GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed. Example: Computing some Fibonacci numbers: fib = do { a -

Re: [Haskell-cafe] Re: Exception handling in numeric computations

2009-03-29 Thread Nicolas Pouillard
Excerpts from Henning Thielemann's message of Sat Mar 28 21:49:33 +0100 2009: On Sat, 28 Mar 2009, John Lato wrote: From: Donn Cave d...@avvanta.com I have never felt that I really understood that one. Honestly, me neither, until recently. I'm only barely starting to understand

Re: [Haskell-cafe] Record updates

2009-03-29 Thread Andrew Coppin
Ryan Ingram wrote: Take a look at Data.Accessor on hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor-template So, to summarise, it provides a datatype to encapsulate a pair of get/set

Re: [Haskell-cafe] Re: Exception handling in numeric computations

2009-03-29 Thread John Lato
On Sat, Mar 28, 2009 at 9:49 PM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Sat, 28 Mar 2009, John Lato wrote: From: Donn Cave d...@avvanta.com I have never felt that I really understood that one. Honestly, me neither, until recently.  I'm only barely starting to

Re: [Haskell-cafe] Record updates

2009-03-29 Thread Malcolm Wallace
Now suppose that foo3 :: [Int], and I want to prepend 5 to it. I end up having to write something like let v1 = v0 {foo3 = 5 : (foo3 v0)} There used to be a feature in pre-Haskell'98 called named field puns, which allows to use a shorter form of field access. Your example would come out

Re: [Haskell-cafe] Record updates

2009-03-29 Thread Hugo Pacheco
There is a page for extensible records in the wiki: http://www.haskell.org/haskellwiki/Extensible_record Haskell's records system has many insuficiencies. Some libraries (see grapefruit or HaskellDB) encode records as classes, but although some proposals Haskell still lacks a good implementation

Re: [Haskell-cafe] ANN: cmonad 0.1.1

2009-03-29 Thread Jason Dusek
2009/03/29 Lennart Augustsson lenn...@augustsson.net: ...GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed. Is this surprising to anyone? -- Jason Dusek ___ Haskell-Cafe mailing list

[Haskell-cafe] Problem using #define in .hsc files

2009-03-29 Thread Johan Tibell
Hi, I'm trying to have hsc2hs interpret this snippet that picks a calling convention to use for FFI imports: #if !defined(CALLCONV) #ifdef WITH_WINSOCK #define CALLCONV stdcall #else #define CALLCONV ccall #endif #endif foreign import CALLCONV unsafe send c_send :: CInt - Ptr a - CSize -

Re: [Haskell-cafe] ANN: cmonad 0.1.1

2009-03-29 Thread Marcin Kosiba
On Sunday 29 March 2009, Lennart Augustsson wrote: I've uploaded my CMonad package to Hackage. It allows you to write Haskell code in a C style. Now I've heard that Haskell makes a fine (if not the finest) imperative language, but isn't this taking that thought a bit too far ;)

Re: [Haskell-cafe] Re: Exception handling in numeric computations

2009-03-29 Thread Jonathan Cast
On Sat, 2009-03-28 at 12:51 +0300, Gregory Petrosyan wrote: On Sat, Mar 28, 2009 at 10:53 AM, Ketil Malde ke...@malde.org wrote: So the difference between an exception or an error type is mainly what you intend to do about it. There's no point in wrapping divisions in Maybe unless you

Re: [Haskell-cafe] ANN: cmonad 0.1.1

2009-03-29 Thread Lennart Augustsson
Well, yes and no. GHC actually does a decent job when given very imperative code with references and mutable arrays. Now the type I use to wrap the references to get type safe l-values and r-values makes it tricker, and ghc lacks a crucial optimization for specialization of constructor returns.

Re: [Haskell-cafe] ANN: cmonad 0.1.1

2009-03-29 Thread Lennart Augustsson
If my primary concern is speed I'll write in C. 2009/3/29 Marcin Kosiba marcin.kos...@gmail.com: On Sunday 29 March 2009, Lennart Augustsson wrote: I've uploaded my CMonad package to Hackage.  It allows you to write Haskell code in a C style. Now I've heard that Haskell makes a fine (if not

[Haskell-cafe] Rational and % operator remix

2009-03-29 Thread michael rice
Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, but you shouldn't get into trouble if you use 98%67 as input (output should be

[Haskell-cafe] Re: Exception handling in numeric computations

2009-03-29 Thread Achim Schneider
Henning Thielemann schlepp...@henning-thielemann.de wrote: Actually, I really object to have exception handling built into IO monad. I couldn't agree more. If I want to write non-recovering code, I can always just say (Right foo) - readLine , and hope that the RTS is smart enough to print

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread Ross Mellgren
I think you probably mean ==, the comparison operator (function), not = (assignment in let-forms or where-forms) -Ross On Mar 29, 2009, at 1:40 PM, michael rice wrote: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first

[Haskell-cafe] Template Haskell messes up scoping?

2009-03-29 Thread Stephan Friedrichs
Hi, when I tried to reorganize some code to use the data-accessor and data-accessor-template packages, i stumbled across a strange effect: When using template haskell some things are out of scope that really shouldn't be. Let me give an example: == T.hs == {-# LANGUAGE

Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)

2009-03-29 Thread Peter Verswyvelen
Mmm, my email was indeed very unclear about my question. A very simple example: suppose a development team is working on a program. This program consist of modules A and B. Each module has it's own Darcs repository. Module A requires B. When a new developer wants to get the source code, he does a

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread Lennart Augustsson
You can use floor in a Rational directly, no need to take it apart and divide. There is no need to write (toRational 1), just write 1. Don't write (subtract ai a), write (ai - i). You also have a type error; the ai should no be a Rational, so you need to move to toRational call to the

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread Daniel Fischer
Am Sonntag 29 März 2009 19:40:19 schrieb michael rice: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, Not for rational numbers.

[Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)

2009-03-29 Thread Achim Schneider
Peter Verswyvelen bugf...@gmail.com wrote: To me, any version control system should be able to track dependencies between repositories. Something similar like Cabal's dependency system. So my question is really, how do you solve the dependency tracking between several Darcs repositories?

Re: [Haskell-cafe] Template Haskell messes up scoping?

2009-03-29 Thread Stephan Friedrichs
Hi Martijn, Martijn van Steenbergen wrote: [...] Apart from the specific problematic file you gave, I had some other scoping issues when using TH to generate the accessors. I worked around this by defining my data types in a separate module Types and calling the TH functions in that module

[Haskell-cafe] uvector package appendU: memory leak?

2009-03-29 Thread Manlio Perillo
Hi. As with a previous post, I think I have found a possible memory problem with the uvector package. I have this data structure (for, again, my Netflix Prize project): IntMap (UArr (Word16 :*: Word8)) I was adding elements to the map using something like: v = map singletonU (a :*:

Re: [Haskell-cafe] uvector package appendU: memory leak?

2009-03-29 Thread Don Stewart
manlio_perillo: Hi. As with a previous post, I think I have found a possible memory problem with the uvector package. I have this data structure (for, again, my Netflix Prize project): IntMap (UArr (Word16 :*: Word8)) I was adding elements to the map using something like: v =

Re: [Haskell-cafe] Template Haskell messes up scoping?

2009-03-29 Thread Martijn van Steenbergen
Hi Stephan, Stephan Friedrichs wrote: Hi, when I tried to reorganize some code to use the data-accessor and data-accessor-template packages, i stumbled across a strange effect: When using template haskell some things are out of scope that really shouldn't be. Apart from the specific

Re: [Haskell-cafe] Template Haskell messes up scoping?

2009-03-29 Thread Claus Reinke
It looks like the scope is interrupted just above $( ... ) - but I'd like to know why and find a more beautiful way than just moving all th calls to the bottom of the module file :) Top-level splices can introduce bindings. IIRC, the current TH implementation uses a simple sequencing approach,

Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)

2009-03-29 Thread Ganesh Sittampalam
On Sun, 29 Mar 2009, Peter Verswyvelen wrote: Module A requires B. When a new developer wants to get the source code, he does a darcs get server://program/A, which gives him only the latest version of A. So he manually needs to do darcs get server://program/B (that B is required is usually

Re: [Haskell-cafe] uvector package appendU: memory leak?

2009-03-29 Thread Manlio Perillo
Don Stewart ha scritto: [...] So the question is: why appending an array of only one element to an existing array causes memory problems? It must copy the entire array. Isn't it the same with snocU? And, since the final result is the same, what happens to the temporary memory used for

Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)

2009-03-29 Thread Peter Verswyvelen
On Sun, Mar 29, 2009 at 10:04 PM, Ganesh Sittampalam gan...@earth.liwrote: There's an (unimplemented) proposal by David Roundy for darcs sub-repos that would solve this problem: you have a darcs patch type that means depend on this patch from this other darcs repo which will be checked out in

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread michael rice
Correct, if it can be stated as a Rational then it terminates. I was messing around last night with the first function on a sequence that approximates sqrt(2) cf (take 25 (1: [2,2..])) forgetting that while the sequence is infinite, I only grabbed the first 25 elements. Your replacement code

Re: [Haskell-cafe] uvector package appendU: memory leak?

2009-03-29 Thread Don Stewart
manlio_perillo: Don Stewart ha scritto: [...] So the question is: why appending an array of only one element to an existing array causes memory problems? It must copy the entire array. Isn't it the same with snocU? And, since the final result is the same, what happens to the

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread michael rice
I'm a Lisper, kind of feeling my way around here in Haskell, so please bear with me. I did the things you suggested, but I think the last one may have gotten garbled. Anyway, this is what I ended up with cf2 :: Rational - [Int] cf2 a = let ai = floor a     in   if a ==

Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)

2009-03-29 Thread Xiao-Yong Jin
Peter Verswyvelen bugf...@gmail.com writes: Mmm, my email was indeed very unclear about my question. A very simple example: suppose a development team is working on a program. This program consist of modules A and B. Each module has it's own Darcs repository. Module A requires B. When a

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread Brandon S. Allbery KF8NH
On 2009 Mar 29, at 16:19, michael rice wrote: but I'm still at least one error short of a clean run Main :load cf.hs ERROR cf.hs:7 - Type error in application *** Expression : ai : cf2 (1 / (a - ai)) *** Term : ai *** Type : Ratio Integer *** Does not match : Int Where

Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)

2009-03-29 Thread Brandon S. Allbery KF8NH
On 2009 Mar 29, at 16:26, Xiao-Yong Jin wrote: Peter Verswyvelen bugf...@gmail.com writes: Module A requires B. When a new developer wants to get the source code, he does a darcs get server://program/A, which gives him only the latest version of A. So he manually needs to do darcs get

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread Brandon S. Allbery KF8NH
On 2009 Mar 29, at 16:27, Brandon S. Allbery KF8NH wrote: cf2 a = let ai = floor a rai = toRational ai in if a == rai then [ai] else rai : cf2 (1 / (a - ai)) Nope, went a bit too fast there, ignore me -- brandon s. allbery

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread michael rice
cf2 :: Rational - [Int] cf2 a = let ai = floor a  -- Doesn't this make ai an Int?   -Michael     in   if a == (toRational ai)     then [ai]     else ai : cf2 (1 / (a - ai)) --- On Sun, 3/29/09, Brandon S. Allbery KF8NH allb...@ece.cmu.edu

Re: [Haskell-cafe] uvector package appendU: memory leak?

2009-03-29 Thread Claus Reinke
IntMap (UArr (Word16 :*: Word8)) I was adding elements to the map using something like: v = map singletonU (a :*: b) insertWith appendU k v m However doing this eats a *lot* of memory. Since 'insertWith' doesn't actually do the 'appendU', the appends will also be compressed in

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread Miguel Mitrofanov
cf2 a = let ai = floor a air = toRational ai in ai : if a == air then [] else cf2 (1 / (a - air)) On 30 Mar 2009, at 00:19, michael rice wrote: I'm a Lisper, kind of feeling my way around here in Haskell, so please bear with me. I did the things you suggested, but I

Re: [Haskell-cafe] Rational and % operator remix

2009-03-29 Thread michael rice
Works like a charm. Here's a final copy for those interested. Michael = import Data.Ratio cf2 :: Rational - [Int] cf2 a = let ai = floor a     air = toRational ai     in ai : if a == air then [] else cf2 (1 / (a - air)) --- On Sun, 3/29/09, Miguel Mitrofanov

Re: [Haskell-cafe] uvector package appendU: memory leak?

2009-03-29 Thread Manlio Perillo
Manlio Perillo ha scritto: Hi. As with a previous post, I think I have found a possible memory problem with the uvector package. I have this data structure (for, again, my Netflix Prize project): IntMap (UArr (Word16 :*: Word8)) [...] Today I have rewritten my program to use `alter`

[Haskell-cafe] Is Text.XHtml.Table usable?

2009-03-29 Thread Thomas Hartman
I was playing with Text.XHtml.Table but couldn't use it to output tables. ( cell . toHtml $ a ) `beside` (cell . toHtml $ b ) tr a b /tr already seems wrong -- should be two cells, right? And the result doesn't get embedded in a table tag? Is there something I'm missing? Working code

Re: [Haskell-cafe] uvector package appendU: memory leak?

2009-03-29 Thread Manlio Perillo
Claus Reinke ha scritto: IntMap (UArr (Word16 :*: Word8)) I was adding elements to the map using something like: v = map singletonU (a :*: b) insertWith appendU k v m However doing this eats a *lot* of memory. Since 'insertWith' doesn't actually do the 'appendU', the appends

Re: [Haskell-cafe] uvector package appendU: memory leak?

2009-03-29 Thread Manlio Perillo
Don Stewart ha scritto: manlio_perillo: Don Stewart ha scritto: [...] So the question is: why appending an array of only one element to an existing array causes memory problems? It must copy the entire array. Isn't it the same with snocU? And, since the final result is the same, what

Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)

2009-03-29 Thread Peter Verswyvelen
On Sun, Mar 29, 2009 at 10:26 PM, Xiao-Yong Jin xj2...@columbia.edu wrote: Now assume you don't have 2 modules but dozens... I can't imagine such kind of situation, unless you are really working on a very big project. Usually, if your project depends on other projects, mostly it should

Re: [Haskell-cafe] uvector package appendU: memory leak?

2009-03-29 Thread Claus Reinke
But Claus was right, appendU is lazy; this seems to be the cause of the problem. appendU is strict, insertWith just doesn't force it (follow the source link in the haddocks to see why). However now I don't really understand why the two implementations differs in lazyness. Or, to ask a

[Haskell-cafe] type-level programming support library

2009-03-29 Thread spoon
I've been doing some basic work on a support library for type level programming ( see http://hackage.haskell.org/trac/summer-of-code/ticket/1541 ). I know there have been similar attempts using fundeps ( Edward Kmett showed me some of his work, but I've lost the address... ) but this approach

Re: [Haskell-cafe] Is Text.XHtml.Table usable?

2009-03-29 Thread Anton van Straaten
Thomas Hartman wrote: I was playing with Text.XHtml.Table but couldn't use it to output tables. ( cell . toHtml $ a ) `beside` (cell . toHtml $ b ) tr a b /tr already seems wrong -- should be two cells, right? And the result doesn't get embedded in a table tag? 'cell' is not a TD

Re: [Haskell] Re: [Haskell-cafe] ANN: cmonad 0.1.1

2009-03-29 Thread Don Stewart
Nested constructed product returns? Or constructed sums? lennart: Well, yes and no. GHC actually does a decent job when given very imperative code with references and mutable arrays. Now the type I use to wrap the references to get type safe l-values and r-values makes it tricker, and ghc

[Haskell-cafe] Re: ANNOUNCE: wxAsteroids 1.0

2009-03-29 Thread Benjamin L . Russell
On Fri, 27 Mar 2009 15:34:06 +0100, Henk-Jan van Tuyl hjgt...@chello.nl wrote: On Thu, 26 Mar 2009 20:41:57 +0100, Henk-Jan van Tuyl hjgt...@chello.nl wrote: Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is a game demonstrating the wxHaskell GUI. More about