read-io: Read IO library

[ library, mit, system ] [ Propose Tags ] [ Report a vulnerability ]

A lightweight library to read and write data types deriving Read and Show.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.0.1
Dependencies base (>=4.9 && <5.0), containers (>=0.5 && <0.6), directory (>=1.2 && <1.3), filepath (>=1.4 && <1.5) [details]
License MIT
Author Firas Zaidan
Maintainer firas@zaidan.de
Category System
Home page https://github.com/zaidan/read-io#readme
Bug tracker https://github.com/zaidan/read-io/issues
Source repo head: git clone https://github.com/zaidan/read-io
Uploaded by zaidan at 2017-02-15T18:35:54Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 857 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-02-15 [all 1 reports]

Readme for read-io-0.0.0.1

[back to package description]

ReadIO - Read IO library

Hackage

A lightweight library to read and write data types deriving Read and Show.

Usage

Defining your data types

Define your data type deriving Read and Show:

data Foo = Foo 
  { id :: Integer,
    name :: String,
    value :: Double,
    nested :: [(String, Bar)]
  }
  deriving (Read, Show, Eq) 

data Bar = Bar 
  { some :: Char
  }
  deriving (Read, Show, Eq) 

Creating your data files

Create some data files you want to read - e. g. data/a.foo:

Foo {
  id = 0,
  name = "a",
  value = 1.5,
  nested = [
    ("key 1", Bar { some = 'a'}),
    ("key 2", Bar { some = 'A'})
  ]
}

and data/b.foo:

Foo {
  id = 1,
  name = "b",
  value = 3.1234567800009,
  nested = [
  ("key 1", Bar { some = 'b'}),
  ("key 2", Bar { some = 'B'})
  ]
}

Read

Use

foo <- System.IO.Read.readFrom "data/a.foo" :: IO Foo

to deserialize it to IO Foo or

foos <- System.IO.Read.readDirectory "data"` :: IO [Foo]

to deserialize all containing files to IO [Foo].

Show

Use

System.IO.Show.showFile foo "data/out.foo"

to serialize foo of type Foo to data/out.foo.

Credits

License

See LICENSE file.