Skip to content

Instantly share code, notes, and snippets.

@funrep
Created December 23, 2013 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funrep/8097890 to your computer and use it in GitHub Desktop.
Save funrep/8097890 to your computer and use it in GitHub Desktop.
import Data.IntMap (IntMap)
import qualified Data.IntMap as IM
import qualified Data.HashMap.Strict as HM
import Data.Aeson
transformIM :: ToJSON a => IntMap a -> Object
transformIM = HM.map toJSON . HM.fromList . convertKeys . IM.toList
where convertKeys = map (\(k, v) -> (T.pack $ show k, v))
@funrep
Copy link
Author

funrep commented Dec 23, 2013

    Couldn't match type `HM.HashMap Text Value'
                  with `unordered-containers-0.2.3.1:Data.HashMap.Base.HashMap
                          Text Value'
    Expected type: HM.HashMap Text a -> Object
      Actual type: HM.HashMap Text a -> HM.HashMap Text Value
    In the return type of a call of `HM.map'
    In the first argument of `(.)', namely `HM.map toJSON'
    In the expression:
      HM.map toJSON . HM.fromList . convertKeys . IM.toList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment