GithubHelp home page GithubHelp logo

obsidiansystems / aeson-gadt-th Goto Github PK

View Code? Open in Web Editor NEW
22.0 30.0 6.0 88 KB

Template Haskell for generating ToJSON and FromJSON instances for GADTs

License: BSD 3-Clause "New" or "Revised" License

Haskell 81.65% Nix 18.35%
decoding gadt encoding haskell json aeson

aeson-gadt-th's Introduction

aeson-gadt-th

Haskell Hackage Hackage CI Github CI BSD3 License

Provides Template Haskell expressions for deriving ToJSON and FromJSON instances for GADTs.

Example Usage:

> {-# LANGUAGE GADTs #-}
> {-# LANGUAGE KindSignatures #-}
> {-# LANGUAGE TemplateHaskell #-}
> {-# LANGUAGE FlexibleContexts #-}
> {-# LANGUAGE FlexibleInstances #-}
> {-# LANGUAGE UndecidableInstances #-}
> {-# LANGUAGE MultiParamTypeClasses #-}
> {-# OPTIONS_GHC -ddump-splices #-}
>
> import Data.Aeson
> import Data.Aeson.GADT.TH
> import Data.Dependent.Map (DMap)
> import Data.Dependent.Sum (DSum)
> import Data.Functor.Identity
> import Data.GADT.Compare
> import Data.GADT.Show.TH
> import Data.Some (Some(..))
>
> data A :: * -> * where
>   A_a :: A a
>   A_b :: Int -> A ()
>
> deriveJSONGADT ''A
> deriveGShow ''A
>
> data B c :: * -> * where
>   B_a :: c -> A a -> B c a
>   B_x :: B c a
>
> deriveJSONGADT ''B
>
> data C t :: * -> * where
>   C_t :: t -> C t t
>
> deriveJSONGADT ''C
>
> data D t x :: * -> * where
>   D_t :: t -> D t x t
>   D_x :: x -> D t x x
>   D_i :: Int -> D t x Int
>
> deriveJSONGADT ''D
>
> data Auth token a where
>   Auth_Login :: String -> String -> Auth token (Either String token)
>
> deriveJSONGADT ''Auth
>
> -- Some real-world-ish examples.
>
> -- | Edit operations for `LabelledGraph`
> data LabelledGraphEdit v vm em :: * -> * where
>   LabelledGraphEdit_ClearAll :: LabelledGraphEdit v vm em ()
>   LabelledGraphEdit_AddVertex :: vm -> LabelledGraphEdit v vm em v
>   LabelledGraphEdit_AddEdge :: v -> v -> em -> LabelledGraphEdit v vm em ()
>   LabelledGraphEdit_SetVertexProperties :: v -> vm -> LabelledGraphEdit v vm em ()
>   LabelledGraphEdit_SetEdgeProperties :: v -> v -> em -> LabelledGraphEdit v vm em ()
>
> -- | PropertyGraphEdit operatios for `PropertyGraph`
> data PropertyGraphEdit v vp ep r where
>   PropertyGraphEdit_ClearAll :: PropertyGraphEdit v vp ep ()
>   PropertyGraphEdit_AddVertex :: (DMap vp Identity) -> PropertyGraphEdit v vp ep v
>   PropertyGraphEdit_AddEdge :: v -> v -> (DMap ep Identity) -> PropertyGraphEdit v vp ep ()
>   PropertyGraphEdit_SetVertexProperty :: GCompare vp => v -> DSum vp Identity -> PropertyGraphEdit v vp ep ()
>   PropertyGraphEdit_SetEdgeProperty :: GCompare ep => v -> v -> DSum ep Identity -> PropertyGraphEdit v vp ep ()
>
> -- | View operations for `LabelledGraph`
> data LabelledGraphView v vm em :: * -> * where
>   LabelledGraphView_All :: LabelledGraphView v vm em ()
>   LabelledGraphView_GetVertexProperties :: v -> LabelledGraphView v vm em vm
>   LabelledGraphView_GetEdgeProperties :: v -> v -> LabelledGraphView v vm em em
>
> deriveJSONGADT ''LabelledGraphEdit
> deriveJSONGADT ''PropertyGraphEdit
> deriveJSONGADT ''LabelledGraphView
>
> main :: IO ()
> main = do
>   putStrLn $ unlines
>     [ "Encoding of A_a:"
>     , show $ encode A_a
>     , "Decoding of encoded A_a:"
>     , show (decode $ encode A_a :: Maybe (Some A))
>     ]
>
>   putStrLn $ unlines
>     [ "Encoding of (A_b 1):"
>     , show $ encode (A_b 1)
>     , "Decoding of encoded (A_b 1):"
>     , show (decode $ encode (A_b 1) :: Maybe (Some A))
>     ]
>
>   putStrLn $ unlines
>     [ "Encoding of (B_a 'a' (A_b 1)):"
>     , show $ encode (B_a 'a' (A_b 1))
>     , "Decoding of encoded (B_a 'a' (A_b 1)):"
>     , case (decode $ encode (B_a 'a' (A_b 1)) :: Maybe (Some (B Char))) of
>         Just (Some (B_a 'a' (A_b 1))) -> "Succeeded"
>         _-> "Failed"
>     ]

Obsidian Systems

aeson-gadt-th's People

Contributors

alexfmpe avatar ali-abrar avatar carymrobbins avatar cgibbard avatar ericson2314 avatar luigy avatar lysxia avatar srid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aeson-gadt-th's Issues

Fix version bounds on dependent-sum

aeson-gadt-th 0.2.1.1 and older are incompatible with dependent-sum 0.6.2.2 and newer (because the This constructor was removed). This causes cabal to pick up invalid build plans.

Fix: add an upper bound dependent-sum < 0.6.2.2 on all versions of aeson-gadt-th prior to 0.2.1.1 (included).

In the latest release aeson-gadt-th 0.2.2, the existing upper bound dependent-sum < 0.7 can also be relaxed to dependent-sum < 0.8.

Build failures with GHC-8.2 and older

Configuring library for aeson-gadt-th-0.2.1.1..
Preprocessing library for aeson-gadt-th-0.2.1.1..
Building library for aeson-gadt-th-0.2.1.1..
[1 of 1] Compiling Data.Aeson.GADT.TH ( src/Data/Aeson/GADT/TH.hs, /tmp/matrix-worker/1565052630/dist-newstyle/build/x86_64-linux/ghc-8.2.2/aeson-gadt-th-0.2.1.1/build/Data/Aeson/GADT/TH.o )

src/Data/Aeson/GADT/TH.hs:215:90: error:
    • Variable not in scope: (<>) :: t6 -> String -> t7
    • Perhaps you meant one of these:
        ‘<$>’ (imported from Prelude), ‘*>’ (imported from Prelude),
        ‘<$’ (imported from Prelude)
    |
215 |     findVar v _ _ = error $ "substVarsWith: couldn't look up variable substitution for " <> show v
    |                                                                                          ^^

EDIT: I made revisions to current releases e.g. https://hackage.haskell.org/package/aeson-gadt-th-0.2.1.1/revisions/

Unhandled substitution case: ListT

This works:

data Edit r where
  Edit_ClearAll :: Edit ()
  Edit_AddNode :: Id -> Id -> V -> Edit Id

deriveGEq ''Edit
deriveGCompare ''Edit
deriveArgDict ''Edit
deriveJSONGADT ''Edit

But this does not:

data Edit r where
  Edit_ClearAll :: Edit ()
  Edit_AddNode :: [Id] -> [Id] -> V -> Edit Id

deriveGEq ''Edit
deriveGCompare ''Edit
deriveArgDict ''Edit
deriveJSONGADT ''Edit

I get:

error:
    Exception when trying to run
compile-time code:
      substVarsWith: Unhandled substitution case: ListT

Type variables not used in GADT constructors

When not all type variables of a GADT are used as arguments in its constructors, aeson deriving fails. For example, the following works:

data View' v vm em :: * -> * where
  View'_GetVertexProperties :: v -> vm -> View' v vm em vm
  View'_GetEdgeProperties :: v -> v -> em -> View' v vm em em

But not this (which is the realistic type; note the absence of vm/em arguments):

data View' v vm em :: * -> * where
  View'_GetVertexProperties :: v -> View' v vm em vm
  View'_GetEdgeProperties :: v -> v -> View' v vm em em

Compiler will throw an error that looks like:

    • Could not deduce (FromJSON topvar1)
        arising from a use of ‘parseJSON’
      from the context: FromJSON topvar
        bound by the instance declaration
        at common/src/Common/Types.hs:140:1-22
      Possible fix:
        add (FromJSON topvar1) to the context of the instance declaration
    • In a stmt of a 'do' block: (x_a1Zsf) <- parseJSON _v'_a1Zsk
      In the expression:
        do (x_a1Zsf) <- parseJSON _v'_a1Zsk
           return (This (View'_GetVertexProperties x_a1Zsf))
      In a case alternative:
          "View'_GetVertexProperties"
            -> do (x_a1Zsf) <- parseJSON _v'_a1Zsk
                  return (This (View'_GetVertexProperties x_a1Zsf))
    |
140 | deriveJSONGADT ''View'
    | ^^^^^^^^^^^^^^^^^^^^^^

In order to hack around it I ended up adding an unused dummy constructor:

data View' v vm em :: * -> * where
  View'_Unused :: v -> vm -> em -> View' v vm em ()
  View'_GetVertexProperties :: v -> View' v vm em vm
  View'_GetEdgeProperties :: v -> v -> View' v vm em em

Support for type variables in constructor arguments

For this definition (the -> b argument in the Q constructor triggers the error):

data Q a :: * -> * where
  Q :: a -> b -> Q a b

deriveJSONGADT ''Q

I get:

error:
    Exception when trying to run
compile-time code:
      substVarsWith: couldn't
look up variable substitution
for b_6989586621679488156

Using e40c293

Real-world type
data Graph' v :: (* -> *) -> * where
  Graph' :: AdjacencyMap v -> Map v (DMap vp Identity) -> Graph' v vp

Build error with nix on macos

I try to build a project using aeson-gadt-th with nix (and reflex-platform) on macos and get this error. I'm not sure that this is the right place to file the issue. Hopefully you can help. Thank you!

--
(...)
cabal: Encountered missing dependencies:
aeson-gadt-th -any

[nix-shell:~/Documents/myProject]$ cabal install --dependencies-only
clang-5.0: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
Resolving dependencies...
Configuring aeson-gadt-th-0.1.2.1...
Building aeson-gadt-th-0.1.2.1...
Failed to install aeson-gadt-th-0.1.2.1
Build log ( /Users/tilmann/.cabal/logs/ghc-8.4.3/aeson-gadt-th-0.1.2.1-7pYTkAwAT8T7XAxzdKa3k0.log ):
cabal: Entering directory '/var/folders/8m/b09mcrs1275dvkqb2mck9jnr0000gn/T/cabal-tmp-50429/aeson-gadt-th-0.1.2.1'
Configuring aeson-gadt-th-0.1.2.1...
clang-5.0: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
Preprocessing library for aeson-gadt-th-0.1.2.1..
Building library for aeson-gadt-th-0.1.2.1..
[1 of 1] Compiling Data.Aeson.GADT.TH ( src/Data/Aeson/GADT/TH.hs, dist/build/Data/Aeson/GADT/TH.o )
ignoring (possibly broken) abi-depends field for packages
Preprocessing executable 'readme' for aeson-gadt-th-0.1.2.1..
Building executable 'readme' for aeson-gadt-th-0.1.2.1..
[1 of 1] Compiling Main ( README.lhs, dist/build/readme/readme-tmp/Main.o )
Linking dist/build/readme/readme ...
clang-5.0: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
clang-5.0: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
Undefined symbols for architecture x86_64:
"_iconv", referenced from:
_hs_iconv in libHSbase-4.11.1.0.a(iconv.o)
(maybe you meant: _base_GHCziIOziEncodingziIconv_iconvEncoding16_closure, _base_GHCziIOziEncodingziIconv_iconvEncoding1_info , _base_GHCziIOziEncodingziIconv_iconvEncoding3_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding4_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding10_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding4_info , _base_GHCziIOziEncodingziIconv_iconvEncoding10_info , _hs_iconv , _base_GHCziIOziEncodingziIconv_iconvEncoding6_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding7_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding5_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding8_bytes , _base_GHCziIOziEncodingziIconv_iconvEncoding7_info , _hs_iconv_open , _base_GHCziIOziEncodingziIconv_iconvEncoding15_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding11_info , _base_GHCziIOziEncodingziIconv_iconvEncoding15_info , _base_GHCziIOziEncodingziIconv_iconvEncoding14_info , _base_GHCziIOziEncodingziIconv_iconvEncoding9_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding16_info , _base_GHCziIOziEncodingziIconv_iconvEncoding14_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding17_bytes , _base_GHCziIOziEncodingziIconv_iconvEncoding1_closure , _hs_iconv_close , _base_GHCziIOziEncodingziIconv_iconvEncoding2_info , _base_GHCziIOziEncodingziIconv_iconvEncoding11_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding2_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding13_bytes , _base_GHCziIOziEncodingziIconv_iconvEncoding18_info , _base_GHCziIOziEncodingziIconv_iconvEncoding12_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding_info , _base_GHCziIOziEncodingziIconv_iconvEncoding_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding18_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding6_info , _base_GHCziIOziEncodingziIconv_iconvEncoding12_info )
"_iconv_open", referenced from:
_hs_iconv_open in libHSbase-4.11.1.0.a(iconv.o)
(maybe you meant: _hs_iconv_open)
"_iconv_close", referenced from:
_hs_iconv_close in libHSbase-4.11.1.0.a(iconv.o)
(maybe you meant: _hs_iconv_close)
"_locale_charset", referenced from:
_localeEncoding in libHSbase-4.11.1.0.a(PrelIOUtils.o)
ld: symbol(s) not found for architecture x86_64
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
cc' failed in phase Linker'. (Exit code: 1)
cabal: Leaving directory '/var/folders/8m/b09mcrs1275dvkqb2mck9jnr0000gn/T/cabal-tmp-50429/aeson-gadt-th-0.1.2.1'
cabal: Error: some packages failed to install:
aeson-gadt-th-0.1.2.1-7pYTkAwAT8T7XAxzdKa3k0 failed during the building phase.
The exception was:
ExitFailure 1

Test suite does not compile

configureFlags: --verbose --prefix=/nix/store/rnrc4n5igj6sn5867mj5nal0wz14akcg-aeson-gadt-th-0.2.2 --libdir=$prefix/lib/$compiler --libsubdir=$abi/$libname --docdir=/nix/store/6hcacyy860yrk24r9db53fs6plq051di-aeson-gadt-th-0.2.2-doc/share/doc/aeson-gadt-th-0.2.2 --with-gcc=gcc --package-db=/build/package.conf.d --ghc-options=-j16 +RTS -A64M -RTS --disable-split-objs --enable-library-profiling --profiling-detail=exported-functions --disable-profiling --enable-shared --disable-coverage --enable-static --disable-executable-dynamic --enable-tests --disable-benchmarks --enable-library-vanilla --disable-library-for-ghci --ghc-option=-split-sections -f-build-readme --extra-lib-dirs=/nix/store/dgdach00xn196vjsnmisak3maab7x6w5-ncurses-6.2/lib --extra-lib-dirs=/nix/store/rdd4c4iq0f87wgm5av6g5y5n35kqpfvs-libffi-3.3/lib --extra-lib-dirs=/nix/store/7w2d4n6sndpizs87bl1vajg9whcj7s89-gmp-6.2.0/lib
Using Parsec parser
Configuring aeson-gadt-th-0.2.2...
Flags chosen: build-readme=False
Dependency aeson -any: using aeson-1.4.7.1
Dependency base -any: using base-4.14.0.0
Dependency containers -any: using containers-0.6.2.1
Dependency dependent-sum -any: using dependent-sum-0.7.1.0
Dependency template-haskell -any: using template-haskell-2.16.0.0
Dependency th-abstraction -any: using th-abstraction-0.3.2.0
Dependency th-extras -any: using th-extras-0.0.0.4
Dependency transformers -any: using transformers-0.5.6.2
Dependency HUnit -any: using HUnit-1.6.0.0
Dependency aeson -any: using aeson-1.4.7.1
Dependency aeson-gadt-th -any: using aeson-gadt-th-0.2.2
Dependency aeson-qq -any: using aeson-qq-0.8.3
Dependency base -any: using base-4.14.0.0
Dependency dependent-sum -any: using dependent-sum-0.7.1.0
Dependency hspec -any: using hspec-2.7.1
Source component graph:
    component lib
    component test:aeson-gadt-th-test dependency lib
Configured component graph:
    component aeson-gadt-th-0.2.2-8qeLOE4l0976M9Ml6vfawB
        include aeson-1.4.7.1-PoZwsvVZAhEzlieMP6aSv
        include base-4.14.0.0
        include containers-0.6.2.1
        include dependent-sum-0.7.1.0-HiPf7spPyqFHB7Yuhk9b8T
        include template-haskell-2.16.0.0
        include th-abstraction-0.3.2.0-4yEKsz3hkum2d9EYr8unnF
        include th-extras-0.0.0.4-EUajLGRd7XOT9sgTXOjAb
        include transformers-0.5.6.2
    component aeson-gadt-th-0.2.2-I6ejbl2qQdwEYMyTwooXQ7-aeson-gadt-th-test
        include HUnit-1.6.0.0-Hf4MZL6UJVJ4zUg6h23D6W
        include aeson-1.4.7.1-PoZwsvVZAhEzlieMP6aSv
        include aeson-gadt-th-0.2.2-8qeLOE4l0976M9Ml6vfawB
        include aeson-qq-0.8.3-GcMTBxcvph4Bx8zd8yBoeh
        include base-4.14.0.0
        include dependent-sum-0.7.1.0-HiPf7spPyqFHB7Yuhk9b8T
        include hspec-2.7.1-B0aamfuqE2E7AuukmQlXji
Linked component graph:
    unit aeson-gadt-th-0.2.2-8qeLOE4l0976M9Ml6vfawB
        include aeson-1.4.7.1-PoZwsvVZAhEzlieMP6aSv
        include base-4.14.0.0
        include containers-0.6.2.1
        include dependent-sum-0.7.1.0-HiPf7spPyqFHB7Yuhk9b8T
        include template-haskell-2.16.0.0
        include th-abstraction-0.3.2.0-4yEKsz3hkum2d9EYr8unnF
        include th-extras-0.0.0.4-EUajLGRd7XOT9sgTXOjAb
        include transformers-0.5.6.2
        Data.Aeson.GADT.TH=aeson-gadt-th-0.2.2-8qeLOE4l0976M9Ml6vfawB:Data.Aeson.GADT.TH
    unit aeson-gadt-th-0.2.2-I6ejbl2qQdwEYMyTwooXQ7-aeson-gadt-th-test
        include HUnit-1.6.0.0-Hf4MZL6UJVJ4zUg6h23D6W
        include aeson-1.4.7.1-PoZwsvVZAhEzlieMP6aSv
        include aeson-gadt-th-0.2.2-8qeLOE4l0976M9Ml6vfawB
        include aeson-qq-0.8.3-GcMTBxcvph4Bx8zd8yBoeh
        include base-4.14.0.0
        include dependent-sum-0.7.1.0-HiPf7spPyqFHB7Yuhk9b8T
        include hspec-2.7.1-B0aamfuqE2E7AuukmQlXji
Ready component graph:
    definite aeson-gadt-th-0.2.2-8qeLOE4l0976M9Ml6vfawB
        depends aeson-1.4.7.1-PoZwsvVZAhEzlieMP6aSv
        depends base-4.14.0.0
        depends containers-0.6.2.1
        depends dependent-sum-0.7.1.0-HiPf7spPyqFHB7Yuhk9b8T
        depends template-haskell-2.16.0.0
        depends th-abstraction-0.3.2.0-4yEKsz3hkum2d9EYr8unnF
        depends th-extras-0.0.0.4-EUajLGRd7XOT9sgTXOjAb
        depends transformers-0.5.6.2
    definite aeson-gadt-th-0.2.2-I6ejbl2qQdwEYMyTwooXQ7-aeson-gadt-th-test
        depends HUnit-1.6.0.0-Hf4MZL6UJVJ4zUg6h23D6W
        depends aeson-1.4.7.1-PoZwsvVZAhEzlieMP6aSv
        depends aeson-gadt-th-0.2.2-8qeLOE4l0976M9Ml6vfawB
        depends aeson-qq-0.8.3-GcMTBxcvph4Bx8zd8yBoeh
        depends base-4.14.0.0
        depends dependent-sum-0.7.1.0-HiPf7spPyqFHB7Yuhk9b8T
        depends hspec-2.7.1-B0aamfuqE2E7AuukmQlXji
Using Cabal-3.2.0.0 compiled by ghc-8.10
Using compiler: ghc-8.10.1
Using install prefix:
/nix/store/rnrc4n5igj6sn5867mj5nal0wz14akcg-aeson-gadt-th-0.2.2
Executables installed in:
/nix/store/rnrc4n5igj6sn5867mj5nal0wz14akcg-aeson-gadt-th-0.2.2/bin
Libraries installed in:
/nix/store/rnrc4n5igj6sn5867mj5nal0wz14akcg-aeson-gadt-th-0.2.2/lib/ghc-8.10.1/x86_64-linux-ghc-8.10.1/aeson-gadt-th-0.2.2-8qeLOE4l0976M9Ml6vfawB
Dynamic Libraries installed in:
/nix/store/rnrc4n5igj6sn5867mj5nal0wz14akcg-aeson-gadt-th-0.2.2/lib/ghc-8.10.1/x86_64-linux-ghc-8.10.1
Private executables installed in:
/nix/store/rnrc4n5igj6sn5867mj5nal0wz14akcg-aeson-gadt-th-0.2.2/libexec/x86_64-linux-ghc-8.10.1/aeson-gadt-th-0.2.2
Data files installed in:
/nix/store/rnrc4n5igj6sn5867mj5nal0wz14akcg-aeson-gadt-th-0.2.2/share/x86_64-linux-ghc-8.10.1/aeson-gadt-th-0.2.2
Documentation installed in:
/nix/store/6hcacyy860yrk24r9db53fs6plq051di-aeson-gadt-th-0.2.2-doc/share/doc/aeson-gadt-th-0.2.2
Configuration files installed in:
/nix/store/rnrc4n5igj6sn5867mj5nal0wz14akcg-aeson-gadt-th-0.2.2/etc
No alex found
Using ar found on system at:
/nix/store/h4v5qdxlmnh7xfpl7pwzrs8js7220bz2-binutils-2.31.1/bin/ar
No c2hs found
No cpphs found
No doctest found
Using gcc version 9.3.0 given by user at:
/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/bin/gcc
Using ghc version 8.10.1 found on system at:
/nix/store/19bwrir9y3jna13w880mqdm1a78qksab-ghc-8.10.1/bin/ghc
Using ghc-pkg version 8.10.1 found on system at:
/nix/store/19bwrir9y3jna13w880mqdm1a78qksab-ghc-8.10.1/bin/ghc-pkg
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.24.0 found on system at:
/nix/store/19bwrir9y3jna13w880mqdm1a78qksab-ghc-8.10.1/bin/haddock
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.68 found on system at:
/nix/store/19bwrir9y3jna13w880mqdm1a78qksab-ghc-8.10.1/bin/hpc
Using hsc2hs version 0.68.7 found on system at:
/nix/store/19bwrir9y3jna13w880mqdm1a78qksab-ghc-8.10.1/bin/hsc2hs
Using hscolour version 1.24 found on system at:
/nix/store/iihy68ay41v0xq8yrs3xjbkl4mjgpzl4-hscolour-1.24.4/bin/HsColour
No jhc found
Using ld found on system at:
/nix/store/6j585c9pab3lglrxqq1g9c2pa8qjgvj0-binutils-wrapper-2.31.1/bin/ld.gold
No pkg-config found
Using runghc version 8.10.1 found on system at:
/nix/store/19bwrir9y3jna13w880mqdm1a78qksab-ghc-8.10.1/bin/runghc
Using strip version 2.31 found on system at:
/nix/store/h4v5qdxlmnh7xfpl7pwzrs8js7220bz2-binutils-2.31.1/bin/strip
Using tar found on system at:
/nix/store/g0j3pan49fp1nspif0zbcmr3zjzdbl8z-gnutar-1.32/bin/tar
No uhc found
building                                                                                                                                                                                                           
Preprocessing library for aeson-gadt-th-0.2.2..                                                                                                                                                                    
Building library for aeson-gadt-th-0.2.2..                                                                                                                                                                         
[1 of 1] Compiling Data.Aeson.GADT.TH ( src/Data/Aeson/GADT/TH.hs, dist/build/Data/Aeson/GADT/TH.o, dist/build/Data/Aeson/GADT/TH.dyn_o )                                                                          
[1 of 1] Compiling Data.Aeson.GADT.TH ( src/Data/Aeson/GADT/TH.hs, dist/build/Data/Aeson/GADT/TH.p_o )                                                                                                             
Preprocessing test suite 'aeson-gadt-th-test' for aeson-gadt-th-0.2.2..                                                                                                                                            
Building test suite 'aeson-gadt-th-test' for aeson-gadt-th-0.2.2..                                                                                                                                                 
[1 of 2] Compiling Expectations     ( test/Expectations.hs, dist/build/aeson-gadt-th-test/aeson-gadt-th-test-tmp/Expectations.o, dist/build/aeson-gadt-th-test/aeson-gadt-th-test-tmp/Expectations.dyn_o )         
[2 of 2] Compiling Main             ( test/Test.hs, dist/build/aeson-gadt-th-test/aeson-gadt-th-test-tmp/Main.o, dist/build/aeson-gadt-th-test/aeson-gadt-th-test-tmp/Main.dyn_o )                                 
                                                                                                                                                                                                                   
test/Test.hs:61:1: error:                                                                                                                                                                                          
    • No instance for (FromJSON (Unit Char))                                                                                                                                                                       
        arising from a use of ‘parseJSON’                                                                                                                                                                          
    • In a stmt of a 'do' block: Unitx_abBZ <- parseJSON _v'_abC7                                                                                                                                                  
      In the expression:                                                                                                                                                                                           
        do Unitx_abBZ <- parseJSON _v'_abC7                                                                                                                                                                        
           return (Some (Bar x_abBZ))                                                                                                                                                                              
      In a case alternative:                                                                                                                                                                                       
          "Bar"
            -> do Unitx_abBZ <- parseJSON _v'_abC7                                                                                                                                                                 
                  return (Some (Bar x_abBZ))                                                                                                                                                                       
   |                                                                                                                                                                                                               
61 | deriveJSONGADT ''Foo
   | ^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                          
                                                                                                                                                                                                                   
test/Test.hs:61:1: error:                                                                                                                                                                                          
    • Could not deduce (ToJSON (Unit Value))                                                                                                                                                                       
        arising from a use of ‘toJSON’                                                                                                                                                                             
      from the context: a ~ Char                                                                                                                                                                                   
        bound by a pattern with constructor: Bar :: Char -> Foo Char,                                                                                                                                              
                 in a case alternative                                                                                                                                                                             
        at test/Test.hs:61:1-20                                                                                                                                                                                    
    • In the expression: toJSON ("Bar" :: String, Unit toJSON x_abBQ)                                                                                                                                              
      In a case alternative:                                                                                                                                                                                       
          Bar x_abBQ -> toJSON ("Bar" :: String, Unit toJSON x_abBQ)                                                                                                                                               
      In the expression:                                                                                                                                                                                           
        \case                                                                                                                                                                                                      
          Bar x_abBQ -> toJSON ("Bar" :: String, Unit toJSON x_abBQ)                                                                                                                                               
          Baz x_abBU -> toJSON ("Baz" :: String, Unit toJSON x_abBU)                                                                                                                                               
   |
61 | deriveJSONGADT ''Foo
   | ^^^^^^^^^^^^^^^^^^^^
                                                                                                                                                                                                                   
test/Test.hs:61:1: error:                                                                                                                                                                                          
    • Could not deduce (ToJSON (Unit Value))                                                                                                                                                                       
        arising from a use of ‘toJSON’                                                                                                                                                                             
      from the context: a ~ Float                                                                                                                                                                                  
        bound by a pattern with constructor: Baz :: Float -> Foo Float,                                                                                                                                            
                 in a case alternative                                                           
        at test/Test.hs:61:1-20                                                                                                                                                                                    
    • In the expression: toJSON ("Baz" :: String, Unit toJSON x_abBU)                                                                                                                                              
      In a case alternative:                                                                                                                                                                                       
          Baz x_abBU -> toJSON ("Baz" :: String, Unit toJSON x_abBU)                                                                                                                                               
      In the expression:                                                                                                                                                                                           
        \case                                                                                                                                                                                                      
          Bar x_abBQ -> toJSON ("Bar" :: String, Unit toJSON x_abBQ)                                                                                                                                               
          Baz x_abBU -> toJSON ("Baz" :: String, Unit toJSON x_abBU)                                                                                                                                               
   |
61 | deriveJSONGADT ''Foo
   | ^^^^^^^^^^^^^^^^^^^^
                                                                                                                                                                                                                   
test/Test.hs:63:1: error:                                                                                                                                                                                          
    • No instance for (FromJSON (Unit Char))                                                                                                                                                                       
        arising from a use of ‘parseJSON’                                                                                                                                                                          
    • In a stmt of a 'do' block: Unitx_abHt <- parseJSON _v'_abHB                                                                                                                                                  
      In the expression:                                                                                                                                                                                           
        do Unitx_abHt <- parseJSON _v'_abHB                                                                                                                                                                        
           return (Some (Spam'Eggs x_abHt))                                                                                                                                                                        
      In a case alternative:                                                                                                                                                                                       
          "Eggs"
            -> do Unitx_abHt <- parseJSON _v'_abHB                                                                                                                                                                 
                  return (Some (Spam'Eggs x_abHt))                                                                                                                                                                 
   |
63 | deriveJSONGADTWithOptions                                                                                                                                                                                     
   | ^^^^^^^^^^^^^^^^^^^^^^^^^...                                                                                                                                                                                  

test/Test.hs:63:1: error:                                                                                                                                                                                          
    • Could not deduce (ToJSON (Unit Value))                                                                                                                                                                       
        arising from a use of ‘toJSON’                                                                                                                                                                             
      from the context: a ~ Char                                                                                                                                                                                   
        bound by a pattern with constructor:                                                                                                                                                                       
                   Spam'Eggs :: Char -> Spam Char,                                                                                                                                                                 
                 in a case alternative                                                                                                                                                                             
        at test/Test.hs:(63,1)-(65,8)                                                                                                                                                                              
    • In the expression: toJSON ("Eggs" :: String, Unit toJSON x_abHk)                                                                                                                                             
      In a case alternative:                                                                                                                                                                                       
          Spam'Eggs x_abHk -> toJSON ("Eggs" :: String, Unit toJSON x_abHk)                                                                                                                                        
      In the expression:                                                                                                                                                                                           
        \case                                                                                                                                                                                                      
          Spam'Eggs x_abHk -> toJSON ("Eggs" :: String, Unit toJSON x_abHk)                                                                                                                                        
          Spam'Life x_abHo -> toJSON ("Life" :: String, Unit toJSON x_abHo)                                                                                                                                        
   |
63 | deriveJSONGADTWithOptions
   | ^^^^^^^^^^^^^^^^^^^^^^^^^...
                                                                                                                                                                                                                   
test/Test.hs:63:1: error:                                                                                                                                                                                          
    • Could not deduce (ToJSON (Unit Value))                                                                                                                                                                       
        arising from a use of ‘toJSON’                                                                                                                                                                             
      from the context: a ~ Float                                                    
        bound by a pattern with constructor:                                                                                                                                                                       
                   Spam'Life :: Float -> Spam Float,                                                                                                                                                               
                 in a case alternative                                                                                                                                                                             
        at test/Test.hs:(63,1)-(65,8)                                                                                                                                                                              
    • In the expression: toJSON ("Life" :: String, Unit toJSON x_abHo)                                                                                                                                             
      In a case alternative:                                                                                                                                                                                       
          Spam'Life x_abHo -> toJSON ("Life" :: String, Unit toJSON x_abHo)                                                                                                                                        
      In the expression:                                                                                                                                                                                           
        \case
          Spam'Eggs x_abHk -> toJSON ("Eggs" :: String, Unit toJSON x_abHk)                                                                                                                                        
          Spam'Life x_abHo -> toJSON ("Life" :: String, Unit toJSON x_abHo)                                                                                                                                        
   |
63 | deriveJSONGADTWithOptions
   | ^^^^^^^^^^^^^^^^^^^^^^^^^...
                                                                                                                                                                                                                   
builder for '/nix/store/6nf59zs0553xbw9ph7a3fs8b42g62711-aeson-gadt-th-0.2.2.drv' failed with exit code 1         

deriveJSONGADT requires `toJSON` and `parseJSON` to be in scope

The TH should not be looking up names from the calling module's scope. Instead, they should use the names from the TH implementation's scope. The impact is that if the user does not have Data.Aeson in scope, the TH splice fails.

Here are two examples of where it's wrong:

Those are the only two I noticed.

deriveArgDict for higher-kinded GADTs (`* -> * -> * -> * -> *`)

Would be nice to have the TH do this automatically. Currently I have to derive this manually.

data Edit v vm em :: * -> * where
  Edit_ClearAll :: Edit v vm em ()
  Edit_AddVertex :: v -> Edit v vm em v
  Edit_AddEdge :: v -> v -> Edit v vm em ()
  Edit_SetVertexProperties :: v -> vm -> Edit v vm em ()
  Edit_GetVertexProperties :: v -> Edit v vm em vm
  Edit_SetEdgeProperty :: v -> v -> em -> Edit v vm em ()
  Edit_GetEdgeProperty :: v -> v -> Edit v vm em em

deriveJSONGADT ''Edit

-- Derive manually because `deriveArgDict` is broken for type variables in constructor arguments
instance ArgDict (Edit v vm em) where
  type ConstraintsFor (Edit v vm em) c = (c v, c (), c vm, c em)
  argDict = \case
    Edit_ClearAll -> Dict
    Edit_AddVertex _ -> Dict
    Edit_AddEdge _ _ -> Dict
    Edit_SetVertexProperties _ _ -> Dict
    Edit_GetVertexProperties _ -> Dict
    Edit_SetEdgeProperty _ _ _ -> Dict
    Edit_GetEdgeProperty _ _ -> Dict

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.