tree-diff-0.0.1: Diffing of (expression) trees.

Safe HaskellNone
LanguageHaskell2010

Data.TreeDiff.Class

Contents

Description

A ToExpr class.

Synopsis

Documentation

ediff :: ToExpr a => a -> a -> Edit EditExpr Source #

Difference between two ToExpr values.

>>> let x = (1, Just 2) :: (Int, Maybe Int)
>>> let y = (1, Nothing)
>>> prettyEditExpr (ediff x y)
_×_ 1 -(Just 2) +Nothing
>>> data Foo = Foo { fooInt :: Either Char Int, fooBool :: [Maybe Bool], fooString :: String } deriving (Eq, Generic)
>>> instance ToExpr Foo
>>> prettyEditExpr $ ediff (Foo (Right 2) [Just True] "fo") (Foo (Right 3) [Just True] "fo")
Foo {fooBool = [Just True], fooInt = Right -2 +3, fooString = "fo"}
>>> prettyEditExpr $ ediff (Foo (Right 42) [Just True, Just False] "old") (Foo (Right 42) [Nothing, Just False, Just True] "new")
Foo
  {fooBool = [-Just True, +Nothing, Just False, +Just True],
   fooInt = Right 42,
   fooString = -"old" +"new"}

ediff' :: (ToExpr a, ToExpr b) => a -> b -> Edit EditExpr Source #

Compare different types.

Note: Use with care as you can end up comparing apples with oranges.

>>> prettyEditExpr $ ediff' ["foo", "bar"] [Just "foo", Nothing]
[-"foo", +Just "foo", -"bar", +Nothing]

class ToExpr a where Source #

toExpr converts a Haskell value into untyped Haskell-like syntax tree, Expr.

>>> toExpr ((1, Just 2) :: (Int, Maybe Int))
App "_\215_" [App "1" [],App "Just" [App "2" []]]

Methods

toExpr :: a -> Expr Source #

toExpr :: (Generic a, All2 ToExpr (GCode a), GFrom a, GDatatypeInfo a) => a -> Expr Source #

listToExpr :: [a] -> Expr Source #

Instances

ToExpr Bool Source # 
ToExpr Char Source #
>>> prettyExpr $ toExpr 'a'
'a'
>>> prettyExpr $ toExpr "Hello world"
"Hello world"
>>> prettyExpr $ toExpr "Hello\nworld"
concat ["Hello\n", "world"]
>>> traverse_ (print . prettyExpr . toExpr) ["", "\n", "foo", "foo\n", "foo\nbar", "foo\nbar\n"]
""
"\n"
"foo"
"foo\n"
concat ["foo\n", "bar"]
concat ["foo\n", "bar\n"]
ToExpr Double Source # 
ToExpr Float Source # 
ToExpr Int Source # 
ToExpr Int8 Source # 
ToExpr Int16 Source # 
ToExpr Int32 Source # 
ToExpr Int64 Source # 
ToExpr Integer Source # 
ToExpr Natural Source # 
ToExpr Ordering Source # 
ToExpr Word Source # 
ToExpr Word8 Source # 
ToExpr Word16 Source # 
ToExpr Word32 Source # 
ToExpr Word64 Source # 
ToExpr () Source # 

Methods

toExpr :: () -> Expr Source #

listToExpr :: [()] -> Expr Source #

ToExpr ByteString Source #
>>> traverse_ (print . prettyExpr . toExpr . BS8.pack) ["", "\n", "foo", "foo\n", "foo\nbar", "foo\nbar\n"]
""
"\n"
"foo"
"foo\n"
BS.concat ["foo\n", "bar"]
BS.concat ["foo\n", "bar\n"]
ToExpr ByteString Source #
>>> traverse_ (print . prettyExpr . toExpr . LBS8.pack) ["", "\n", "foo", "foo\n", "foo\nbar", "foo\nbar\n"]
""
"\n"
"foo"
"foo\n"
LBS.concat ["foo\n", "bar"]
LBS.concat ["foo\n", "bar\n"]
ToExpr Scientific Source #
>>> prettyExpr $ toExpr (123.456 :: Scientific)
scientific 123456 `-3`
ToExpr Text Source #
>>> traverse_ (print . prettyExpr . toExpr . T.pack) ["", "\n", "foo", "foo\n", "foo\nbar", "foo\nbar\n"]
""
"\n"
"foo"
"foo\n"
T.concat ["foo\n", "bar"]
T.concat ["foo\n", "bar\n"]
ToExpr UTCTime Source # 
ToExpr Value Source # 
ToExpr Text Source #
>>> traverse_ (print . prettyExpr . toExpr . LT.pack) ["", "\n", "foo", "foo\n", "foo\nbar", "foo\nbar\n"]
""
"\n"
"foo"
"foo\n"
LT.concat ["foo\n", "bar"]
LT.concat ["foo\n", "bar\n"]
ToExpr Void Source # 
ToExpr IntSet Source # 
ToExpr Day Source #
>>> prettyExpr $ toExpr $ ModifiedJulianDay 58014
Day "2017-09-18"
ToExpr UUID Source #
>>> prettyExpr $ toExpr UUID.nil
UUID "00000000-0000-0000-0000-000000000000"
ToExpr Expr Source # 
ToExpr a => ToExpr [a] Source # 

Methods

toExpr :: [a] -> Expr Source #

listToExpr :: [[a]] -> Expr Source #

ToExpr a => ToExpr (Maybe a) Source # 

Methods

toExpr :: Maybe a -> Expr Source #

listToExpr :: [Maybe a] -> Expr Source #

(ToExpr a, Integral a) => ToExpr (Ratio a) Source #
>>> prettyExpr $ toExpr (3 % 12 :: Rational)
_%_ 1 4

Methods

toExpr :: Ratio a -> Expr Source #

listToExpr :: [Ratio a] -> Expr Source #

HasResolution a => ToExpr (Fixed a) Source # 

Methods

toExpr :: Fixed a -> Expr Source #

listToExpr :: [Fixed a] -> Expr Source #

ToExpr a => ToExpr (Min a) Source # 

Methods

toExpr :: Min a -> Expr Source #

listToExpr :: [Min a] -> Expr Source #

ToExpr a => ToExpr (Max a) Source # 

Methods

toExpr :: Max a -> Expr Source #

listToExpr :: [Max a] -> Expr Source #

ToExpr a => ToExpr (First a) Source # 

Methods

toExpr :: First a -> Expr Source #

listToExpr :: [First a] -> Expr Source #

ToExpr a => ToExpr (Last a) Source # 

Methods

toExpr :: Last a -> Expr Source #

listToExpr :: [Last a] -> Expr Source #

ToExpr a => ToExpr (Option a) Source # 
ToExpr a => ToExpr (NonEmpty a) Source # 
ToExpr a => ToExpr (ZipList a) Source # 
ToExpr a => ToExpr (Identity a) Source #
>>> prettyExpr $ toExpr $ Identity 'a'
Identity 'a'
ToExpr a => ToExpr (Dual a) Source # 

Methods

toExpr :: Dual a -> Expr Source #

listToExpr :: [Dual a] -> Expr Source #

ToExpr a => ToExpr (Sum a) Source # 

Methods

toExpr :: Sum a -> Expr Source #

listToExpr :: [Sum a] -> Expr Source #

ToExpr a => ToExpr (Product a) Source # 
ToExpr a => ToExpr (First a) Source # 

Methods

toExpr :: First a -> Expr Source #

listToExpr :: [First a] -> Expr Source #

ToExpr a => ToExpr (Last a) Source # 

Methods

toExpr :: Last a -> Expr Source #

listToExpr :: [Last a] -> Expr Source #

ToExpr v => ToExpr (IntMap v) Source # 
ToExpr a => ToExpr (Tree a) Source # 

Methods

toExpr :: Tree a -> Expr Source #

listToExpr :: [Tree a] -> Expr Source #

ToExpr v => ToExpr (Seq v) Source # 

Methods

toExpr :: Seq v -> Expr Source #

listToExpr :: [Seq v] -> Expr Source #

ToExpr k => ToExpr (Set k) Source # 

Methods

toExpr :: Set k -> Expr Source #

listToExpr :: [Set k] -> Expr Source #

ToExpr a => ToExpr (Hashed a) Source # 
ToExpr k => ToExpr (HashSet k) Source # 
(ToExpr a, Unbox a) => ToExpr (Vector a) Source # 
(ToExpr a, Storable a) => ToExpr (Vector a) Source # 
(ToExpr a, Prim a) => ToExpr (Vector a) Source # 
ToExpr a => ToExpr (Vector a) Source # 
(ToExpr a, ToExpr b) => ToExpr (Either a b) Source # 

Methods

toExpr :: Either a b -> Expr Source #

listToExpr :: [Either a b] -> Expr Source #

(ToExpr a, ToExpr b) => ToExpr (a, b) Source # 

Methods

toExpr :: (a, b) -> Expr Source #

listToExpr :: [(a, b)] -> Expr Source #

(ToExpr k, ToExpr v) => ToExpr (HashMap k v) Source # 

Methods

toExpr :: HashMap k v -> Expr Source #

listToExpr :: [HashMap k v] -> Expr Source #

(ToExpr k, ToExpr v) => ToExpr (Map k v) Source # 

Methods

toExpr :: Map k v -> Expr Source #

listToExpr :: [Map k v] -> Expr Source #

ToExpr (Proxy * a) Source # 

Methods

toExpr :: Proxy * a -> Expr Source #

listToExpr :: [Proxy * a] -> Expr Source #

(ToExpr a, ToExpr b, ToExpr c) => ToExpr (a, b, c) Source # 

Methods

toExpr :: (a, b, c) -> Expr Source #

listToExpr :: [(a, b, c)] -> Expr Source #

ToExpr a => ToExpr (Const * a b) Source # 

Methods

toExpr :: Const * a b -> Expr Source #

listToExpr :: [Const * a b] -> Expr Source #

ToExpr a => ToExpr (Tagged * t a) Source # 

Methods

toExpr :: Tagged * t a -> Expr Source #

listToExpr :: [Tagged * t a] -> Expr Source #

(ToExpr a, ToExpr b, ToExpr c, ToExpr d) => ToExpr (a, b, c, d) Source # 

Methods

toExpr :: (a, b, c, d) -> Expr Source #

listToExpr :: [(a, b, c, d)] -> Expr Source #

(ToExpr a, ToExpr b, ToExpr c, ToExpr d, ToExpr e) => ToExpr (a, b, c, d, e) Source # 

Methods

toExpr :: (a, b, c, d, e) -> Expr Source #

listToExpr :: [(a, b, c, d, e)] -> Expr Source #

defaultExprViaShow :: Show a => a -> Expr Source #

An alternative implementation for literal types. We use show representation of them.

SOP

sopToExpr :: All2 ToExpr xss => DatatypeInfo xss -> SOP I xss -> Expr Source #

>>> prettyExpr $ sopToExpr (gdatatypeInfo (Proxy :: Proxy String)) (gfrom "foo")
_:_ 'f' "oo"