on 0802221 help sign in
45 lines 809 B history raw
1{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE TypeSynonymInstances #-}
4module Servant.Utils.Text where
6import Data.String.Conversions
7import Data.Text
8import Text.Read
10class FromText a where
11 fromText :: Text -> Maybe a
13class ToText a where
14 toText :: a -> Text
17instance FromText Text where
18 fromText = Just
20instance ToText Text where
21 toText = id
24instance FromText String where
25 fromText = Just . cs
27instance ToText String where
28 toText = cs
31instance FromText Bool where
32 fromText "true" = Just True
33 fromText "false" = Just False
34 fromText _ = Nothing
36instance ToText Bool where
37 toText True = "true"
38 toText False = "false"
41instance FromText Integer where
42 fromText = readMaybe . cs
44instance ToText Integer where
45 toText = cs . show