* Serge D. Mechveliani <mech...@botik.ru> [2012-10-17 19:02:37+0400]
> People,
> consider the following contrived program for division with remainder:
> 
> ----------------------------------------------------------------
> qRem :: Int -> Int -> (Int, Int)
> qRem m n = if m < 0 || n <= 0 then  error "\nwrong arguments in qRem.\n"
>            else                     qRem' 0 m
>            where
>            qRem' q r = if r < n then (q, r)  else qRem' (succ q) (r - n)

You need to force evaluation of 'q' here, otherwise it becomes a growing
chain of 'succ' applications.

E.g.

    qRem' q r = if r < n then (q, r)  else (qRem' $! succ q) (r - n)

Roman

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to