1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 16:33:03 +03:00

Write a custom Show instance for JSObject.

This commit is contained in:
Rob Rix 2016-02-29 17:33:19 -05:00
parent 466d7d3611
commit e39d728af0

View File

@ -1,5 +1,7 @@
module Text.JSON where
import Data.List
data JSValue
= JSNull
| JSBool !Bool
@ -19,7 +21,11 @@ toJSString :: String -> JSString
toJSString = JSONString
newtype JSObject value = JSONObject { fromJSObject :: [(String, value)] }
deriving (Eq, Show)
deriving (Eq)
instance Show value => Show (JSObject value) where
show (JSONObject pairs) = "{" ++ intercalate "," (showPair <$> pairs) ++ "}"
where showPair (key, value) = show (toJSString key) ++ ":" ++ show value
toJSObject :: [(String, value)] -> JSObject value
toJSObject = JSONObject