On Wed, Oct 16, 2013 at 2:18 PM, Miro Karpis <miroslav.karpis@gmail.com> wrote:
Hi, please,...is it possible to use a capital letter in record syntax data definition? For example

data Car =
  Car { CarName  :: !Text
         ,CarColor   :: !Text
        } deriving (Show,Generic)

When I try this I get: parse error on input `CarName'
 
Record field names cannot start with a capital letter. Haskell uses the case of the first letter of a name to classify it: variables start with a lowercase letter; constructors start with an uppercase letter.


The thing is that I'm trying to parse a json file (with Aeson package) that has records starting with capital letter. After that I would like to parse the JSON file with following code:

 d <- (eitherDecode <$> getJSON) :: IO (Either String [Car])

where getJSON gets the json file from url

If not, what alternative do I have?


If you generate your aeson instances with Data.Aeson.TH.deriveJSON, note that the first parameter to deriveJSON is a function which lets you alter the names. That should enable you to craft a workaround.

-Karl