Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- newtype A = A Int
- newtype B = B Int
- type Database = String
- type JSON = String
- class ParseDatabase a where parse :: Database -> Maybe a
- instance ParseDatabase A where parse db = A <$> readMaybe s
- instance ParseDatabase B where parse db = B <$> readMaybe s
- class ToJSON a where toJSON :: a -> JSON
- instance ToJSON A where toJSON (A n) = show n
- instance ToJSON B where toJSON (B n) = "{\"this one uses an object, not a bare number\": " ++ show n ++ "}"
- database :: Database
- database = "3"
- -- The thing you are asking for.
- foo :: Database -> Maybe JSON
- foo db = toJSON <$> parse db
- -- Now I ask you: which of these two JSON objects do you expect to get from foo database, and why?
- -- 3
- -- {"this one uses an object, not a bare number": 3}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement