Skip to content

Commit b502f14

Browse files
dhall: Add Data instance to Import
1 parent 236a04f commit b502f14

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

dhall/CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Unreleased
2+
3+
* [Add `Data` instances for `Import` and various other types](https://github.com/dhall-lang/dhall-haskell/pull/2462)
4+
15
1.41.2
26

37
* [BUG FIX: Fix `:hash` REPL command to α-normalize input](https://github.com/dhall-lang/dhall-haskell/pull/2420)
@@ -1049,7 +1053,7 @@
10491053
* This allows the `dhall` package to be built without using
10501054
`TemplateHaskell`
10511055
* See: https://github.com/dhall-lang/dhall-haskell/pull/928
1052-
* Increase lines of context for error messages
1056+
* Increase lines of context for error messages
10531057
* Error messages now provide at least 20 lines of context instead of 3
10541058
before truncating large expressions
10551059
* See: https://github.com/dhall-lang/dhall-haskell/pull/916
@@ -1432,7 +1436,7 @@
14321436
expression
14331437
* You can pin the new hashes by supplying the `--protocol-version 1.0`
14341438
option on the command line until you need support for newer language
1435-
features
1439+
features
14361440
* This also includes a breaking change to `ImportType` in the API
14371441
* BREAKING CHANGE TO THE LANGUAGE: Disallow combining records of terms and
14381442
types

dhall/ghc-src/Dhall/Crypto.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DeriveDataTypeable #-}
12
{-# LANGUAGE DeriveGeneric #-}
23
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
34

@@ -14,6 +15,7 @@ module Dhall.Crypto (
1415

1516
import Control.DeepSeq (NFData)
1617
import Data.ByteString (ByteString)
18+
import Data.Data (Data)
1719
import GHC.Generics (Generic)
1820

1921
import qualified Crypto.Hash.SHA256
@@ -23,7 +25,7 @@ import qualified Data.ByteString.Char8 as ByteString.Char8
2325

2426
-- | A SHA256 digest
2527
newtype SHA256Digest = SHA256Digest { unSHA256Digest :: ByteString }
26-
deriving (Eq, Generic, Ord, NFData)
28+
deriving (Data, Eq, Generic, Ord, NFData)
2729

2830
instance Show SHA256Digest where
2931
show = toString

dhall/ghcjs-src/Dhall/Crypto.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DeriveDataTypeable #-}
12
{-# LANGUAGE DeriveGeneric #-}
23
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
34
{-# LANGUAGE JavaScriptFFI #-}
@@ -14,6 +15,7 @@ module Dhall.Crypto (
1415

1516
import Control.DeepSeq (NFData)
1617
import Data.ByteString (ByteString)
18+
import Data.Data (Data)
1719
import GHC.Generics (Generic)
1820
import JavaScript.TypedArray.ArrayBuffer (ArrayBuffer)
1921
import System.IO.Unsafe (unsafePerformIO)
@@ -25,7 +27,7 @@ import qualified GHCJS.Buffer as Buffer
2527

2628
-- | A SHA256 digest
2729
newtype SHA256Digest = SHA256Digest { unSHA256Digest :: ByteString }
28-
deriving (Eq, Generic, Ord, NFData)
30+
deriving (Data, Eq, Generic, Ord, NFData)
2931

3032
instance Show SHA256Digest where
3133
show (SHA256Digest bytes) = ByteString.Char8.unpack $ Base16.encode bytes

dhall/src/Dhall/Syntax/Expr.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ data Expr s a
245245
| ImportAlt (Expr s a) (Expr s a)
246246
-- | > Embed import ~ import
247247
| Embed a
248-
deriving Generic
248+
deriving (Generic)
249249
-- NB: If you add a constructor to Expr, please also update the Arbitrary
250250
-- instance in Dhall.Test.QuickCheck.
251251

dhall/src/Dhall/Syntax/Import.hs

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
{-# LANGUAGE DeriveGeneric #-}
2-
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE RecordWildCards #-}
1+
{-# LANGUAGE DeriveDataTypeable #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE RecordWildCards #-}
45

56
module Dhall.Syntax.Import
67
( Directory(..)
@@ -14,9 +15,11 @@ module Dhall.Syntax.Import
1415
, Scheme(..)
1516
) where
1617

18+
import Data.Data (Data)
1719
import Data.Text (Text)
1820
import Dhall.Src (Src (..))
1921
import Dhall.Syntax.Expr (Expr (..))
22+
import Dhall.Syntax.Instances.Data ()
2023
import Dhall.Syntax.Instances.Functor ()
2124
import GHC.Generics (Generic)
2225

@@ -29,15 +32,15 @@ import qualified Dhall.Crypto
2932
@Directory { components = [ "baz", "bar", "foo" ] }@
3033
-}
3134
newtype Directory = Directory { components :: [Text] }
32-
deriving Generic
35+
deriving (Data, Generic)
3336

3437
{-| A `File` is a `directory` followed by one additional path component
3538
representing the `file` name
3639
-}
3740
data File = File
3841
{ directory :: Directory
3942
, file :: Text
40-
} deriving Generic
43+
} deriving (Data, Generic)
4144

4245
-- | The beginning of a file path which anchors subsequent path components
4346
data FilePrefix
@@ -49,11 +52,11 @@ data FilePrefix
4952
-- ^ Path relative to @..@
5053
| Home
5154
-- ^ Path relative to @~@
52-
deriving Generic
55+
deriving (Data, Generic)
5356

5457
-- | The URI scheme
5558
data Scheme = HTTP | HTTPS
56-
deriving Generic
59+
deriving (Data, Generic)
5760

5861
-- | This type stores all of the components of a remote import
5962
data URL = URL
@@ -62,7 +65,7 @@ data URL = URL
6265
, path :: File
6366
, query :: Maybe Text
6467
, headers :: Maybe (Expr Src Import)
65-
} deriving Generic
68+
} deriving (Data, Generic)
6669

6770
-- | The type of import (i.e. local vs. remote vs. environment)
6871
data ImportType
@@ -73,23 +76,23 @@ data ImportType
7376
| Env Text
7477
-- ^ Environment variable
7578
| Missing
76-
deriving Generic
79+
deriving (Data, Generic)
7780

7881
-- | How to interpret the import's contents (i.e. as Dhall code or raw text)
7982
data ImportMode = Code | RawText | Location
80-
deriving Generic
83+
deriving (Data, Generic)
8184

8285
-- | A `ImportType` extended with an optional hash for semantic integrity checks
8386
data ImportHashed = ImportHashed
8487
{ hash :: Maybe Dhall.Crypto.SHA256Digest
8588
, importType :: ImportType
86-
} deriving Generic
89+
} deriving (Data, Generic)
8790

8891
-- | Reference to an external resource
8992
data Import = Import
9093
{ importHashed :: ImportHashed
9194
, importMode :: ImportMode
92-
} deriving Generic
95+
} deriving (Data, Generic)
9396

9497

9598

0 commit comments

Comments
 (0)