Last active
August 29, 2015 14:22
-
-
Save dzackgarza/db1fdf0ad2c1449a6a64 to your computer and use it in GitHub Desktop.
IO/Monad Issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------ | |
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