composite-dhall 0.0.4.1 → 0.0.6.0
raw patch · 11 files changed
+103/−4 lines, 11 filesdep +vinylPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: vinyl
API changes (from Hackage documentation)
- Composite.Dhall: data CoF f xs
- Composite.Dhall: data F f xs
+ Composite.Dhall: CoF :: Rec f xs -> CoF f xs
+ Composite.Dhall: F :: Rec f xs -> F f xs
+ Composite.Dhall: [unCoF] :: CoF f xs -> Rec f xs
+ Composite.Dhall: [unF] :: F f xs -> Rec f xs
+ Composite.Dhall: instance Data.Functor.Contravariant.Contravariant Composite.Dhall.TextTemplate
+ Composite.Dhall: newtype CoF f xs
+ Composite.Dhall: newtype F f xs
+ Composite.Dhall.CoRecord: instance (Data.Vinyl.Core.RMap xs, Data.Vinyl.Core.RecApplicative xs, Composite.CoRecord.FoldRec ((s Composite.Record.:-> x) : xs) ((s Composite.Record.:-> x) : xs), xs Data.Vinyl.Lens.⊆ ((s Composite.Record.:-> x) : xs), GHC.TypeLits.KnownSymbol s, Composite.Dhall.CoRecord.FromDhallUnion (Composite.CoRecord.Field xs), Dhall.Marshal.Decode.FromDhall x) => Dhall.Marshal.Decode.FromDhall (Composite.CoRecord.Field ((s Composite.Record.:-> x) : xs))
+ Composite.Dhall.CoRecord: instance (Data.Vinyl.Core.RMap xs, Data.Vinyl.Core.RecApplicative xs, GHC.TypeLits.KnownSymbol s, Dhall.Marshal.Decode.FromDhall x, xs Data.Vinyl.Lens.⊆ ((s Composite.Record.:-> x) : xs), Composite.CoRecord.FoldRec ((s Composite.Record.:-> x) : xs) ((s Composite.Record.:-> x) : xs), Composite.Dhall.CoRecord.FromDhallUnion (Composite.CoRecord.Field xs)) => Composite.Dhall.CoRecord.FromDhallUnion (Composite.CoRecord.Field ((s Composite.Record.:-> x) : xs))
+ Composite.Dhall.CoRecord: instance (GHC.TypeLits.KnownSymbol s, Dhall.Marshal.Decode.FromDhall x) => Composite.Dhall.CoRecord.FromDhallUnion (s Composite.Record.:-> x)
+ Composite.Dhall.CoRecord: instance Composite.Dhall.CoRecord.FromDhallUnion (Composite.CoRecord.Field '[])
+ Composite.Dhall.CoRecord: instance Composite.Dhall.CoRecord.FromDhallUnion x => Composite.Dhall.CoRecord.FromDhallUnion (Data.Functor.Identity.Identity x)
Files
- ChangeLog.md +9/−0
- composite-dhall.cabal +10/−1
- src/Composite/Dhall.hs +3/−1
- src/Composite/Dhall/CoRecord.hs +49/−0
- test/Spec.hs +21/−2
- test/data/A.dhall +2/−0
- test/data/B.dhall +2/−0
- test/data/C.dhall +3/−0
- test/data/D.dhall +2/−0
- test/data/E.dhall +1/−0
- test/data/F.dhall +1/−0
ChangeLog.md view
@@ -1,5 +1,14 @@ # Changelog for composite-dhall +## v0.0.6.0++* Fix exports for `F` and `CoF`.+* Fix Contravariant export for `TextTemplate`.++## v0.0.5.0++* Add Composite.Dhall.CoRec with an instance for `Field`.+ ## v0.0.4.0 * Change implementations to use DerivingVia.
composite-dhall.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: composite-dhall-version: 0.0.4.1+version: 0.0.6.0 synopsis: Dhall instances for composite records. description: Dhall instances for composite records. category: Composite, Data, Dhall@@ -18,6 +18,12 @@ extra-source-files: README.md ChangeLog.md+ test/data/A.dhall+ test/data/B.dhall+ test/data/C.dhall+ test/data/D.dhall+ test/data/E.dhall+ test/data/F.dhall source-repository head type: git@@ -26,6 +32,7 @@ library exposed-modules: Composite.Dhall+ Composite.Dhall.CoRecord other-modules: Paths_composite_dhall hs-source-dirs:@@ -36,6 +43,7 @@ , composite-base >=0.7.0.0 && <0.8 , dhall >=1.34.0 && <1.40 , text >=1.0 && <1.4+ , vinyl >=0.13.0 && <0.14 default-language: Haskell2010 test-suite composite-dhall-test@@ -54,4 +62,5 @@ , tasty , tasty-hunit , text >=1.0 && <1.4+ , vinyl >=0.13.0 && <0.14 default-language: Haskell2010
src/Composite/Dhall.hs view
@@ -13,7 +13,7 @@ {-# LANGUAGE TypeOperators #-} {-# OPTIONS_GHC -fno-warn-incomplete-patterns #-} -module Composite.Dhall (TextTemplate (TextTemplate, unTextTemplate), runTextTemplate, F (unF), CoF (unCoF)) where+module Composite.Dhall (TextTemplate (TextTemplate, unTextTemplate), runTextTemplate, F (F, unF), CoF (CoF, unCoF)) where import Composite.Record import Control.Applicative@@ -211,6 +211,8 @@ -- @since 0.0.3.0 newtype TextTemplate a = TextTemplate {unTextTemplate :: Op Text a} deriving newtype (D.FromDhall)++deriving newtype instance Contravariant TextTemplate -- | Run a `TextTemplate` against a value. --
+ src/Composite/Dhall/CoRecord.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DerivingVia #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}++module Composite.Dhall.CoRecord () where++import Composite.CoRecord hiding (Op)+import Composite.Record+import Data.Functor.Compose+import Data.Functor.Identity+import Data.Vinyl+import qualified Dhall as D+import GHC.TypeLits++class FromDhallUnion x where+ autoWithU :: D.InputNormalizer -> D.UnionDecoder x++instance (KnownSymbol s, D.FromDhall x) => FromDhallUnion (s :-> x) where+ autoWithU opts =+ let nL :: (s :-> a)+ nL = undefined+ in D.constructor (valName nL) (Val @s <$> D.autoWith opts)++instance FromDhallUnion (Field '[]) where+ autoWithU = pure $ D.UnionDecoder $ Compose mempty++instance FromDhallUnion x => FromDhallUnion (Identity x) where+ autoWithU opts = Identity <$> autoWithU opts++instance (RMap xs, RecApplicative xs, FoldRec (s :-> x ': xs) (s :-> x ': xs), xs ⊆ (s :-> x ': xs), KnownSymbol s, FromDhallUnion (Field xs), D.FromDhall x) => D.FromDhall (Field (s :-> x ': xs)) where+ autoWith opts = D.union $ autoWithU opts++instance (RMap xs, RecApplicative xs, KnownSymbol s, D.FromDhall x, xs ⊆ (s :-> x ': xs), FoldRec (s :-> x ': xs) (s :-> x ': xs), FromDhallUnion (Field xs)) => FromDhallUnion (Field (s :-> x ': xs)) where+ autoWithU opts =+ let k :: Field xs -> Field (s :-> x ': xs)+ k = widenField+ l :: Field '[s :-> x] -> Field (s :-> x ': xs)+ l = widenField+ (p :: D.UnionDecoder (Field (s :-> x ': xs))) = fmap (l . CoVal . Identity) (autoWithU @(s :-> x) opts)+ (q :: D.UnionDecoder (Field (s :-> x ': xs))) = fmap k (autoWithU @(Field xs) opts)+ in (p <> q :: D.UnionDecoder (Field (s :-> x ': xs)))
test/Spec.hs view
@@ -1,22 +1,28 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE DerivingVia #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralisedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} {-# OPTIONS_GHC -fno-warn-unused-top-binds #-} module Main (main) where import Composite+import Composite.CoRecord hiding (Op) import Composite.Dhall+import Composite.Dhall.CoRecord () import Composite.TH import Data.Functor.Contravariant+import Data.Functor.Identity import Data.Text-import Dhall+import Dhall as D hiding (field) import Test.Tasty import Test.Tasty.HUnit @@ -29,6 +35,8 @@ type RecId = Record '[A, B] +type CoRecId = CoRec Identity '[A, B]+ type RecMaybe = Rec Maybe '[A, B] type RecList = Rec [] '[A, B]@@ -36,6 +44,12 @@ recId :: RecId recId = "foo" :*: 5 :*: RNil +coRecId :: CoRecId+coRecId = field @A "foo"++coRecId2 :: CoRecId+coRecId2 = field @B 5+ recMaybe :: RecMaybe recMaybe = Just "foo" :^: Just 5 :^: RNil @@ -60,7 +74,12 @@ pure (), testCase "parses List Rec" $ do x <- input auto "./test/data/D.dhall"- assertEqual "" recList x+ assertEqual "" recList x,+ testCase "parses CoRec" $ do+ x <- input auto "./test/data/E.dhall"+ assertEqual "" coRecId x+ y <- input auto "./test/data/F.dhall"+ assertEqual "" coRecId2 y ] main :: IO ()
+ test/data/A.dhall view
@@ -0,0 +1,2 @@+{ a = "foo"+, b = +5 }
+ test/data/B.dhall view
@@ -0,0 +1,2 @@+{ a = Some "foo"+, b = Some +5 }
+ test/data/C.dhall view
@@ -0,0 +1,3 @@+{ a = \(x : Text) -> "Hello, ${x}!"+, b = \(y : Integer) -> "You are ${Integer/show y} years old."+}
+ test/data/D.dhall view
@@ -0,0 +1,2 @@+{ a = ["foo", "bar"]+, b = [ +5, +4] }
+ test/data/E.dhall view
@@ -0,0 +1,1 @@+< a : Text | b : Integer >.a "foo"
+ test/data/F.dhall view
@@ -0,0 +1,1 @@+< a : Text | b : Integer >.b +5