[Haskell-cafe] Why this exception occurs ?
Albert Y. C. Lai
trebla at vex.net
Fri May 25 14:55:04 EDT 2007
Donald Bruce Stewart wrote:
> instance Num String anyone? Mwhaha
>
addString xs ys = add 0 xs ys
where
m = fromEnum (maxBound :: Char) + 1
alu c x y =
let s = c + fromEnum x + fromEnum y
in if s >= m then (1, s-m) else (0, s)
add c (x:xs) (y:ys) = case alu c x y of (c', s') -> toEnum s' : add c' xs ys
add c [] (y:ys) = case alu c 0 y of (0, s') -> toEnum s' : ys
(1, s') -> toEnum s' : add 1 [] ys
add c xs@(_:_) [] = add c [] xs
add c [] [] = if c==0 then [] else [toEnum c]
More information about the Haskell-Cafe
mailing list