main :: [sys_message] main = [Stdout (lay (map lincomb tests))] where tests = [[1,2,3], [0,1,2,3], [1,0,3,4], [1,2,0], [0,0,0], [0], [1,1,1], [-1,-1,-1], [-1,-2,0,-3], [-1]] lincomb :: [num]->[char] lincomb xs = "0", if result = "" = result, otherwise where result = foldl term "" (zip2 [1..] xs) term r (i,0) = r term "" (i,-1) = "-" ++ te i term "" (i,1) = te i term "" (i,n) = "-" ++ show (abs n) ++ "*" ++ te i, if n<0 = show n ++ "*" ++ te i, otherwise term r (i,-1) = r ++ " - " ++ te i term r (i,1) = r ++ " + " ++ te i term r (i,n) = r ++ sgn ++ show (abs n) ++ "*" ++ te i where sgn = " - ", if n<0 = " + ", otherwise te n = "e(" ++ shownum n ++ ")"