Skip to content

Conversation

@Lysxia
Copy link
Contributor

@Lysxia Lysxia commented Oct 11, 2016

I think this new (=.) allows to create Codecs for records neatly without Template Haskell.

Example:

-- As if    data (,) a b = (,) { fst :: a, snd :: b }

parsePair :: Codec fr fw a -> Codec fr fw b -> Codec fr fw (a, b)
parsePair a b
  = (,)
  <$> fst =. a
  <*> snd =. b

parseFlipped :: Codec fr fw b -> Codec fr fw a -> Codec fr fw (a, b)
parseFlipped b a
  = flip (,)
  <$> snd =. b
  <*> fst =. a

If you agree with this I can try to document it in Data.Codec.

(.=) seems to be the most common choice to map fields in other serialization libraries (JSON, YAML), and I picked the hardly used (=.) to avoid conflicts (assuming that users of Codec might need to use one of these other libraries at the same time).

@Lysxia
Copy link
Contributor Author

Lysxia commented Oct 13, 2016

What do you think of adding a Profunctor instance as well?

@chpatrick chpatrick merged commit 585475a into chpatrick:master Oct 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants