Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created April 10, 2014 19:40
Show Gist options
  • Select an option

  • Save aamedina/10415713 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/10415713 to your computer and use it in GitHub Desktop.
data JSValue = JSString String
| JSNumber Double
| JSBool Bool
| JSNull
| JSObject [(String, JSValue)]
| JSArray [JSValue]
deriving (Eq, Ord, Show)
getString :: JSValue -> Maybe String
getString (JSString str) = Just str
getString _ = Nothing
getInt (JSNumber n) = Just (truncate n)
getInt _ = Nothing
getDouble (JSNumber n) = Just n
getDouble _ = Nothing
getBool (JSBool b) = Just b
getBool _ = Nothing
getObject (JSObject o) = Just o
getObject _ = Nothing
getArray (JSArray a) = Just a
getArray _ = Nothing
isNull v = v == JSNull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment