Skip to content

Instantly share code, notes, and snippets.

@Gabriella439
Created December 5, 2022 23:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Example where
import Data.Text (Text)
import GHC.Generics (Generic)
import Dhall (ToDhall)
import Dhall.Diff (Diff)
import OldType (OldType)
import NewType (NewType)
import qualified Dhall
import qualified Dhall.Core as Core
import qualified Dhall.Diff as Diff
diffType :: forall a b . (ToDhall a, ToDhall b) => Diff
diffType = do
Diff.diff
(Core.denote (Dhall.declared (Dhall.inject @a)))
(Core.denote (Dhall.declared (Dhall.inject @b)))
main :: IO ()
main = do
print (Diff.doc (diffType @OldType @NewType))
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
module NewType where
import Data.Text (Text)
import Dhall (ToDhall)
import GHC.Generics (Generic)
data NewType
= Foo{ bar :: Text, baz :: Bool, new :: [Double] }
| Qux{ qyzzy :: Integer }
deriving (Generic, ToDhall)
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
module OldType where
import Data.Text (Text)
import Dhall (ToDhall)
import GHC.Generics (Generic)
import Numeric.Natural (Natural)
data OldType
= Foo{ bar :: Text, baz :: Bool }
| Qux{ qyzzy :: Natural }
deriving (Generic, ToDhall)
< Foo : : { + new : …
, …
}
| Qux : : { qyzzy : - Natural
+ Integer
}
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment