Skip to content

Commit 0603fb5

Browse files
nc6Soupstraw
authored andcommitted
Improve comments and error messages
1 parent c4afe64 commit 0603fb5

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

example/Monad.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ spec = huddleDef $ mdo
1919
transaction <-
2020
"transaction"
2121
=:= mp
22-
[ idx 0 ==> set txIn,
23-
idx 1 ==> set' <-- txOut
22+
[ idx 0 ==> set txIn
23+
, idx 1 ==> set' <-- txOut
2424
]
2525
txIn <- "txIn" =:= arr ["transaction_id" ==> hash32, "index" ==> txId]
2626
txOut <- "txOut" =:= arr [idx 0 ==> address, idx 1 ==> value]
@@ -44,9 +44,9 @@ spec2 =
4444
_transaction <-
4545
"transaction"
4646
=:= mp
47-
[ comment "Transaction inputs" $ idx 0 ==> set <-- txIn,
48-
comment "Transaction outputs" $ idx 1 ==> set <-- txOut,
49-
comment "Metadata" $ idx 2 ==> metadata
47+
[ comment "Transaction inputs" $ idx 0 ==> set <-- txIn
48+
, comment "Transaction outputs" $ idx 1 ==> set <-- txOut
49+
, comment "Metadata" $ idx 2 ==> metadata
5050
]
5151
metadata <- "metadata" =:= VBytes
5252
_value <- "value" =:= mp ["token" ==> VText, "quantity" ==> VUInt]

src/Codec/CBOR/Cuddle/Huddle.hs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,14 @@ instance IsType0 HuddleItem where
633633
toType0 (HIGroup g) = toType0 g
634634
toType0 (HIGRule g) =
635635
error $
636-
"Attempt to reference generic rule from HuddleItem not supported: " <> show g
636+
"Attempt to reference a raw generic rule: "
637+
<> show g
638+
<> ". Most likely this indicates you haven't provided generic parameters."
637639
toType0 (HIGRule' g) =
638640
error $
639-
"Attempt to reference generic rule from HuddleItem not supported: " <> show g
641+
"Attempt to reference a raw generic rule: "
642+
<> show g
643+
<> ". Most likely this indicates you haven't provided generic parameters."
640644

641645
class CanQuantify a where
642646
-- | Apply a lower bound
@@ -960,12 +964,13 @@ binding2 fRule t0 t1 =
960964
type GRuleDef' = Named (FnWithArg GRef Type0)
961965

962966
data GRuleCallAux = GRuleCallAux
963-
{ defFn :: FnWithArg GRef Type0,
964-
callArg :: Type2
967+
{ defFn :: FnWithArg GRef Type0
968+
, callArg :: Type2
965969
}
966970

967971
type GRuleCall' = Named GRuleCallAux
968972

973+
-- | Create a generic rule definition binding a single generic parameter.
969974
binding' :: (GRef -> Rule) -> GRuleDef'
970975
binding' fRule =
971976
Named
@@ -983,15 +988,18 @@ instance IsGRuleDef GRuleDef' where
983988

984989
instance IsGRuleDef HuddleItem where
985990
toGRuleDef (HIGRule' gd) = gd
986-
toGRuleDef _ = error "Attempt to use a non-generic rule as a GRuleDef"
991+
toGRuleDef hi =
992+
error $
993+
"Attempt to apply generic parameters to a non-generic rule: " <> show hi
987994

995+
-- | Call a generic definition, applying the given type parameter.
988996
(<--) :: (IsType0 t0, IsGRuleDef gd) => gd -> t0 -> GRuleCall'
989997
(toGRuleDef -> f) <-- t0 = fmap toCall f
990998
where
991999
toCall rd =
9921000
GRuleCallAux
993-
{ defFn = rd,
994-
callArg = t2
1001+
{ defFn = rd
1002+
, callArg = t2
9951003
}
9961004
t2 = case toType0 t0 of
9971005
NoChoice x -> x
@@ -1228,7 +1236,7 @@ toCDDL' mkPseudoRoot hdl =
12281236
toGenericCall' (Named n gr _) =
12291237
C.T2Name
12301238
(C.Name n)
1231-
(Just . C.GenericArg $ (toCDDLType1 (callArg gr)) NE.:| [])
1239+
(Just . C.GenericArg $ toCDDLType1 (callArg gr) NE.:| [])
12321240

12331241
toGenRuleDef :: GRuleDef -> C.WithComments C.Rule
12341242
toGenRuleDef (Named n gr c) =

src/Codec/CBOR/Cuddle/Huddle/Generic.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module Codec.CBOR.Cuddle.Huddle.Generic where
22

33
-- | Function carrying its argument
44
data FnWithArg a result = FnWithArg
5-
{ fn :: a -> result,
6-
arg :: a
5+
{ fn :: a -> result
6+
, arg :: a
77
}
88
deriving (Functor)
99

src/Codec/CBOR/Cuddle/Huddle/HuddleM.hs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
-- | Monad for declaring Huddle constructs
2-
module Codec.CBOR.Cuddle.Huddle.HuddleM
3-
( module Huddle,
4-
(=:=),
5-
(=:~),
6-
(=::=),
7-
binding,
8-
binding',
9-
setRootRules,
10-
huddleDef,
11-
huddleDef',
12-
include,
13-
unsafeIncludeFromHuddle,
14-
)
2+
module Codec.CBOR.Cuddle.Huddle.HuddleM (
3+
module Huddle,
4+
(=:=),
5+
(=:~),
6+
(=::=),
7+
binding,
8+
binding',
9+
setRootRules,
10+
huddleDef,
11+
huddleDef',
12+
include,
13+
unsafeIncludeFromHuddle,
14+
)
1515
where
1616

1717
import Codec.CBOR.Cuddle.Huddle hiding (binding, binding', (=:=), (=:~))

0 commit comments

Comments
 (0)