convertible-1.1.1.0: Typeclasses and instances for converting between types

Copyright | Copyright (C) 2009-2011 John Goerzen
License | BSD3
Maintainer | John Goerzen <jgoerzen@complete.org>
Stability | provisional
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Data.Convertible.Base

Contents

- The conversion process
- Handling the results

Description

Synopsis

- convert :: Convertible a b => a -> b
- class Convertible a b where
- type ConvertResult a = Either ConvertError a
- data ConvertError = ConvertError {
  - convSourceValue :: String
  - convSourceType :: String
  - convDestType :: String
  - convErrorMessage :: String
  }
- convError :: (Show a, Typeable a, Typeable b) => String -> a -> ConvertResult b
- prettyConvertError :: ConvertError -> String

# The conversion process

convert :: Convertible a b => a -> b Source #

Convert from one type of data to another. Raises an exception if there is an error with the conversion. For a function that does not raise an exception in that case, see `safeConvert`.

class Convertible a b where Source #

A typeclass that represents something that can be converted. A `Convertible a b` instance represents an `a` that can be converted to a `b`.

Minimal complete definition

safeConvert

Methods

safeConvert :: a -> ConvertResult b Source #

Convert `a` to `b`, returning Right on success and Left on error. For a simpler interface, see `convert`.

# Handling the results

type ConvertResult a = Either ConvertError a Source #

The result of a safe conversion via `safeConvert`.

data ConvertError Source #

How we indicate that there was an error.

Constructors

ConvertError |

Fields

- convSourceValue :: String
- convSourceType :: String
- convDestType :: String
- convErrorMessage :: String

Instances

Eq ConvertError Source # |
Methods (==) :: ConvertError -> ConvertError -> Bool # (/=) :: ConvertError -> ConvertError -> Bool #
Read ConvertError Source # |
Methods readsPrec :: Int -> ReadS ConvertError # readList :: ReadS [ConvertError] # readPrec :: ReadPrec ConvertError # readListPrec :: ReadPrec [ConvertError] #
Show ConvertError Source # |
Methods showsPrec :: Int -> ConvertError -> ShowS # show :: ConvertError -> String # showList :: [ConvertError] -> ShowS #
Error ConvertError Source # |
Methods noMsg :: ConvertError # strMsg :: String -> ConvertError #

convError :: (Show a, Typeable a, Typeable b) => String -> a -> ConvertResult b Source #

prettyConvertError :: ConvertError -> String Source #