You may need to study skolems / rank-N types. The exact scope of the "IO" is inside the Wrapper, and nowhere else; so using it in let at all allows it to be visible outside its scope. With the case expression, it can be visible anywhere in the case alternative that pattern matches the Wrapper without it necessarily escaping the scope (you could explicitly leak it, but it will raise the same error about it escaping in that case).

GADTs are a way to get this same case matchung behavior, but it still doesn't help you with this; you are asking that the compiler ignore the rank of the type variable and make it visible outside its scope so that you can use let instead of case, and ghc will not let you do this.

On Wed, Jul 10, 2019 at 11:57 AM Lana Black <lanablack@amok.cc> wrote:
A followup question. What is the reason case and let expressions are
treated differently in this case? I can see the error message saying
about the type variable escaping its scope, but I don't understand how
exactly this can happen with let.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


--
brandon s allbery kf8nh
allbery.b@gmail.com