[Haskell-cafe] Hiding side effects in a data structure

2007-10-19 Thread C Rodrigues
While thinking about how to generate unique integer IDs on demand without using a state variable, I came up with an interesting design pattern. It's a way of doing side-effecting computation outside IO. Referential transparency is preserved by making the side effects spatial rather than

[Haskell-cafe] Type synonym application

2007-03-18 Thread C Rodrigues
Type synonyms aren't applied as I would expect during kind checking. What's going on here? type WithList a b = b [a] type FooPair a b = (b, a - b) -- error: `WithList' is applied to too many type arguments ints1 :: WithList Int FooPair [Int] ints1 = ([1], id) -- error: `FooPair' is not

[Haskell-cafe] RE: MPTCs and rigid variables

2007-03-03 Thread C Rodrigues
{-# OPTIONS_GHC -fglasgow-exts #-} class Foo a b | a - b where foo :: Foo b c = a - Maybe c instance Foo String () where foo _ = Nothing instance Foo Int String where foo 4 = Just (); foo _ = Nothing There appears to be a type-safe way to use unsafeCoerce# for this: import

[Haskell-cafe] Space leaks in large mutable data structures

2007-02-05 Thread C Rodrigues
I'd like to hear what tips and techniques you guys have for avoiding space leaks. I understand the basic techniques to force evaluation of closures. What I'd like to know is how you avoid space leaks in large, long-lived, mutable data structures. These kind of data are particularly sensitive

[Haskell-cafe] (no subject)

2007-02-04 Thread C Rodrigues
_ FREE online classifieds from Windows Live Expo – buy and sell with people you know http://clk.atdmt.com/MSN/go/msnnkwex001001msn/direct/01/?href=http://expo.live.com?s_cid=Hotmail_tagline_12/06

[Haskell-cafe] Laziness through boxing

2007-01-16 Thread C Rodrigues
I had a problem with strictness in the Parsec library, and I'd like to know if there's a good way to solve it. The following illustrates the problem. This raises an error when run: main = parseTest (return undefined return 0) Whereas this does not: main = parseTest (return (Just

[Haskell-cafe] IA64 porting: spill code in the mangler

2006-08-09 Thread C Rodrigues
Hi folks, I've been trying to compile a new ia64 port. I've cross-compiled an unregisterised compiler that generated working binaries the first time it was built, which was a pleasant experience. But I ran into issues with the registerised build. The mangler is choking on floating-point

[Haskell-cafe] Template haskell and scoping

2006-06-21 Thread C Rodrigues
The (..) in the splice is out of scope according to GHC. If I use [||] then it works, but for my purposes it's easier to use the constructors. How should I refer to that variable? import Data.Bits import Language.Haskell.TH main = print $ $(return $ VarE $ mkName ..) 7 (14 :: Int)

[Haskell-cafe] Computing lazy and strict list operations at the same time

2006-06-19 Thread C Rodrigues
Here's a puzzle I haven't been able to solve. Is it possible to write the initlast function? There are functions init and last that take constant stack space and traverse the list at most once. You can think of traversing the list as deconstructing all the (:) [] constructors in list.

Re: [Haskell-cafe] Computing lazy and strict list operations atthe same time

2006-06-19 Thread C Rodrigues
Ah, thanks for the replies. I like the approach that uses lazy tuples of intermediate values because it has a recognizable similarity to the original two functions. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Rank 2 polymorphism in pattern matching?

2006-04-08 Thread C Rodrigues
This counterintuitive typechecking result came up when I wrote a wrapper around runST. Is there some limitation of HM with respect to type checking pattern matching? data X a b = X (a - a) run :: forall a. (forall b. X a b) - a - a -- This definition doesn't pass the typechecker run (X f) = f