module Hasmin.Types.Class
( ToText(..)
, Minifiable(..)
) where
import Control.Monad.Reader (Reader, runReader)
import Data.Word (Word8)
import Data.Text (pack, Text)
import Data.Text.Lazy (toStrict)
import Data.Text.Lazy.Builder (Builder, fromText, toLazyText)
import Hasmin.Config
class Minifiable a where
minifyWith :: a -> Reader Config a
minify :: a -> a
minify x = runReader (minifyWith x) defaultConfig
class ToText a where
toText :: a -> Text
toBuilder :: a -> Builder
toText = toStrict . toLazyText . toBuilder
toBuilder = fromText . toText
instance ToText Word8 where
toText = pack . show
instance ToText Int where
toText = pack . show
instance ToText Text where
toText = id
instance (ToText a, ToText b) => ToText (Either a b) where
toText = either toText toText
toBuilder = either toBuilder toBuilder