On 5/30/07, Chas Owens <[EMAIL PROTECTED]> wrote:
I have poked around a bit in the code and can't find a good way to die. I am currently usingperlReplicate n a = if n == 1/0 then error "Infinite replications would exhaust memory" else if n < 0 then genericReplicate 0 a else genericReplicate (truncate n) a But that gives the following message pugs> "a" x Inf Internal error while running expression: Infinite replications would exhaust memory But this isn't an internal error; it is a user error, so I want a message like pugs> "a" x Inf *** Infinite replications would exhaust memory at <interactive> line 1, column 1-9
I'm not near a compiling box right now, but the fix would be to lift perlReplicate into a monad (Eval, or just leave a Monad m context); then fail when the need arises. Somthing like (untested): perlReplicate :: VInt -> a -> Eval [a] perlReplicate (1/0) _ = fail "Infinite replications would exhaust memory" perlReplicate i a = return $ flip genericReplicate a $ if i < 0 then 0 else a You'll need to tweak the calling site to be monadic too. -- Gaal Yahas <[EMAIL PROTECTED]> http://gaal.livejournal.com/
