Mercurial > hg > Members > atton > delta_monad
changeset 44:6e270dfe2bb9
Define pretty-print for Delta
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 09 Nov 2014 11:39:07 +0900 |
parents | 90b171e3a73e |
children | 0c2d758406b1 |
files | delta.hs |
diffstat | 1 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/delta.hs Sat Nov 01 15:19:04 2014 +0900 +++ b/delta.hs Sun Nov 09 11:39:07 2014 +0900 @@ -1,7 +1,15 @@ import Control.Applicative import Data.Numbers.Primes -- $ cabal install primes -data Delta a = Delta [String] a [String] a deriving (Show) +data Delta a = Delta [String] a [String] a + +instance (Show a) => Show (Delta a) where + show (Delta lx x ly y) = values ++ logs + where + values = "Delta {" ++ (show x) ++ "|" ++ (show y) ++ "}\n" + logs = concat . reverse $ zipWith (formatter x y) lx ly + formatter x y = (\x y -> " {" ++ x ++ (separator x y) ++ y ++ "}\n") + separator x y = if (max (length x) (length y)) > 50 then "|\n " else "|" value :: (Delta a) -> a value (Delta _ x _ _) = x