Skip to content

Instantly share code, notes, and snippets.

@dzackgarza
Last active August 29, 2015 14:22
Show Gist options
  • Save dzackgarza/db1fdf0ad2c1449a6a64 to your computer and use it in GitHub Desktop.
Save dzackgarza/db1fdf0ad2c1449a6a64 to your computer and use it in GitHub Desktop.
IO/Monad Issues
------------------------------------------------
Version that works:
------------------------------------------------
-- | Resources passed to featureResources in constructor
getVoteResource = (resourceAt "/packages/vote") {
resourceDesc = [(GET, "Get the number of votes a package has.")],
resourceGet = [("json", returnOne)]
}
-- | Trivial json response
returnOne _ = do
isInMap <- fmap(Map.member "c") $ readMemState votesCache
let
arr = if isInMap
then [("inMap", "True")]
else [("inMap", "False")]
ok. toResponse $ toJSON arr
--------------------------------------------------
Version that doesn't work
--------------------------------------------------
-- | Resources passed to featureResources in constructor
getVoteResource = (resourceAt "/packages/vote") {
resourceDesc = [(GET, "Get the number of votes a package has.")],
resourceGet = [("json", returnOne)]
}
-- | Trivial json response
returnOne _ = do
votesMap <- readMemState votesCache
let
arr = if "c" `Map.member` votesMap
then [("inMap", "True")]
else [("inMap", "False")]
ok. toResponse $ toJSON arr
Distribution/Server/Features/Ranking.hs:79:32:
Couldn't match type ‘m0 Response’ with ‘Response’
Expected type: Distribution.Server.Framework.Resource.ServerResponse
Actual type: DynamicPath
-> ServerPartT
(Control.Monad.Trans.Error.ErrorT ErrorResponse IO) (m0 Response)
In the expression: returnOne
In the expression: ("json", returnOne)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment