https://github.com/xich/scotty/issues/26
https://github.com/xich/scotty/pull/27
class ScottyString a where
toContent :: a -> Content
toText :: a -> T.Text
fromScotty :: T.Text -> a
instance ScottyString B.ByteString where
toContent bs = ContentBuilder (fromByteString bs)
toText bs = toText $ BL.fromChunks [bs]
fromScotty = B.concat . BL.toChunks . fromScotty
instance ScottyString BL.ByteString where
toContent bs = ContentBuilder (fromLazyByteString bs)
toText = decodeUtf8
fromScotty = encodeUtf8
instance ScottyString T.Text where
toContent = toContent . encodeUtf8
toText = id
fromScotty = id
instance ScottyString String where
toContent = toContent . T.pack
toText = T.pack
fromScotty = T.unpack
For me it works fine, but old code is breaked… Because now there is no default type for some functions.
How add default type for this typeclass (for example, Text)?
BTW, I’ve started an almost identical Stringable typeclass on hackage: http://hackage.haskell.org/package/stringable
Written because I got tired of having to remember how to convert everything to each other.