Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:41:41+00:00 2026-06-09T18:41:41+00:00

(src http://hackage.haskell.org/packages/archive/safecopy/0.6.1/doc/html/Data-SafeCopy.html ) If you rename Contacts data type into data Contacts_v0 type Name

  • 0

(src http://hackage.haskell.org/packages/archive/safecopy/0.6.1/doc/html/Data-SafeCopy.html)

If you rename Contacts data type into data Contacts_v0

type Name     = String
type Address  = String
data Contacts = Contacts [(Name, Address)]
instance SafeCopy Contacts where
     putCopy (Contacts list) = contain $ safePut list
     getCopy = contain $ Contacts <$> safeGet

How is Contacts_v0 suppose to be assigned to old existing data?

type Name = String
type Address = String
type Phone = String

data Contacts_v0 = Contacts_v0 [(Name, Address)]
instance SafeCopy Contacts_v0 where
     putCopy (Contacts_v0 list) = contain $ safePut list
     getCopy = contain $ Contacts_v0 <$> safeGet

data Contact = Contact { name    :: Name
                        , address :: Address
                        , phone   :: Phone }
instance SafeCopy Contact where
    putCopy Contact{..} = contain $ do safePut name; safePut address; safePut phone
    getCopy = contain $ Contact <$> safeGet <*> safeGet <*> safeGet

data Contacts = Contacts [Contact]
instance SafeCopy Contacts where
     version = 2
     kind = extension
     putCopy (Contacts contacts) = contain $ safePut contacts
     getCopy = contain $ Contacts <$> safeGet

instance Migrate Contacts where
     type MigrateFrom Contacts = Contacts_v0
     migrate (Contacts_v0 contacts) = Contacts [ Contact{ name    = name
                                                        , address = address
                                                        , phone   = "" }
                                               | (name, address) <- contacts ]

From the above library documentation I am trying to do this.

{-# LANGUAGE RecordWildCards, TypeFamilies #-}
import Control.Applicative
import Data.SafeCopy

type Name = String
type Address = String
type Phone = String

data Contacts = Contacts [(Name, Address)] deriving (Show)
instance SafeCopy Contacts where
     putCopy (Contacts list) = contain $ safePut list
     getCopy = contain $ Contacts <$> safeGet

data Contacts_v0 = Contacts_v0 [(Name, Address)] deriving (Show)
instance SafeCopy Contacts_v0 where
     putCopy (Contacts_v0 list) = contain $ safePut list
     getCopy = contain $ Contacts_v0 <$> safeGet

data Contact = Contact { name :: Name, address :: Address, phone :: Phone } deriving (Show)
instance SafeCopy Contact where
    putCopy Contact{..} = contain $ do safePut name; safePut address; safePut phone
    getCopy = contain $ Contact <$> safeGet <*> safeGet <*> safeGet

{-
data Contacts = Contacts [Contact]
instance SafeCopy Contacts where
     version = 2
     kind = extension
     putCopy (Contacts contacts) = contain $ safePut contacts
     getCopy = contain $ Contacts <$> safeGet

instance Migrate Contacts where
     type MigrateFrom Contacts = Contacts_v0
     migrate (Contacts_v0 contacts) = Contacts [ Contact{ name    = name, address = address, phone   = "" }
                                               | (name, address) <- contacts ]
-}

main :: IO ()
main = do
    let test = Contacts [("gert","home")]
    print test
    --let testNew = how do you migrate test using migrate?
    --print testNew

Note that it would make more sense to me if they renamed the new one to Contacts_v2 instead of renaming the old one.

Maybe I should rephrase the question, when is safecopy useful?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:41:42+00:00Added an answer on June 9, 2026 at 6:41 pm
    {-# LANGUAGE RecordWildCards, TypeFamilies#-}
    import Control.Applicative
    import Data.SafeCopy
    import Data.Binary
    import Data.Serialize.Get
    import Data.Serialize.Put
    
    type Name = String
    type Address = String
    type Phone = String
    
    data Contact = Contact { name :: Name, address :: Address, phone :: Phone } deriving (Show)
    instance Binary Contact where
        put Contact{..} = do put name; put address; put phone
        get = do name <- get; address <- get; phone <- get; return Contact{..}
    instance SafeCopy Contact where
        putCopy Contact{..} = contain $ do safePut name; safePut address; safePut phone
        getCopy = contain $ Contact <$> safeGet <*> safeGet <*> safeGet
    
    data Contacts = Contacts [Contact] deriving (Show)
    instance Binary Contacts where
        put (Contacts set) = put set
        get = fmap Contacts get
    instance SafeCopy Contacts where
         version = 2
         kind = extension
         putCopy (Contacts contacts) = contain $ safePut contacts
         getCopy = contain $ Contacts <$> safeGet
    instance Migrate Contacts where
         type MigrateFrom Contacts = Contacts_v0
         migrate (Contacts_v0 contacts) = Contacts[Contact{name=name,address=address,phone=""}|(name,address)<-contacts]
    
    data Contacts_v0 = Contacts_v0 [(Name, Address)] deriving (Show)
    instance Binary Contacts_v0 where
        put (Contacts_v0 set) = put set
        get = fmap Contacts_v0 get
    instance SafeCopy Contacts_v0 where
        putCopy (Contacts_v0 list) = contain $ safePut list
        getCopy = contain $ Contacts_v0 <$> safeGet
    
    main :: IO ()
    main = do
        -- 
        -- instance Binary 
        --
        let c' = Contacts[Contact{name="gert",address="home",phone="test"},Contact{name="gert2",address="home2",phone="test2"}]
        let e' = encode c'
        print e'
        let d' = decode e'
        print (d':: Contacts)
    
        let c = Contacts_v0 [("gert_v0","home_v0"),("gert2_v0","home2_v0")]
        let e = encode c
        print e
        let d = decode e
        print (d:: Contacts_v0)
        --can not do print (d:: Contacts) meaning you are screwed
    
        --
        -- instance SafeCopy
        --
        let c'' = Contacts_v0 [("gert_v0","home_v0"),("gert2_v0","home2_v0")]
        let e'' = runPut (safePut c'')
        print e''
        let d'' = runGet safeGet e''
        case d'' of
            Left _ -> print "error"
            Right d'' -> print (d'':: Contacts)
        --can do print (d:: Contacts) or print (d:: Contacts_v0) meaning you are safed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to port classic Perlin Noise (src: http://mrl.nyu.edu/~perlin/doc/oscar.html#noise ) to JavaScript - for
I downloaded apache2.2.22 src from http://httpd.apache.org/download.cgi and made the installation. The installation works fine.
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TextToSpeechActivity.html I was going to add this but how can i add it if
Please download the following code : http://media.pragprog.com/titles/eband3/code/Sudokuv2/src/org/example/sudoku/PuzzleView.java In the code, What initial value does
Reading manual about Sling http://sling.apache.org/site/46-line-blog.html added folder blog and blog.html to destination: \launchpad\content\src\main\resources\content\ but
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
an svn:externals reference like this dojo -r 21434 http://svn.dojotoolkit.org/src/dojo/trunk/ is happily accepted by subversive
I recently installed ruby 1.9.3 and rubygems 1.8.24. Both installed perfectly (src: http://railsapps.github.com/installing-rails.html ).
I have an html page with this script: flashembed(header_container, {src: http://****.swf?__cv=3cfd4cc0ac1fad53803ff73629e93d00, version: [8,0], expressInstall:
Here is an excerpt from my code: xtype: 'image', src: 'http://www.sencha.com/files/blog/old/blog/wp-content/uploads/2010/06/sencha-logo.png', left: '50%', top:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.