I am studying safecopy library and trying to execute hello world.
I followed the example from haddock and cannot get deserialization working for a new type.
Something is missing in example, which is not obvious.
GHCi, version 8.8.3
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import GHC.Generics
import Data.SafeCopy
import Data.Serialize
data BaseT = BaseT Int deriving (Generic, Serialize, Show, Eq)
instance SafeCopy BaseT where
version = 0
kind = base
putCopy (BaseT s) = contain $ safePut s
getCopy = contain $ BaseT <$> safeGet
data NextT = NextT Int Int deriving (Generic, Serialize, Show, Eq)
instance SafeCopy NextT where
version = 1
kind = extension
putCopy (NextT a b) = contain $ do safePut a ; safePut b
getCopy = contain $ NextT <$> safeGet <*> safeGet
instance Migrate NextT where
type MigrateFrom NextT = BaseT
migrate (BaseT s) = NextT s s
*Main> (runGet safeGet (encode $ BaseT 888)) :: Either String NextT
Left "Failed reading: safecopy: Int: Cannot find getter associated with this version number: Version {unVersion = 888}\nEmpty call stack\n"
Hi.
I am studying safecopy library and trying to execute hello world. I followed the example from haddock and cannot get deserialization working for a new type. Something is missing in example, which is not obvious.
GHCi, version 8.8.3