module Frames.ColumnTypeable where
import Control.Monad (MonadPlus)
import Data.Readable (Readable(fromText))
import qualified Data.Text as T
import Language.Haskell.TH
data Parsed a = Possibly a | Definitely a deriving (Eq, Ord, Show)
instance Functor Parsed where
fmap f (Possibly x) = Possibly (f x)
fmap f (Definitely x) = Definitely (f x)
class Parseable a where
parse :: MonadPlus m => T.Text -> m (Parsed a)
default parse :: (Readable a, MonadPlus m)
=> T.Text -> m (Parsed a)
parse = fmap Definitely . fromText
discardConfidence :: Parsed a -> a
discardConfidence (Possibly x) = x
discardConfidence (Definitely x) = x
parse' :: (MonadPlus m, Parseable a) => T.Text -> m a
parse' = fmap discardConfidence . parse
instance Parseable Bool where
instance Parseable Int where
instance Parseable Float where
instance Parseable Double where
parse = fmap Definitely . fromText . T.filter (/= ',')
instance Parseable T.Text where
class ColumnTypeable a where
colType :: a -> Q Type
inferType :: T.Text -> a