Hmm .. #haskell folx ... I'm tinkering with Haskell and Yesod and don't quite ge...
Mara Saphira, crush of too many :therian: - 40c3 @littlefox@gotosocial-dev.svc.0x0a.network
Hmm .. #haskell folx ...
I'm tinkering with Haskell and Yesod and don't quite get this:
>>= is supposed to be Maybe a -> (a -> Maybe b) -> Maybe b
and in GHCi with Maybe Int it seems to do that:
ghci> a :: Maybe Int = Just 42
ghci> a >>= (\ x -> Just $ show x)
Just "42"
but in my yesod code, this fails:
maybeAuthId :: Handler (Maybe (Key User))
maybeAuthId = do
muid <- lookupSession "uid"
return $ fromPathPiece $ fromMaybe "" muid
maybeAuthUser :: Handler (Maybe User)
maybeAuthUser = maybeAuthId >>= (\ muid -> runDB $ get muid)
error:
• Couldn't match expected type: Key User
with actual type: Maybe (Key User)
• In the first argument of ‘get’, namely ‘muid’
In the second argument of ‘($)’, namely ‘get muid’
In the expression: runDB $ get muid
|
172 | maybeAuthUser = maybeAuthId >>= (\ muid -> runDB $ get muid)
| ^^^^
(ignore that those functions are usually in Yesod.Auth - I need a bit more flexibility)