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
对我来说它工作得很好,但是旧代码被破坏了......因为现在某些函数没有默认类型。
如何为此类型类添加默认类型(例如Text)?