[Haskell-beginners] converting a json encoded radix tree to a haskell data type
Adam Flott
adam at adamflott.com
Thu Aug 27 15:30:36 UTC 2015
On 08/27/2015 11:18 AM, Karl Voelker wrote:
> On Thu, Aug 27, 2015, at 08:04 AM, Adam Flott wrote:
>> data Things = MkThings {
>> thing :: TL.Text,
>> times :: ThingTimes
>> } deriving (Show, Eq, Typeable)
>>
>> data ThingTimes = MkThingtimes {
>> ml :: V.Vector Times
>> } deriving (Show, Eq, Typeable)
>>
>> data Times = MkTimes {
>> t1 :: Maybe Int32,
>> t2 :: Maybe Int32
>> } deriving (Show, Eq, Typeable)
>>
>> -- radix.json --
>> {
>> "a" : {
>> "b" : [ 1, 2 ],
>> "c" : {
>> "d" : [ 3, null ]
>> }
>> },
>> "a2" : { "b2" : [ 4, 5 ] }
>> }
>> -- radix.json --
> It looks like your input file has Things nested inside Things, but your
> data types don't allow for that. Is that intentional? What value is that
> example input supposed to parse to?
Vector [
MkThings "ab" (MkThingTimes (Vector [ Just 1, Just 2 ])),
MkThings "abcd" (MkThingsTimes (Vector [ Just 3, Nothing))
MkThings "a2b2" (MkThingTimes (Vector [ Just 4, Just 5 ])) ]
More information about the Beginners
mailing list