Re: [Haskell-cafe] About the Monad Transformers

2009-06-17 Thread Neil Brown
.shawn wrote: On page 141 of Yet another Haskell Tutorial (9.7 Monad Transformers) mapTreeM action (Leaf a) = do lift (putStrLn (Leaf ++ show a)) b - action a return (Leaf b) mapTreeM :: (MonadTrans t, Monad (t IO), Show a) = (a - t IO a1) - Tree a - t IO (Tree a1) Why does the type

Re: [Haskell-cafe] Software Transactional Memory and LWN

2009-06-11 Thread Neil Brown
Ketil Malde wrote: Hi, Browsing LWN, I ran across this comment: http://lwn.net/Articles/336039/ The author makes a bunch of unsubstantiated claims about STM, namely that all implementations use locking under the hood, and that STM can live- and deadlock. I've seen a lot of similar sentiments

Re: [Haskell-cafe] Software Transactional Memory and LWN

2009-06-11 Thread Neil Brown
Ketil Malde wrote: So the naïve attempt at doing this would be something like: thread = do -- grab lock 1 t - readTVar lock when t retry writeTVar lock True -- grab lock 2 t2 - readTVar lock2 when t2 retry writeTVar writeTVar

Re: [Haskell-cafe] Weird and entirely random problem...

2009-06-10 Thread Neil Brown
Hi, I'm presuming the problem with your result is that the span... String is in the times map, and not in the store map (you weren't clear on the exact problem). I took a look at the code, here's my thoughts on why this occurs. If you start by putting something in the cache with key foo,

Re: [Haskell-cafe] How to improve below code?

2009-06-09 Thread Neil Brown
Andy Stewart wrote: So have a better solution to avoid write above ugly code How about: data Page a = Page {pageName :: IORef String ,pageId:: Int ,pageBuffer:: a ,pageBox :: VBox } class PageBuffer a where pageBufferClone :: a -

Re: [Haskell-cafe] FGL Question

2009-05-24 Thread Neil Brown
Hans van Thiel wrote: Hello, I want to get the top or the bottom elements of a graph, but the following code appears to give the wrong answer in most cases, and the right answer in a few cases. Any ideas? -- get the most general or the least general elements graphMLGen :: Bool - Gr [Rule]

Re: [Haskell-cafe] Introducing Instances in GHC point releases

2009-05-22 Thread Neil Brown
Duncan Coutts wrote: What we're currently missing is a PVP checker: a tool to compare APIs of package versions and check that it is following the PVP. Ideally, we will have packages opt-in to follow the PVP for those packages that do opt-in we have the PVP enforced on hackage using the checker

Re: [Haskell-cafe] tips on using monads

2009-05-18 Thread Neil Brown
Michael P Mossey wrote: I've got one of those algorithms which threatens to march off the right edge (in the words of Goerzen et al). I need something like a State or Maybe monad, but this is inside the IO monad. So I presume I need StateT or MaybeT. However, I'm still (slowly) learning about

Re: [Haskell-cafe] Removing mtl from the Haskell Platform

2009-05-13 Thread Neil Brown
Sittampalam, Ganesh wrote: We've discussed replacing it with transformers+monads-fd+an mtl compatiblity layer on librar...@. Ross and I plan to propose doing this for the second release of the platform - it's not fair to disrupt the first release at this stage. transformers+monads-fd is quite a

Re: [Haskell-cafe] Decoupling OpenAL/ALUT packages from OpenGL

2009-05-12 Thread Neil Brown
Sven Panne wrote: Regarding Functor/Applicative: The obvious instances for e.g. a 2-dimensional vertex are: data Vertex2 a = Vertex2 a a instance Functor Vertex2 where fmap f (Vertex2 x y) = Vertex2 (f x) (f y) instance Applicative Vertex2 where pure a = Vertex2 a a

Re: [Haskell-cafe] Simulation and GHC Thread Scheduling

2009-05-09 Thread Neil Brown
properly, the slight variation is actually a good test). What I would like to know is are there any plans for GHC to incorporate user-definable scheduler? What exactly is it that you want from a user-definable scheduler? Do you want co-operative scheduling in your program, or do you want

Re: [Haskell-cafe] Just 3 = (1+)?

2009-05-09 Thread Neil Brown
Hi, (1+) :: Num a = a - a For the bind operator, you need something of type a - Maybe b on the RHS, not simply a - a. You want one of these instead: fmap (1+) (Just 3) liftM (1+) (Just 3) Alternatively, you may find it useful to define something like: (*) = flip liftM so that you can

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Neil Brown
Neil Mitchell wrote: I didn't at first, then I remembered: 1 + True = fromInteger 1 + True And if we have Num for Bool, it type checks. Does that also mean that you could write: if 3 - 4 then ... else ... (= if (fromInteger 3 :: Bool) - (fromInteger 4 :: Bool) then ... else ...) or

Re: [Haskell-cafe] Trying to contact authors of Real World Haskell?

2009-05-07 Thread Neil Brown
Itsme (Sophie) wrote: I could not find any contact info for Brian O'Sullivan, Don Stewart, or John Goerzen on their book site. Any pointers to how I might locate any of them much appreciated. Two of the three have posted to this list in the last 24 hours, so you can take their email addresses

Re: [Haskell-cafe] Parsec - Custom Fail

2009-05-05 Thread Neil Brown
Hi, When we needed to do something similar with Parsec, we chose to pack the relevant source position into the error string (you can just use Show/Read, plus a special sequence of characters to indicate where the position ends and the real error starts). We then unpack it outside runParser

Re: [Haskell-cafe] instance Monad (Except err)

2009-05-04 Thread Neil Brown
Martijn van Steenbergen wrote: Hello, Mr. McBride and mr. Paterson define in their Applicative paper: data Except e a = OK a | Failed e instance Monoid e = Applicative (Except e) where ... Sometimes I'd still like to use = on Excepts but this feels wrong somehow, because it doesn't use

Re: [Haskell-cafe] Question about implementing an off-side rule in Parsec 2

2009-04-28 Thread Neil Brown
Bas van Gijzel wrote: Hello everyone, I'm doing a bachelor project focused on comparing parsers. One of the parser libraries I'm using is Parsec (2) and I'm going to implement a very small subset of haskell with it, with as most important feature the off-side rule (indentation based parsing)

[Haskell-cafe] Type constraints and classes

2009-04-26 Thread Neil Brown
Hi, I have a Haskell problem that keeps cropping up and I wondered if there was any solution/work-around/dirty-hack that could help. I keep wanting to define class instances for things like Functor or Monad, but with restrictions on the inner type. I'll explain with an example, because I

<    1   2