Skip to content

Instantly share code, notes, and snippets.

@mxswd
Created April 16, 2014 09:39
Show Gist options
  • Save mxswd/10842271 to your computer and use it in GitHub Desktop.
Save mxswd/10842271 to your computer and use it in GitHub Desktop.
data EL = O (H.HashMap Text EL)
| V EL
| S | N | B | E
| T | U
deriving Show
instance Monoid EL where
mempty = U
U `mappend` U = U
T `mappend` _ = T
_ `mappend` T = T
U `mappend` O m = O m
U `mappend` V x = V x
U `mappend` S = S
U `mappend` N = N
U `mappend` B = B
U `mappend` E = E
O m `mappend` U = O m
V x `mappend` U = V x
S `mappend` U = S
N `mappend` U = N
B `mappend` U = B
E `mappend` U = E
O m `mappend` O n = O (H.unionWith mappend m n)
V x `mappend` V y = V (x `mappend` y)
S `mappend` S = S
N `mappend` N = N
B `mappend` B = B
E `mappend` E = E
_ `mappend` _ = T
to :: Value -> EL
to (Object m) = O (H.map to m)
to (Array v) = V (mconcat (V.toList (V.map to v)))
to (String _) = S
to (Number _) = N
to (Bool _) = B
to Null = E
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment