tree-diff-0.3.1: Diffing of (expression) trees.
Safe HaskellSafe-Inferred
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 {fooInt = Right -2 +3, fooBool = [Just True], fooString = "fo"}
>>> prettyEditExpr $ ediff (Foo (Right 42) [Just True, Just False] "old") (Foo (Right 42) [Nothing, Just False, Just True] "new")
Foo {
  fooInt = Right 42,
  fooBool = [-Just True, +Nothing, Just False, +Just True],
  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" []]]

Minimal complete definition

Nothing

Methods

toExpr :: a -> Expr Source #

default toExpr :: (Generic a, GToExpr (Rep a)) => a -> Expr Source #

listToExpr :: [a] -> Expr Source #

Instances

Instances details
ToExpr Key Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Value Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr ByteArray Source #

Since: 0.2.2

Instance details

Defined in Data.TreeDiff.Class

ToExpr Void Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Int16 Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Int32 Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Int64 Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Int8 Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Word16 Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Word32 Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Word64 Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Word8 Source # 
Instance details

Defined in Data.TreeDiff.Class

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"]
Instance details

Defined in Data.TreeDiff.Class

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"]
Instance details

Defined in Data.TreeDiff.Class

ToExpr ShortByteString Source #
>>> traverse_ (print . prettyExpr . toExpr . SBS.toShort . BS8.pack) ["", "\n", "foo", "foo\n", "foo\nbar", "foo\nbar\n"]
""
"\n"
"foo"
"foo\n"
mconcat ["foo\n", "bar"]
mconcat ["foo\n", "bar\n"]
Instance details

Defined in Data.TreeDiff.Class

ToExpr IntSet Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Ordering Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Scientific Source #
>>> prettyExpr $ toExpr (123.456 :: Scientific)
scientific 123456 `-3`
Instance details

Defined in Data.TreeDiff.Class

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"]
Instance details

Defined in Data.TreeDiff.Class

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"]
Instance details

Defined in Data.TreeDiff.Class

ToExpr Day Source #
>>> prettyExpr $ toExpr $ ModifiedJulianDay 58014
Day "2017-09-18"
Instance details

Defined in Data.TreeDiff.Class

ToExpr UTCTime Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Expr Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr UUID Source #
>>> prettyExpr $ toExpr UUID.nil
UUID "00000000-0000-0000-0000-000000000000"
Instance details

Defined in Data.TreeDiff.Class

ToExpr Integer Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Natural Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr () Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: () -> Expr Source #

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

ToExpr Bool Source # 
Instance details

Defined in Data.TreeDiff.Class

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"]
Instance details

Defined in Data.TreeDiff.Class

ToExpr Double Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Float Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Int Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr Word Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr a => ToExpr (KeyMap a) Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr a => ToExpr (ZipList a) Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr a => ToExpr (Identity a) Source #
>>> prettyExpr $ toExpr $ Identity 'a'
Identity 'a'
Instance details

Defined in Data.TreeDiff.Class

ToExpr a => ToExpr (First a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: First a -> Expr Source #

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

ToExpr a => ToExpr (Last a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Last a -> Expr Source #

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

ToExpr a => ToExpr (First a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: First a -> Expr Source #

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

ToExpr a => ToExpr (Last a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Last a -> Expr Source #

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

ToExpr a => ToExpr (Max a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Max a -> Expr Source #

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

ToExpr a => ToExpr (Min a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Min a -> Expr Source #

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

ToExpr a => ToExpr (Dual a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Dual a -> Expr Source #

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

ToExpr a => ToExpr (Product a) Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr a => ToExpr (Sum a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Sum a -> Expr Source #

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

ToExpr a => ToExpr (NonEmpty a) Source # 
Instance details

Defined in Data.TreeDiff.Class

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

Defined in Data.TreeDiff.Class

Methods

toExpr :: Ratio a -> Expr Source #

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

ToExpr v => ToExpr (IntMap v) Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr v => ToExpr (Seq v) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Seq v -> Expr Source #

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

ToExpr k => ToExpr (Set k) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Set k -> Expr Source #

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

ToExpr a => ToExpr (Tree a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Tree a -> Expr Source #

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

ToExpr a => ToExpr (Hashed a) Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr a => ToExpr (Maybe a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Maybe a -> Expr Source #

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

ToExpr k => ToExpr (HashSet k) Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr a => ToExpr (Vector a) Source # 
Instance details

Defined in Data.TreeDiff.Class

(ToExpr a, Prim a) => ToExpr (Vector a) Source # 
Instance details

Defined in Data.TreeDiff.Class

(ToExpr a, Storable a) => ToExpr (Vector a) Source # 
Instance details

Defined in Data.TreeDiff.Class

(ToExpr a, Unbox a) => ToExpr (Vector a) Source # 
Instance details

Defined in Data.TreeDiff.Class

ToExpr a => ToExpr (Maybe a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Maybe a -> Expr Source #

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

ToExpr a => ToExpr [a] Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: [a] -> Expr Source #

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

(ToExpr a, ToExpr b) => ToExpr (Either a b) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Either a b -> Expr Source #

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

HasResolution a => ToExpr (Fixed a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Fixed a -> Expr Source #

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

ToExpr (Proxy a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Proxy a -> Expr Source #

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

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

Defined in Data.TreeDiff.Class

Methods

toExpr :: Map k v -> Expr Source #

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

(ToExpr a, ToExpr b) => ToExpr (Either a b) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Either a b -> Expr Source #

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

(ToExpr a, ToExpr b) => ToExpr (These a b) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: These a b -> Expr Source #

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

(ToExpr a, ToExpr b) => ToExpr (Pair a b) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Pair a b -> Expr Source #

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

(ToExpr a, ToExpr b) => ToExpr (These a b) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: These a b -> Expr Source #

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

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

Defined in Data.TreeDiff.Class

Methods

toExpr :: HashMap k v -> Expr Source #

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

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

Defined in Data.TreeDiff.Class

Methods

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

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

ToExpr a => ToExpr (Const a b) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Const a b -> Expr Source #

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

ToExpr a => ToExpr (Tagged t a) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

toExpr :: Tagged t a -> Expr Source #

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

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

Defined in Data.TreeDiff.Class

Methods

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

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

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

Defined in Data.TreeDiff.Class

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 # 
Instance details

Defined in Data.TreeDiff.Class

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.

Generics

genericToExpr :: (Generic a, GToExpr (Rep a)) => a -> Expr Source #

Generic toExpr.

>>> data Foo = Foo Int Char deriving Generic
>>> genericToExpr (Foo 42 'x')
App "Foo" [App "42" [],App "'x'" []]

class GToExpr f Source #

Minimal complete definition

gtoExpr

Instances

Instances details
GSumToExpr f => GToExpr (M1 i c f) Source # 
Instance details

Defined in Data.TreeDiff.Class

Methods

gtoExpr :: M1 i c f x -> Expr