Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'undecidable' into text

Conflicts:
	convertible-text.cabal
  • Loading branch information...
commit 1cc7f9b9aa3285b2def28d1ff9caac13c9806f62 2 parents 61f2c51 + 8c82e64
@snoyberg authored
View
9 Data/Convertible/Base.hs
@@ -1,4 +1,10 @@
{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE OverlappingInstances #-}
+{-# LANGUAGE ExistentialQuantification #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE UndecidableInstances #-}
{-
Copyright (C) 2009 John Goerzen <jgoerzen@complete.org>
@@ -48,6 +54,9 @@ class ConvertAttempt a b => ConvertSuccess a b where
{- | Convert @a@ to @b@. -}
convertSuccess :: a -> b
+instance ConvertSuccess a b => ConvertAttempt a b where
+ convertAttempt = return . convertSuccess
+
{-
{- | Any type can be converted to itself. -}
instance Convertible a a where
View
149 Data/Convertible/Instances/C.hs
@@ -1,3 +1,6 @@
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE TypeSynonymInstances #-}
{- |
Module : Data.Convertible.Instances.C
Copyright : Copyright (C) 2009 John Goerzen
@@ -31,293 +34,197 @@ import Foreign.C.Types
-- Section 1
instance ConvertAttempt CFloat Int where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CFloat Int8 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int8 CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int8 CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CFloat Int16 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int16 CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int16 CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CFloat Int32 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int32 CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int32 CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CFloat Int64 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int64 CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int64 CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CFloat Word where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CFloat Word8 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word8 CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word8 CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CFloat Word16 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word16 CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word16 CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CFloat Word32 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word32 CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word32 CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CFloat Word64 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word64 CFloat where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word64 CFloat where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Int where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Int8 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int8 CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int8 CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Int16 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int16 CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int16 CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Int32 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int32 CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int32 CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Int64 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int64 CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int64 CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Word where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Word8 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word8 CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word8 CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Word16 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word16 CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word16 CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Word32 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word32 CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word32 CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CDouble Word64 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word64 CDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word64 CDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Int where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int CLDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Int8 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int8 CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int8 CLDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Int16 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int16 CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int16 CLDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Int32 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int32 CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int32 CLDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Int64 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Int64 CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Int64 CLDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Word where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word CLDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Word8 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word8 CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word8 CLDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Word16 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word16 CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word16 CLDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Word32 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word32 CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word32 CLDouble where
convertSuccess= fromIntegral
instance ConvertAttempt CLDouble Word64 where
convertAttempt = boundedConversion (return . truncate)
-instance ConvertAttempt Word64 CLDouble where
- convertAttempt= return . fromIntegral
instance ConvertSuccess Word64 CLDouble where
convertSuccess= fromIntegral
-- Section 2
-instance ConvertAttempt CFloat Double where
- convertAttempt = return . realToFrac
instance ConvertSuccess CFloat Double where
convertSuccess = realToFrac
-instance ConvertAttempt Double CFloat where
- convertAttempt = return . realToFrac
instance ConvertSuccess Double CFloat where
convertSuccess = realToFrac
-instance ConvertAttempt CFloat Float where
- convertAttempt = return . realToFrac
instance ConvertSuccess CFloat Float where
convertSuccess = realToFrac
-instance ConvertAttempt Float CFloat where
- convertAttempt = return . realToFrac
instance ConvertSuccess Float CFloat where
convertSuccess = realToFrac
-instance ConvertAttempt CFloat Rational where
- convertAttempt = return . realToFrac
instance ConvertSuccess CFloat Rational where
convertSuccess = realToFrac
-instance ConvertAttempt Rational CFloat where
- convertAttempt = return . realToFrac
instance ConvertSuccess Rational CFloat where
convertSuccess = realToFrac
-instance ConvertAttempt CDouble Double where
- convertAttempt = return . realToFrac
instance ConvertSuccess CDouble Double where
convertSuccess = realToFrac
-instance ConvertAttempt Double CDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess Double CDouble where
convertSuccess = realToFrac
-instance ConvertAttempt CDouble Float where
- convertAttempt = return . realToFrac
instance ConvertSuccess CDouble Float where
convertSuccess = realToFrac
-instance ConvertAttempt Float CDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess Float CDouble where
convertSuccess = realToFrac
-instance ConvertAttempt CDouble Rational where
- convertAttempt = return . realToFrac
instance ConvertSuccess CDouble Rational where
convertSuccess = realToFrac
-instance ConvertAttempt Rational CDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess Rational CDouble where
convertSuccess = realToFrac
-instance ConvertAttempt CLDouble Double where
- convertAttempt = return . realToFrac
instance ConvertSuccess CLDouble Double where
convertSuccess = realToFrac
-instance ConvertAttempt Double CLDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess Double CLDouble where
convertSuccess = realToFrac
-instance ConvertAttempt CLDouble Float where
- convertAttempt = return . realToFrac
instance ConvertSuccess CLDouble Float where
convertSuccess = realToFrac
-instance ConvertAttempt Float CLDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess Float CLDouble where
convertSuccess = realToFrac
-instance ConvertAttempt CLDouble Rational where
- convertAttempt = return . realToFrac
instance ConvertSuccess CLDouble Rational where
convertSuccess = realToFrac
-instance ConvertAttempt Rational CLDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess Rational CLDouble where
convertSuccess = realToFrac
@@ -1442,151 +1349,101 @@ instance ConvertAttempt CULLong CLLong where
convertAttempt = boundedConversion (return . fromIntegral)
-- Section 5
-instance ConvertAttempt CFloat CDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess CFloat CDouble where
convertSuccess = realToFrac
-instance ConvertAttempt CFloat CLDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess CFloat CLDouble where
convertSuccess = realToFrac
-instance ConvertAttempt CDouble CFloat where
- convertAttempt = return . realToFrac
instance ConvertSuccess CDouble CFloat where
convertSuccess = realToFrac
-instance ConvertAttempt CDouble CLDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess CDouble CLDouble where
convertSuccess = realToFrac
-instance ConvertAttempt CLDouble CFloat where
- convertAttempt = return . realToFrac
instance ConvertSuccess CLDouble CFloat where
convertSuccess = realToFrac
-instance ConvertAttempt CLDouble CDouble where
- convertAttempt = return . realToFrac
instance ConvertSuccess CLDouble CDouble where
convertSuccess = realToFrac
-- Section 6
-instance ConvertAttempt CFloat Integer where
- convertAttempt = return . truncate
instance ConvertSuccess CFloat Integer where
convertSuccess = truncate
-instance ConvertAttempt Integer CFloat where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Integer CFloat where
convertSuccess = fromIntegral
-instance ConvertAttempt CDouble Integer where
- convertAttempt = return . truncate
instance ConvertSuccess CDouble Integer where
convertSuccess = truncate
-instance ConvertAttempt Integer CDouble where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Integer CDouble where
convertSuccess = fromIntegral
-instance ConvertAttempt CLDouble Integer where
- convertAttempt = return . truncate
instance ConvertSuccess CLDouble Integer where
convertSuccess = truncate
-instance ConvertAttempt Integer CLDouble where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Integer CLDouble where
convertSuccess = fromIntegral
-- Section 7
-instance ConvertAttempt CChar Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CChar Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CChar where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CSChar Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CSChar Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CSChar where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CUChar Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CUChar Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CUChar where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CShort Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CShort Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CShort where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CUShort Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CUShort Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CUShort where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CInt Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CInt Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CInt where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CUInt Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CUInt Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CUInt where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CLong Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CLong Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CLong where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CULong Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CULong Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CULong where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CSize Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CSize Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CSize where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CWchar Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CWchar Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CWchar where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CLLong Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CLLong Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CLLong where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt CULLong Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess CULLong Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer CULLong where
View
6 Data/Convertible/Instances/Map.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
{- |
Module : Data.Convertible.Instances.Map
Copyright : Copyright (C) 2009 John Goerzen
@@ -26,10 +28,6 @@ import qualified Data.Map as Map
instance Ord k => ConvertSuccess [(k, a)] (Map.Map k a) where
convertSuccess = Map.fromList
-instance Ord k => ConvertAttempt [(k, a)] (Map.Map k a) where
- convertAttempt = return . convertSuccess
instance ConvertSuccess (Map.Map k a) [(k, a)] where
convertSuccess = Map.toList
-instance ConvertAttempt (Map.Map k a) [(k, a)] where
- convertAttempt = return . convertSuccess
View
111 Data/Convertible/Instances/Num.hs
@@ -1,3 +1,6 @@
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE TypeSynonymInstances #-}
{- |
Module : Data.Convertible.Instances.Num
Copyright : Copyright (C) 2009 John Goerzen
@@ -43,13 +46,9 @@ import Data.Word
instance ConvertSuccess Integer Integer where
convertSuccess = id
-instance ConvertAttempt Integer Integer where
- convertAttempt = return
instance ConvertSuccess Char Integer where
convertSuccess = fromIntegral . fromEnum
-instance ConvertAttempt Char Integer where
- convertAttempt = return . convertSuccess
{- The following instances generated by util/genNumInstances.hs
@@ -57,71 +56,51 @@ instance ConvertAttempt Char Integer where
instance ConvertAttempt Integer Int where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Int Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Int Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer Int8 where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Int8 Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Int8 Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer Int16 where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Int16 Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Int16 Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer Int32 where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Int32 Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Int32 Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer Int64 where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Int64 Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Int64 Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer Word where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Word Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Word Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer Word8 where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Word8 Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Word8 Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer Word16 where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Word16 Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Word16 Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer Word32 where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Word32 Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Word32 Integer where
convertSuccess = fromIntegral
instance ConvertAttempt Integer Word64 where
convertAttempt = boundedConversion (return . fromIntegral)
-instance ConvertAttempt Word64 Integer where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Word64 Integer where
convertSuccess = fromIntegral
@@ -397,270 +376,186 @@ instance ConvertAttempt Word64 Word32 where
instance ConvertSuccess Integer Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Integer Double where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Double Integer where
convertSuccess = truncate
-instance ConvertAttempt Double Integer where
- convertAttempt = return . truncate
instance ConvertSuccess Integer Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Integer Float where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Float Integer where
convertSuccess = truncate
-instance ConvertAttempt Float Integer where
- convertAttempt = return . truncate
instance ConvertSuccess Integer Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Integer Rational where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Rational Integer where
convertSuccess = truncate
-instance ConvertAttempt Rational Integer where
- convertAttempt = return . truncate
instance ConvertAttempt Double Int where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Int Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Double Int8 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int8 Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Int8 Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Double Int16 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int16 Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Int16 Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Double Int32 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int32 Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Int32 Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Double Int64 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int64 Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Int64 Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Double Word where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Word Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Double Word8 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word8 Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Word8 Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Double Word16 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word16 Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Word16 Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Double Word32 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word32 Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Word32 Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Double Word64 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word64 Double where
convertSuccess = fromIntegral
-instance ConvertAttempt Word64 Double where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Int where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Int Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Int8 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int8 Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Int8 Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Int16 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int16 Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Int16 Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Int32 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int32 Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Int32 Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Int64 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int64 Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Int64 Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Word where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Word Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Word8 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word8 Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Word8 Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Word16 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word16 Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Word16 Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Word32 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word32 Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Word32 Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Float Word64 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word64 Float where
convertSuccess = fromIntegral
-instance ConvertAttempt Word64 Float where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Int where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Int Rational where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Int8 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int8 Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Int8 Rational where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Int16 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int16 Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Int16 Rational where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Int32 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int32 Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Int32 Rational where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Int64 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Int64 Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Int64 Rational where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Word where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Word Rational where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Word8 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word8 Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Word8 Rational where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Word16 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word16 Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Word16 Rational where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Word32 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word32 Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Word32 Rational where
- convertAttempt = return . fromIntegral
instance ConvertAttempt Rational Word64 where
convertAttempt = boundedConversion (return . truncate)
instance ConvertSuccess Word64 Rational where
convertSuccess = fromIntegral
-instance ConvertAttempt Word64 Rational where
- convertAttempt = return . fromIntegral
instance ConvertSuccess Double Float where
convertSuccess = realToFrac
-instance ConvertAttempt Double Float where
- convertAttempt = return . realToFrac
instance ConvertSuccess Double Rational where
convertSuccess = toRational
-instance ConvertAttempt Double Rational where
- convertAttempt = return . toRational
instance ConvertSuccess Float Double where
convertSuccess = realToFrac
-instance ConvertAttempt Float Double where
- convertAttempt = return . realToFrac
instance ConvertSuccess Float Rational where
convertSuccess = toRational
-instance ConvertAttempt Float Rational where
- convertAttempt = return . toRational
instance ConvertSuccess Rational Double where
convertSuccess = realToFrac
-instance ConvertAttempt Rational Double where
- convertAttempt = return . realToFrac
instance ConvertSuccess Rational Float where
convertSuccess = realToFrac
-instance ConvertAttempt Rational Float where
- convertAttempt = return . realToFrac
instance ConvertAttempt Char Int where
convertAttempt = boundedConversion (return . fromIntegral . fromEnum)
View
16 Data/Convertible/Instances/Time.hs
@@ -1,3 +1,6 @@
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE TypeSynonymInstances #-}
{- |
Module : Data.ConvertAttempt.Instances.Time
Copyright : Copyright (C) 2009 John Goerzen
@@ -189,9 +192,6 @@ instance ConvertAttempt LocalTime TimeOfDay where
----------------------------------------------------------------------
-- Conversions between old and new time
----------------------------------------------------------------------
-instance ConvertAttempt ST.CalendarTime ZonedTime where
- convertAttempt = return . convertSuccess
-
instance ConvertSuccess ST.CalendarTime ZonedTime where
convertSuccess ct = ZonedTime {
zonedTimeToLocalTime = LocalTime {
@@ -221,8 +221,6 @@ instance ConvertAttempt ST.CalendarTime POSIXTime where
instance ConvertAttempt ST.CalendarTime UTCTime where
convertAttempt = convertAttemptVia (undefined::POSIXTime)
-instance ConvertAttempt ST.ClockTime POSIXTime where
- convertAttempt = return . convertSuccess
instance ConvertSuccess ST.ClockTime POSIXTime where
convertSuccess (ST.TOD x y) = fromRational $
fromInteger x + fromRational (y % 1000000000000)
@@ -241,8 +239,6 @@ instance ConvertAttempt ST.ClockTime ZonedTime where
instance ConvertAttempt ZonedTime ST.ClockTime where
convertAttempt = convertAttemptVia (undefined::POSIXTime)
-instance ConvertAttempt POSIXTime ST.ClockTime where
- convertAttempt = return . convertSuccess
instance ConvertSuccess POSIXTime ST.ClockTime where
convertSuccess x = ST.TOD rsecs rpico
where rsecs = floor x
@@ -253,8 +249,6 @@ instance ConvertSuccess UTCTime ST.ClockTime where
instance ConvertAttempt UTCTime ST.ClockTime where
convertAttempt = convertAttempt . utcTimeToPOSIXSeconds
-instance ConvertAttempt ZonedTime ST.CalendarTime where
- convertAttempt = return . convertSuccess
instance ConvertSuccess ZonedTime ST.CalendarTime where
convertSuccess zt = ST.CalendarTime {
ST.ctYear = fromIntegral year,
@@ -286,8 +280,6 @@ instance ConvertAttempt POSIXTime ST.CalendarTime where
instance ConvertAttempt UTCTime ST.CalendarTime where
convertAttempt = convertAttempt . utcTimeToPOSIXSeconds
-instance ConvertAttempt ST.TimeDiff NominalDiffTime where
- convertAttempt = return . convertSuccess
instance ConvertSuccess ST.TimeDiff NominalDiffTime where
{- This is a clever hack. We convert the TimeDiff to a ClockTime, applying
it as a diff vs. the epoch. Converting this ClockTime to a POSIXTime yiels
@@ -295,8 +287,6 @@ instance ConvertSuccess ST.TimeDiff NominalDiffTime where
epoch. -}
convertSuccess td = convertSuccess clockTime
where clockTime = ST.addToClockTime td (ST.TOD 0 0)
-instance ConvertAttempt NominalDiffTime ST.TimeDiff where
- convertAttempt = return . convertSuccess
instance ConvertSuccess NominalDiffTime ST.TimeDiff where
{- Similar clever hack as above. -}
convertSuccess ndt =
View
1  Data/Convertible/Utils.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE FlexibleContexts #-}
{-
Copyright (C) 2009 John Goerzen <jgoerzen@complete.org>
View
7 convertible-text.cabal
@@ -67,13 +67,6 @@ library
Data.Convertible.Instances.Time,
Data.Convertible.Instances.Text,
Data.Convertible.Instances.String
-
- --Other-Modules: Database.HDBC.Utils
- --Extensions: ExistentialQuantification, AllowOverlappingInstances,
- -- AllowUndecidableInstances
- Extensions: ExistentialQuantification, MultiParamTypeClasses,
- UndecidableInstances, FlexibleInstances,
- FlexibleContexts, TypeSynonymInstances, CPP
Executable runtests
if flag(buildtests)
View
16 utils/genCinstances.hs
@@ -8,25 +8,17 @@ hsfloat = ["Double", "Float", "Rational"]
printFP (f, i) =
"instance ConvertAttempt " ++ f ++ " " ++ i ++ " where \n\
\ convertAttempt = boundedConversion (return . truncate)\n\
- \instance ConvertAttempt " ++ i ++ " " ++ f ++ " where \n\
- \ convertAttempt= return . fromIntegral\n\
\instance ConvertSuccess " ++ i ++ " " ++ f ++ " where \n\
\ convertSuccess= fromIntegral\n"
printIntegerF f =
- "instance ConvertAttempt " ++ f ++ " Integer where\n\
- \ convertAttempt = return . truncate\n\
- \instance ConvertSuccess " ++ f ++ " Integer where\n\
+ "instance ConvertSuccess " ++ f ++ " Integer where\n\
\ convertSuccess = truncate\n\
- \instance ConvertAttempt Integer " ++ f ++ " where\n\
- \ convertAttempt = return . fromIntegral\n\
\instance ConvertSuccess Integer " ++ f ++ " where\n\
\ convertSuccess = fromIntegral\n"
printIntegerI i =
- "instance ConvertAttempt " ++ i ++ " Integer where\n\
- \ convertAttempt = return . fromIntegral\n\
- \instance ConvertSuccess " ++ i ++ " Integer where\n\
+ "instance ConvertSuccess " ++ i ++ " Integer where\n\
\ convertSuccess = fromIntegral\n\
\instance ConvertAttempt Integer " ++ i ++ " where\n\
\ convertAttempt = boundedConversion (return . fromIntegral)\n"
@@ -38,9 +30,7 @@ printCharI i =
\ convertAttempt = boundedConversion (return . fromIntegral . fromEnum)\n"
printFP1 (f1, f2) =
- "instance ConvertAttempt " ++ f1 ++ " " ++ f2 ++ " where\n\
- \ convertAttempt = return . realToFrac\n\
- \instance ConvertSuccess " ++ f1 ++ " " ++ f2 ++ " where\n\
+ "instance ConvertSuccess " ++ f1 ++ " " ++ f2 ++ " where\n\
\ convertSuccess = realToFrac\n"
printFPFP (f1, f2) = printFP1 (f1, f2) ++ printFP1 (f2, f1)
View
16 utils/genNumInstances.hs
@@ -20,8 +20,6 @@ showIntToInteger :: String -> String
showIntToInteger i =
"instance ConvertAttempt Integer " ++ i ++ " where\n\
\ convertAttempt = boundedConversion (return . fromIntegral)\n\
- \instance ConvertAttempt " ++ i ++ " Integer where\n\
- \ convertAttempt = return . fromIntegral\n\
\instance ConvertSuccess " ++ i ++ " Integer where\n\
\ convertSuccess = fromIntegral\n"
@@ -36,9 +34,7 @@ showFloatToInt (f, i) =
"instance ConvertAttempt " ++ f ++ " " ++ i ++ " where\n\
\ convertAttempt = boundedConversion (return . truncate)\n\
\instance ConvertSuccess " ++ i ++ " " ++ f ++ " where\n\
- \ convertSuccess = fromIntegral\n\
- \instance ConvertAttempt " ++ i ++ " " ++ f ++ " where\n\
- \ convertAttempt = return . fromIntegral\n"
+ \ convertSuccess = fromIntegral\n"
floatToFloatWork :: [(String, String)]
floatToFloatWork = do
@@ -50,9 +46,7 @@ floatToFloatWork = do
showFloatToFloat :: (String, String) -> String
showFloatToFloat (src, dst) =
"instance ConvertSuccess " ++ src ++ " " ++ dst ++ " where\n\
- \ convertSuccess = " ++ convertFunc ++ "\n\
- \instance ConvertAttempt " ++ src ++ " " ++ dst ++ " where\n\
- \ convertAttempt = return . " ++ convertFunc ++ "\n"
+ \ convertSuccess = " ++ convertFunc ++ "\n"
where
convertFunc
| dst == "Rational" = "toRational"
@@ -61,12 +55,8 @@ showFloatToFloat (src, dst) =
showFloatToInteger f =
"instance ConvertSuccess Integer " ++ f ++ " where\n\
\ convertSuccess = fromIntegral\n\
- \instance ConvertAttempt Integer " ++ f ++ " where\n\
- \ convertAttempt = return . fromIntegral\n\
\instance ConvertSuccess " ++ f ++ " Integer where\n\
- \ convertSuccess = truncate\n\
- \instance ConvertAttempt " ++ f ++ " Integer where\n\
- \ convertAttempt = return . truncate\n"
+ \ convertSuccess = truncate\n"
showIntToChar i =
"instance ConvertAttempt Char " ++ i ++ " where\n\
Please sign in to comment.
Something went wrong with that request. Please try again.