1. Define a datatype which supports Ron serialization:
data MyType = Cons1 { _mtBool :: !Bool , _mtList :: ![Text] , _mtOtherValue :: !OtherType } | Cons2 Text Int deriving (Generic) deriving ('ToRon', 'FromRon') via 'RonWith' '['FieldsDropPrefix'] MyType
For more options, see "Data.Ron.Class".
You will need to set DerivingStrategies, DerivingVia, DeriveGeneric,
DataKinds
for this to compile.
2. Read a value of this type from a file with decodeFile:
myValue <- decodeFile "path\/to\/file" useMyValue myValue
3. Write your value to a file with encodeFile
encodeFile haskellStyle "path\/to\/file" myValue
For a type defined above, you can expect the serialized form to look like this:
Cons1 ( bool: false , list: [ "list" , "of" , "strings" ] , otherValue: OtherType (/* something here */) )
• Serialize and deserialize: | ||
• Ron class and deriving: |