{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -Wall -Werror #-}
module Siphon.Types
( Siphon(..)
, Indexed(..)
, SiphonError(..)
, RowError(..)
, CellError(..)
) where
import Data.Vector (Vector)
import Control.Exception (Exception)
import Data.Text (Text)
data CellError = CellError
{ cellErrorColumn :: !Int
, cellErrorContent :: !Text
} deriving (Show,Read,Eq)
newtype Indexed a = Indexed
{ indexedIndex :: Int
} deriving (Eq,Ord,Functor,Show,Read)
data SiphonError = SiphonError
{ siphonErrorRow :: !Int
, siphonErrorCause :: !RowError
} deriving (Show,Read,Eq)
instance Exception SiphonError
data RowError
= RowErrorParse
| RowErrorDecode !(Vector CellError)
| RowErrorSize !Int !Int
| RowErrorHeaders !(Vector (Vector CellError)) !(Vector Text) !(Vector Int)
| RowErrorHeaderSize !Int !Int
| RowErrorMalformed !Int
deriving (Show,Read,Eq)
data Siphon f c a where
SiphonPure ::
!a
-> Siphon f c a
SiphonAp ::
!(f c)
-> !(c -> Maybe a)
-> !(Siphon f c (a -> b))
-> Siphon f c b
instance Functor (Siphon f c) where
fmap f (SiphonPure a) = SiphonPure (f a)
fmap f (SiphonAp h c apNext) = SiphonAp h c ((f .) <$> apNext)
instance Applicative (Siphon f c) where
pure = SiphonPure
SiphonPure f <*> y = fmap f y
SiphonAp h c y <*> z = SiphonAp h c (flip <$> y <*> z)