1

There is the following snippet of code in the Aeson package usage example:

data Coord = Coord { x :: Double, y :: Double }

instance FromJSON Coord where
  parseJSON (Object v) = Coord    <$>
                         v .: "x" <*>
                         v .: "y"

The type of parseJSON function is parseJSON :: Value -> Parser a. I have the following question about this code: what is the .: function? From the example I might say that its type is Object -> String -> Parser String, however I can't find anything about it on hoogle/hackage. Any help would be appreciated!

2
  • 2
    The index linked to at the top of documentation pages often helps in such cases. Commented Aug 1, 2015 at 14:13
  • @duplode Thanks a lot, that basically answers the question. Commented Aug 1, 2015 at 14:15

1 Answer 1

2

It retrieves the value associated with the key. (.:) produces a parse failure (via empty from Alternative) if the key isn't there, so it is suitable for mandatory keys (as opposed to (.:?), which makes sense for optional ones).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.