{-# LANGUAGE Safe #-}
module Hasmin.Class
( ToText(..)
, Minifiable(..)
) where
import Control.Monad.Reader (Reader)
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
{-# MINIMAL minify #-}
minify :: a -> Reader Config a
class ToText a where
{-# MINIMAL toText | toBuilder #-}
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