Ticket #49 (closed enhancement: fixed)

Opened 2 years ago

Last modified 21 months ago

Read instances

Reported by: choener Owned by:
Priority: minor Milestone: 0.8
Version: 0.7 Keywords: Read instance
Cc: choener@…

Description

Hi,

how about Read instances for the library? I like Read/Show a lot for serializing because it costs nothing (cost = my time spent programming that).

Do you want it in the vector library or do you prefer something like "vector-read-instances"? It is a vote because I already have the code for unboxed vectors written. ;-)

{-# LANGUAGE ScopedTypeVariables #-}

-- | Read instance for unboxed vectors.

module Data.Vector.Unboxed.Read where

import qualified Data.Vector.Unboxed as VU
import qualified Text.Read.Lex as L
import GHC.Show
import Text.Read
import Text.ParserCombinators.ReadP

instance (VU.Unbox a, Read a) => Read (VU.Vector a) where
  readPrec =
    parens $ do
        L.Ident "fromList" <- lexP
        (vals :: [a])  <- readPrec
        lift $ skipSpaces
        lift $ string "::"
        lift $ skipSpaces
        lift $ string "Data.Vector.Unboxed.Vector"
        return $ VU.fromList vals
  readListPrec = readListPrecDefault
  readList     = readListDefault

Change History

Changed 2 years ago by choener

Hi,

I needed this public earlier than I expected. I will transfer all the stuff from "vector-read-instances" into a patch in the near future and until then keep the package alive on hackage.

Changed 21 months ago by rl

If you could do this in the next week or so, it would go into 0.8.

Changed 21 months ago by choener

  • cc choener@… added

Changed 21 months ago by rl

  • status changed from new to closed
  • resolution set to fixed

Fri Aug 26 23:04:27 BST 2011 Roman Leshchinskiy <rl@…>

  • Follow containers convention in Show instances and add Read instances
Note: See TracTickets for help on using tickets.