Skip to content

Commit 2366f40

Browse files
Add FromDhall instance for Contravariant functors: Predicate, Equivalence, Op (#2278)
1 parent 9b43e4b commit 2366f40

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

dhall/src/Dhall/Marshal/Decode.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE ConstraintKinds #-}
33
{-# LANGUAGE DefaultSignatures #-}
44
{-# LANGUAGE DeriveFunctor #-}
5+
{-# LANGUAGE DerivingStrategies #-}
56
{-# LANGUAGE FlexibleContexts #-}
67
{-# LANGUAGE FlexibleInstances #-}
78
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -12,6 +13,7 @@
1213
{-# LANGUAGE RankNTypes #-}
1314
{-# LANGUAGE RecordWildCards #-}
1415
{-# LANGUAGE ScopedTypeVariables #-}
16+
{-# LANGUAGE StandaloneDeriving #-}
1517
{-# LANGUAGE TupleSections #-}
1618
{-# LANGUAGE TypeApplications #-}
1719
{-# LANGUAGE TypeFamilies #-}
@@ -130,6 +132,7 @@ import Data.Either.Validation
130132
, eitherToValidation
131133
, validationToEither
132134
)
135+
import Data.Functor.Contravariant (Op(..), Predicate(..), Equivalence(..))
133136
import Data.Hashable (Hashable)
134137
import Data.Int (Int16, Int32, Int64, Int8)
135138
import Data.List.NonEmpty (NonEmpty (..))
@@ -338,6 +341,12 @@ instance FromDhall (f (Result f)) => FromDhall (Result f) where
338341

339342
expected = pure "result"
340343

344+
deriving newtype instance (ToDhall x) => FromDhall (Predicate x)
345+
346+
deriving newtype instance (ToDhall x) => FromDhall (Equivalence x)
347+
348+
deriving newtype instance (FromDhall b, ToDhall x) => FromDhall (Op b x)
349+
341350
-- | You can use this instance to marshal recursive types from Dhall to Haskell.
342351
--
343352
-- Here is an example use of this instance:

0 commit comments

Comments
 (0)