Bridge, Lens and variables beginning with underscores
Currently, if you use this module to convert types on which you are using the Lens library, you get an invalid output file since it generates variables with underscores. Fixing this manually is possible, but increasingly tedious as the number of types increases.
I am not sure I understand the problem. Can you show how you derive the instances in a dummy test case, what the result is and what the expected result should ?
Sorry, I really should have explained more.
data Record = Record
{ _fieldA :: Int
}
makeLens ''Record
The library generates lens functions for the fields with underscore. When the elm module is generated for this record, it looks like this:
type alias ARecord =
{ _fieldA: Int
}
jsonDecARecord : Json.Decode.Decoder ( ARecord )
jsonDecARecord =
("_fieldA" := Json.Decode.int) `Json.Decode.andThen` \p_fieldA ->
Json.Decode.succeed {_fieldA = p_fieldA}
jsonEncARecord : ARecord -> Value
jsonEncARecord val =
Json.Encode.object
[ ("_fieldA", Json.Encode.int val._fieldA)
]
However, elm doesn't allow underscores at the beginning of variables. I guess it could be so that it still receives records with underscores, but generates elm type aliases without the underscores.
Usual "fix" is:
$(deriveBoth defaultOptions{ fieldLabelModifier = drop 1}) ''Record
Is that acceptable for your use case ?
This is a perfect fix. I can't think of a case where it wouldn't be. Sorry, I guess I should have read the documentation. Figures that this would already have been adressed
I think it might be worth it to keep the issue open, as elm-bridge shouldn't generate invalid elm code.