Incremental
fumieval/incremental を使うと、任意のデータ型の値の差分が取得できる。
動作確認を行なった incremental のバージョン
fumieval/incremental@4cf2c99098dcaad902587ed1de03fc447350eb9e
Main.hs
code: (hs)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Lib where
import Data.Extensible
import Data.Incremental
type Person = Record
'[ "name" >: String
, "age" >: Int
]
instance Incremental String where
type Delta String = String
diff str1 str2 =
if str1 == str2
then Nothing
else Just ""
alice :: Person
alice = #name @= "Alice"
<: #age @= 10
<: nil
bob :: Person
bob = #name @= "Bob"
<: #age @= 10
<: nil
fakeBob :: Person
fakeBob = #name @= "BoB"
<: #age @= 14
<: nil
example :: IO ()
example = do
print $ diff alice bob
print $ diff alice fakeBob
print $ diff bob fakeBob
print $ diff bob bob
実行例
code: (hs)
ghci> example
Just (WrapDelta {unwrapDelta = Just ""} <: WrapDelta {unwrapDelta = Nothing} <: nil)
Just (WrapDelta {unwrapDelta = Just ""} <: WrapDelta {unwrapDelta = Just 14} <: nil)
Just (WrapDelta {unwrapDelta = Just ""} <: WrapDelta {unwrapDelta = Just 14} <: nil)
Nothing