Mercurial > hg > Members > atton > delta_monad
comparison delta.hs @ 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 |
comparison
equal
deleted
inserted
replaced
43:90b171e3a73e | 44:6e270dfe2bb9 |
---|---|
1 import Control.Applicative | 1 import Control.Applicative |
2 import Data.Numbers.Primes -- $ cabal install primes | 2 import Data.Numbers.Primes -- $ cabal install primes |
3 | 3 |
4 data Delta a = Delta [String] a [String] a deriving (Show) | 4 data Delta a = Delta [String] a [String] a |
5 | |
6 instance (Show a) => Show (Delta a) where | |
7 show (Delta lx x ly y) = values ++ logs | |
8 where | |
9 values = "Delta {" ++ (show x) ++ "|" ++ (show y) ++ "}\n" | |
10 logs = concat . reverse $ zipWith (formatter x y) lx ly | |
11 formatter x y = (\x y -> " {" ++ x ++ (separator x y) ++ y ++ "}\n") | |
12 separator x y = if (max (length x) (length y)) > 50 then "|\n " else "|" | |
5 | 13 |
6 value :: (Delta a) -> a | 14 value :: (Delta a) -> a |
7 value (Delta _ x _ _) = x | 15 value (Delta _ x _ _) = x |
8 | 16 |
9 similar :: (Delta a) -> a | 17 similar :: (Delta a) -> a |