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 6964809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:58:16+00:00 2026-05-27T15:58:16+00:00

What is the best way to make type Configuration = Array DIM1 (Double, Double,

  • 0

What is the best way to make

type Configuration = Array DIM1 (Double, Double, Double)

an instance of Read? So later I could derive

data SimulationData = SD Configuration Double StdGen Int

to be an instance of Read too.

  • 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-05-27T15:58:17+00:00Added an answer on May 27, 2026 at 3:58 pm

    Such an instance will be an orphan instance, which you should generally avoid. However, it’s fairly simple to write it:

    {-# LANGUAGE TypeOperators #-}
    
    import Data.Array.Repa (Array, Shape, Elt, Z(..), (:.)(..))
    import qualified Data.Array.Repa as R
    
    instance Read Z where
      readsPrec _ r = do
        ("Z", s) <- lex r
        return (Z, s)
    
    instance (Read tail, Read head) => Read (tail :. head) where
      readsPrec d =
        readParen (d > prec) $ \r -> do
          (tl, s) <- readsPrec (prec + 1) r
          (":.", t) <- lex s
          (hd, u) <- readsPrec (prec + 1) t
          return (tl :. hd, u)
        where prec = 3
    
    instance (Shape sh, Read sh, Elt a, Read a) => Read (Array sh a) where
      readsPrec d =
        readParen (d > app) $ \r -> do
          ("Array", s) <- lex r
          (sh, t) <- readsPrec (app + 1) s
          (xs, u) <- readsPrec (app + 1) t
          return (R.fromList sh xs, u)
        where app = 10
    

    If you use the StandaloneDeriving extension, the first two instances can be simplified:

    deriving instance Read Z
    deriving instance (Read tail, Read head) => Read (tail :. head)
    

    These instances should probably be in repa itself; I just based them on the example instance given in Text.Show and repa’s show output. I suggest making a feature request on repa’s bug tracker, and putting these instances into a module of your program for now (unless you want to avoid orphan instances entirely, in which case you’ll have to solve the problem another way altogether).


    That said, you should probably consider simply converting your data to a list (with toList) and using that; it avoids the orphan instance, and shouldn’t have any downsides. You might also want to consider using a “real” serialisation library like cereal if you’re more interested in processing the data with code than having it be human-readable; Read is generally considered to be of rather limited use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read much about Core Data.. but what is an efficient way to make
What is the best way to make a Delphi application (Delphi 2007 for Win32)
What is the best way to make a <div> fade away after a given
What is the best way to make trailing slashes not matter in the latest
What is the best way to make one of the branches of a subversion
what's the best way to make communications between page widgets residing on differents ViewPart?
What is the best way to make an HTTP GET request in Ruby with
What is the best way to make sure that all the environment variables I
What is the best way to make my Qt Ruby application into an executable
What's the best way to make a function that has pointer as argument work

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.