Haskell: ScopedTypeVariables needed in pattern matching type annotations -


why code require scopedtypevariables extension?

{-# language scopedtypevariables #-}  char = case '3' of      (x :: char) -> x     nothing          -> '?' 

when read documentation on scopedtypevariables, seems mean unifying type variables in function body parent function signature. code snippet isn't unifying type variables though!

also effect of loading scopedtypevariables without loading explicitforall? other usecases of scopedtypevariables seem require explicitforall work. in above snippet, there's no explicitforall.

scopedtypevariables enables explicitforall automatically sake of sanity suggest using scopedtypevariables when using other type system extensions (except possibly ones dealing classes/instances/contexts) , never using explicitforall directly.

the reason scopedtypevariables required pattern variable signatures such signatures part of extension. among other uses, give way bring type variable scope. example:

f (just (x::a)) = bob       bob::[a]     bob = [x] 

i not know why pattern signatures part of scopedtypevariables, per se; created purpose, , code written in 1 go. teasing them apart make orthogonal extensions considered more trouble worth.

edit

actually, there's pretty reason. exception of pattern bindings, type variable in pattern signature generalized, bringing variable scope. in above example, don't need know if there a in outer type environment. if enable pattern signatures without scoped type variables, variable generalized or not depending on whether scoped type variables turned on or not. same sort of confusion happens explicitforall without scopedtypevariables, why i'd kill extension , make scopedtypevariables default, or @ least turn on automatically extensions enable explicitforall.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -