Created
October 20, 2017 16:44
-
-
Save mlopes/a79a50ca2355cc21998d0f0c075c0b50 to your computer and use it in GitHub Desktop.
This file contains 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
import Data.Text (Text) | |
import qualified Data.Yaml as Y | |
import Data.Yaml (FromJSON(..), (.:)) | |
import Data.ByteString (ByteString) | |
import Text.RawString.QQ | |
import Control.Applicative | |
actionsYml :: ByteString | |
actionsYml = [r| | |
action: | |
- description: some description | |
- project: inbox | |
- contexts: [ online, computer ] | |
|] | |
data Action = | |
Action { | |
description :: Text | |
, project :: Text | |
, contexts :: [Text] | |
} deriving (Eq, Show) | |
instance FromJSON Action where | |
parseJSON (Y.Object v) = | |
Action <$> | |
v .: "description" <*> | |
v .: "project" <*> | |
v .: "contexts" | |
parseJSON _ = fail "Expected Object for Action value" | |
data Actions = | |
Actions { | |
action :: [Action] | |
} deriving (Eq, Show) | |
instance FromJSON Actions where | |
parseJSON (Y.Object v) = | |
Actions <$> | |
v .: "action" | |
parseJSON _ = fail "Expected Object for Actions value" | |
main :: IO () | |
main = | |
print $ (Y.decode actionsYml :: Maybe(Actions)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment