Created
February 13, 2013 11:59
-
-
Save koko-u/4944123 to your computer and use it in GitHub Desktop.
toJSONしか作ってない
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BookmarkUtil ( | |
Bookmark(..), | |
toJSON | |
) where | |
import Data.List | |
data Bookmark = Bookmark { | |
name :: String, | |
url :: String | |
} | Folder { | |
name :: String, | |
children :: [Bookmark] | |
} deriving (Show) | |
toJSON :: Bookmark -> String | |
toJSON (Bookmark name url) = | |
"{ name: \"" ++ name ++ "\", url: \"" ++ url ++ "\" }" | |
toJSON (Folder name bookmarks) = | |
"{name: \"" ++ name ++ "\", children: [" ++ | |
(concat (intersperse ", " (map toJSON bookmarks))) | |
++ "]}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment