Skip to content

Instantly share code, notes, and snippets.

@feighter09
Last active May 4, 2016 04:46
Show Gist options
  • Save feighter09/be2afa1fb6cb810f9e1c24d79882caf8 to your computer and use it in GitHub Desktop.
Save feighter09/be2afa1fb6cb810f9e1c24d79882caf8 to your computer and use it in GitHub Desktop.
-- original
getBody :: ServerPart L.ByteString
parseBody :: FromJSON a => ServerPart (Maybe a)
parseBody = getBody >>= (return . A.decode)
-- attempt
parseBody :: FromJSON a => MaybeT (ServerPartT IO) a
parseBody = lift $ getBody >>= (return . A.decode)
-- Error
-- Couldn't match type ‘a’ with ‘Maybe a0’
-- ‘a’ is a rigid type variable bound by
-- the type signature for
-- parseBody :: FromJSON a => MaybeT (ServerPartT IO) a
-- at src/Main.hs:65:14
-- Expected type: L.ByteString -> a
-- Actual type: L.ByteString -> Maybe a0
-- Relevant bindings include
-- parseBody :: MaybeT (ServerPartT IO) a (bound at src/Main.hs:66:1)
-- In the second argument of ‘(.)’, namely ‘decode’
-- In the second argument of ‘(>>=)’, namely ‘(return . decode)’
-- So Maybe a0 doesn't match FromJSON a, that I get, but I was trying to use MaybeT (ServerPartT IO) a
-- as a replacement for ServerPartT IO (Maybe a), so there's something I'm not quite understanding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment