Skip to content

Instantly share code, notes, and snippets.

@robkuz
Created April 26, 2016 15:41
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 robkuz/ac5926237bb731e737f9fe773846e730 to your computer and use it in GitHub Desktop.
Save robkuz/ac5926237bb731e737f9fe773846e730 to your computer and use it in GitHub Desktop.
Why need the full blown type signature?

I have the following value and its signature

type JsonResponse = Affjax.AffjaxResponse Json
getUser :: forall e m. (MonadAff (ajax :: Affjax.AJAX | e) m) => String -> m (Either Error JsonResponse)
getUser user = liftAff $ attempt $ Affjax.get $ "http://someservice.com?user=" ++ user

Now I want to use that in combination with a Maybe. Easy enough just use map (or the alias operator)

applyUser' = getUser <$> Just "Bob"

Only this gives me the following error

82  applyUser = getUser <$> Just "Bob"
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

No type class instance was found for

Control.Monad.Aff.Class.MonadAff ( ajax :: AJAX
                                 | _0
                                 )
                                 _1

The instance head contains unknown type variables. Consider adding a type annotation.

in value declaration getUser'

where _1 is an unknown type
    _0 is an unknown type

Only when I add the signature as

applyUser :: forall e m. (MonadAff (ajax :: Affjax.AJAX | e) m) => Maybe (m (Either Error JsonResponse))

it compiles. I am a bit stunned as really I dont see why the compiler is not able to fully infer all data here

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