
Say I have the following module: ---------------------------------------- module A ( T(T) , t , val ) where data T = T { t :: Int } val :: T val = T 7 ---------------------------------------- When I use A with the following imports, I don't expect this to work, but it does: import qualified A import A(T(..)) main = putStrLn $ show $ t A.val The problem is that I explicitly didn't export 't' as an element of T (by not writing T(..)). Am I just misunderstanding how exports work? I couldn't figure out what the correct behavior should be by looking at the 98 report. Sean

On Tue, Dec 1, 2009 at 3:11 PM, Sean McLaughlin
Say I have the following module:
---------------------------------------- module A ( T(T) , t , val ) where
data T = T { t :: Int }
val :: T val = T 7 ----------------------------------------
When I use A with the following imports, I don't expect this to work, but it does:
import qualified A import A(T(..))
main = putStrLn $ show $ t A.val
The problem is that I explicitly didn't export 't' as an element of T (by not writing T(..)). Am I just misunderstanding how exports work? I couldn't figure out what the correct behavior should be by looking at the 98 report.
Oh interesting. What a crazy corner case. I also feel like your program shouldn't be valid. Maybe it's a bug?

It looks like it is specified and the intended behavior: From the report, section 5.2: An algebraic datatype T declared by a data or newtype declaration may be named in one of three ways: The form T names the type but not the constructors or field names. The ability to export a type without its constructors allows the construction of abstract datatypes (see Section 5.8). The form T(c1,...,cn), names the type and some or all of its constructors and field names. The abbreviated form T(..) names the type and all its constructors and field names that are currently in scope (whether qualified or not). And then later similarly for imports from 5.3.1: Exactly which entities are to be imported can be specified in one of the following three ways: The imported entities can be specified explicitly by listing them in parentheses. Items in the list have the same form as those in export lists, except qualifiers are not permitted and the `module modid' entity is not permitted. When the(..) form of import is used for a type or class, the (..) refers to all of the constructors, methods, or field names exported from the module. The list must name only entities exported by the imported module. The list may be empty, in which case nothing except the instances is imported. -Ross On Dec 1, 2009, at 5:18 PM, Luke Palmer wrote:
On Tue, Dec 1, 2009 at 3:11 PM, Sean McLaughlin
wrote: Say I have the following module:
---------------------------------------- module A ( T(T) , t , val ) where
data T = T { t :: Int }
val :: T val = T 7 ----------------------------------------
When I use A with the following imports, I don't expect this to work, but it does:
import qualified A import A(T(..))
main = putStrLn $ show $ t A.val
The problem is that I explicitly didn't export 't' as an element of T (by not writing T(..)). Am I just misunderstanding how exports work? I couldn't figure out what the correct behavior should be by looking at the 98 report.
Oh interesting. What a crazy corner case. I also feel like your program shouldn't be valid. Maybe it's a bug? _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Tue, Dec 01, 2009 at 05:11:42PM -0500, Sean McLaughlin wrote:
The problem is that I explicitly didn't export 't' as an element of T (by not writing T(..)). Am I just misunderstanding how exports work? I couldn't figure out what the correct behavior should be by looking at the 98 report.
Exports (and imports) merely enumerate names, not their relationships, so the original export is equivalent to T(T, t) or T(..).
participants (4)
-
Luke Palmer
-
Ross Mellgren
-
Ross Paterson
-
Sean McLaughlin