Skip to content

Instantly share code, notes, and snippets.

@Gabriella439
Created December 5, 2022 23:19
Show Gist options
  • Select an option

  • Save Gabriella439/40ab5bc241df8d20b0a899d9da1031dc to your computer and use it in GitHub Desktop.

Select an option

Save Gabriella439/40ab5bc241df8d20b0a899d9da1031dc to your computer and use it in GitHub Desktop.

Revisions

  1. Gabriella439 created this gist Dec 5, 2022.
    26 changes: 26 additions & 0 deletions Example.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    {-# 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))
    13 changes: 13 additions & 0 deletions NewType.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    {-# 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)
    14 changes: 14 additions & 0 deletions OldType.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    {-# 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)
    7 changes: 7 additions & 0 deletions output.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    < Foo : : { + new : …
    , …
    }
    | Qux : : { qyzzy : - Natural
    + Integer
    }
    >