Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: What does the warning "Variable is implicitly quantified due to a context" mean?

At this line

type SafeReturn a = Exception e => Either e a

I got this warning

Variable ‘e’ is implicitly quantified due to a context
Use explicit forall syntax instead.

What does it mean?

like image 675
sqd Avatar asked Dec 24 '22 07:12

sqd


1 Answers

You have a free type variable in your type synonym which you haven't dealt with. To take the extreme example, if we removed your a parameter, we'd have something like

type SafeReturn = [e] -- Using a * -> * type instead of a * -> * -> * type

This probably isn't what you want since we don't know know exactly what e is referring to here and this is the same problem that your SafeReturn faces; what does the e mean?

Now there is one context where e could mean something and that's what the error message is telling you.

type SafeReturn a = forall e. Exception e => Either e a

This means something different. In fact you've created a universally quantified type here. This means that anything of type SafeReturn a has no way of inspecting e other than whatever methods are offered by Exception.

like image 107
badcook Avatar answered May 30 '23 01:05

badcook