[Haskell-cafe] DB vs read/show for persisting large data
Michael Snoyman
michael at snoyman.com
Wed Dec 14 15:30:41 CET 2011
On Wed, Dec 14, 2011 at 4:22 PM, Claude Heiland-Allen <claude at goto10.org> wrote:
> On 14/12/11 13:59, Marc Weber wrote:
>>
>> Excerpts from Michael Snoyman's message of Wed Dec 14 14:34:30 +0100 2011:
>>>
>>> On Wed, Dec 14, 2011 at 3:31 PM, C K Kashyap<ckkashyap at gmail.com> wrote:
>>> Definite *don't* use read/show: if you make any updates to your data
>>> structures, all old files will be lost.
>>
>>
>> Well you can work around it:
>>
>> data MyDataV1 = {
>> name :: String
>> }
>> deriving (Read,Show)
>>
>> then you make an update:
>>
>> data MyDataV2 = {
>> name :: String,
>> age : Int
>> }
>> deriving (Read,Show)
>>
>> then you can do
>> let (v1 :: MyDataV1) = tryReadDataToMaybe data
>> let (v2 :: MyDataV2) = tryReadDataToMaybe data
>> let real_data = upgrade v1 `or` v2
>>
>>
>> But you already see that you start writing boilerplate code.
>> It can be done for easy data structures .. But it soon will be a night
>> mare if you have complex data.
>>
>> If you use a version control system you don't loose your data - it will
>> just be "hard to update".
>
> [snip]
>
> I ran into this very nightmare in one project, and was recommend safecopy
> [0] by someone on the #haskell IRC channel. I've not (yet) used it but it
> looks very nice!
>
> [0] http://hackage.haskell.org/package/safecopy
That also happens to be one of the best module descriptions I've ever read.
Michael
More information about the Haskell-Cafe
mailing list