Skip to content
Merged
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
repository: 'dfinity/candid'
path: candid
ref: ab15036543c10066d0b5c266de2108e9e0133e0a
ref: 9b0e92e8729e660bfdcf02a3169b9a4b829762a4

- uses: haskell/actions/setup@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions candid.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ library
Codec.Candid.EncodeTextual
Codec.Candid.Encode
Codec.Candid.Infer
Codec.Candid.Subtype
Codec.Candid.Coerce

default-language: Haskell2010
Expand Down Expand Up @@ -89,6 +90,7 @@ test-suite test
hs-source-dirs: test
other-modules:
SpecTests
Tests
THTests

default-language: Haskell2010
Expand Down
2 changes: 2 additions & 0 deletions src/Codec/Candid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Candid is inherently typed, so before encoding or decoding, you have to indicate
, unescapeFieldName
, candidHash
, Value(..)
, isSubtypeOf

-- ** Dynamic use

Expand Down Expand Up @@ -150,6 +151,7 @@ import Codec.Candid.TypTable
import Codec.Candid.Decode
import Codec.Candid.Encode
import Codec.Candid.EncodeTextual
import Codec.Candid.Subtype

-- $setup
-- >>> :set -dppr-cols=200
Expand Down
8 changes: 5 additions & 3 deletions src/Codec/Candid/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ decode b = do
-- Decode
(ts, vs) <- decodeVals b
-- Coerce to expected type
c <- coerceSeqDesc ts (buildSeqDesc (asTypes @(AsTuple a)))
vs' <- c vs
vs' <- coerceSeqDesc vs ts (buildSeqDesc (asTypes @(AsTuple a)))
fromCandidVals vs'

-- | Decode (dynamic) values to Haskell type
Expand Down Expand Up @@ -106,9 +105,12 @@ class CandidSeq a where
seqDesc :: forall a. CandidArg a => SeqDesc
seqDesc = buildSeqDesc (asTypes @(AsTuple a))

typeGraph :: forall a. Candid a => Type (Ref TypeRep Type)
typeGraph = asType @(AsCandid a)

-- | NB: This will loop with recursive types!
typeDesc :: forall a. Candid a => Type Void
typeDesc = asType @(AsCandid a) >>= go
typeDesc = typeGraph @a >>= go
where go (Ref _ t) = t >>= go

instance Pretty TypeRep where
Expand Down
Loading