-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable sum of product styling #35
Changes from all commits
eb5d1fc
b6976c4
91e74f0
2d8537e
e9808cc
c71eb76
d168774
c805353
e8cc031
47003b2
8b41601
51123b9
72b0396
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@JsonClassDiscriminator("tag") | ||
@Parcelize | ||
@Serializable | ||
sealed class Enum : Parcelable { | ||
@Parcelize | ||
@Serializable | ||
@SerialName("dataCons0") | ||
data class DataCons0(val contents: Record0) : Enum() | ||
|
||
@Parcelize | ||
@Serializable | ||
@SerialName("dataCons1") | ||
object DataCons1 : Enum() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@JsonClassDiscriminator("tag") | ||
@Parcelize | ||
@Serializable | ||
sealed class Enum : Parcelable { | ||
@Parcelize | ||
@Serializable | ||
@SerialName("dataCons0") | ||
data class DataCons0(val contents: Record0) : Enum() | ||
|
||
@Parcelize | ||
@Serializable | ||
@SerialName("dataCons1") | ||
data class DataCons1(val contents: Record1) : Enum() | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@Parcelize | ||
@Serializable | ||
data class Record0( | ||
val record0Field0: Int, | ||
val record0Field1: Int, | ||
) : Parcelable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@Parcelize | ||
@Serializable | ||
data class Record0( | ||
val record0Field0: Int, | ||
val record0Field1: Int, | ||
) : Parcelable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@Parcelize | ||
@Serializable | ||
data class Record1( | ||
val record1Field0: Int, | ||
val record1Field1: Int, | ||
) : Parcelable |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,9 @@ module Moat | |
-- ** Option type and defaults | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes here are just passing options down to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Options, | ||
defaultOptions, | ||
EncodingStyle (..), | ||
SumOfProductEncodingOptions (..), | ||
defaultSumOfProductEncodingOptions, | ||
|
||
-- ** Helper type for omissions | ||
KeepOrDiscard (..), | ||
|
@@ -64,6 +67,7 @@ module Moat | |
omitFields, | ||
omitCases, | ||
makeBase, | ||
sumOfProductEncodingOptions, | ||
|
||
-- * Pretty-printing | ||
|
||
|
@@ -662,7 +666,7 @@ consToMoatType :: | |
consToMoatType o@Options {..} parentName instTys variant ts bs = \case | ||
[] -> do | ||
value <- lift $ newName "value" | ||
matches <- liftCons (mkVoid parentName instTys ts) | ||
matches <- liftCons (mkVoid o parentName instTys ts) | ||
lift $ lamE [varP value] (caseE (varE value) matches) | ||
cons -> do | ||
-- TODO: use '_' instead of matching | ||
|
@@ -695,7 +699,7 @@ consToMoatType o@Options {..} parentName instTys variant ts bs = \case | |
cases <- forM cons' (liftEither . mkCase o) | ||
ourMatch <- | ||
matchProxy | ||
=<< lift (enumExp parentName instTys dataInterfaces dataProtocols dataAnnotations cases dataRawValue ts bs) | ||
=<< lift (enumExp parentName instTys dataInterfaces dataProtocols dataAnnotations cases dataRawValue ts bs sumOfProductEncodingOptions) | ||
pure [pure ourMatch] | ||
|
||
liftCons :: (Functor f, Applicative g) => f a -> f [g a] | ||
|
@@ -831,7 +835,7 @@ mkTypeTag Options {..} typName instTys = \case | |
mkName | ||
(nameStr typName ++ "Tag") | ||
let tag = tagExp typName parentName field False | ||
matchProxy =<< lift (enumExp parentName instTys dataInterfaces dataProtocols dataAnnotations [] dataRawValue [tag] (False, Nothing, [])) | ||
matchProxy =<< lift (enumExp parentName instTys dataInterfaces dataProtocols dataAnnotations [] dataRawValue [tag] (False, Nothing, []) sumOfProductEncodingOptions) | ||
_ -> throwError $ NotANewtype typName | ||
|
||
-- make a newtype into a type alias | ||
|
@@ -860,16 +864,17 @@ mkTypeAlias typName instTys = \case | |
-- | Make a void type (empty enum) | ||
mkVoid :: | ||
() => | ||
Options -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like a good use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah lol i see that you already have this as a refactoring potential! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is definitely getting tedious to pass these around over and over. |
||
-- | type name | ||
Name -> | ||
-- | type variables | ||
[Type] -> | ||
-- | tags | ||
[Exp] -> | ||
MoatM Match | ||
mkVoid typName instTys ts = | ||
mkVoid Options {..} typName instTys ts = | ||
matchProxy | ||
=<< lift (enumExp typName instTys [] [] [] [] Nothing ts (False, Nothing, [])) | ||
=<< lift (enumExp typName instTys [] [] [] [] Nothing ts (False, Nothing, []) sumOfProductEncodingOptions) | ||
|
||
mkNewtype :: | ||
() => | ||
|
@@ -1462,12 +1467,14 @@ enumExp :: | |
[Exp] -> | ||
-- | Make base? | ||
(Bool, Maybe MoatType, [Protocol]) -> | ||
SumOfProductEncodingOptions -> | ||
Q Exp | ||
enumExp parentName tyVars ifaces protos anns cases raw tags bs = | ||
enumExp parentName tyVars ifaces protos anns cases raw tags bs sop = | ||
do | ||
enumInterfaces_ <- Syntax.lift ifaces | ||
enumAnnotations_ <- Syntax.lift anns | ||
enumProtocols_ <- Syntax.lift protos | ||
sumOfProductEncodingOptions_ <- Syntax.lift sop | ||
applyBase bs $ | ||
RecConE | ||
'MoatEnum | ||
|
@@ -1479,7 +1486,8 @@ enumExp parentName tyVars ifaces protos anns cases raw tags bs = | |
('enumCases, ListE cases), | ||
('enumRawValue, rawValueE raw), | ||
('enumPrivateTypes, ListE []), | ||
('enumTags, ListE tags) | ||
('enumTags, ListE tags), | ||
('enumSumOfProductEncodingOption, sumOfProductEncodingOptions_) | ||
] | ||
|
||
newtypeExp :: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tadfisher Yeah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah yeah yeah!