Skip to content

Instantly share code, notes, and snippets.

@Gabriella439
Created December 5, 2022 23:19
Show Gist options
  • Save Gabriella439/40ab5bc241df8d20b0a899d9da1031dc to your computer and use it in GitHub Desktop.
Save Gabriella439/40ab5bc241df8d20b0a899d9da1031dc to your computer and use it in GitHub Desktop.
{-# 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