Skip to content

Commit b808829

Browse files
Add FromDhall instance for Contravariant functors: Predicate, Equivalence, Op
1 parent 9b43e4b commit b808829

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

dhall/src/Dhall/Marshal/Decode.hs

+12
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 #-}
@@ -117,6 +119,9 @@ module Dhall.Marshal.Decode
117119
, Text
118120
, Vector
119121
, Generic
122+
, Op
123+
, Predicate
124+
, Equivalence
120125
) where
121126

122127

@@ -130,6 +135,7 @@ import Data.Either.Validation
130135
, eitherToValidation
131136
, validationToEither
132137
)
138+
import Data.Functor.Contravariant (Op(..), Predicate(..), Equivalence(..))
133139
import Data.Hashable (Hashable)
134140
import Data.Int (Int16, Int32, Int64, Int8)
135141
import Data.List.NonEmpty (NonEmpty (..))
@@ -338,6 +344,12 @@ instance FromDhall (f (Result f)) => FromDhall (Result f) where
338344

339345
expected = pure "result"
340346

347+
deriving newtype instance (ToDhall x) => FromDhall (Predicate x)
348+
349+
deriving newtype instance (ToDhall x) => FromDhall (Equivalence x)
350+
351+
deriving newtype instance (FromDhall b, ToDhall x) => FromDhall (Op b x)
352+
341353
-- | You can use this instance to marshal recursive types from Dhall to Haskell.
342354
--
343355
-- Here is an example use of this instance:

0 commit comments

Comments
 (0)