Skip to content

Read instance for NominalDiffTime #130

@MaxGabriel

Description

@MaxGabriel

Hi, I'd like to propose adding a Read instance for NominalDiffTime.

My specific use case

I was recently working on adding configurable idle timeouts to the Persistent database library, which uses resource-pool under the hood, which uses a NominalDiffTime for describing how long to let an idle resource sit around before disposing of it.

Unfortunately, the configuration type in the Persistent codebase derived Read, so adding a NominalDiffTime field to it caused issues because NominalDiffTime does not have a Read instance. I can workaround this by e.g. having an Integer field that I convert to a NominalDiffTime, it's just slightly less nice.

To be honest, I try to avoid Read as much as I can, and I don't really think the Persistent type needs a Read instance. That said, Read is a pretty foundational typeclass in Haskell, and time is a pretty foundational package, so it would be nice if its types had Read instances.

Implementation

The type already has a Show instance implemented like this:

instance Show NominalDiffTime where
    show (MkNominalDiffTime t) = (showFixed True t) ++ "s"

It doesn't look like there is an analogous function to showFixed for reading, which might make implementing a Read instance annoying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions