If a type that could be defined either by `data` or `newtype` (i.e., a single-constructor type) is exported abstractly (without its constructor), can the user of the type tell how the type was declared? Dean
yes.
data D = D Int newtype N = N Int
there is a difference between (N undefined) `seq` () and (D undefined) `seq` () there has been a lot of discussion about this on the mailing list, probably under a title of something like "difference between data and newtype". -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume On Sat, 8 Mar 2003, Dean Herington wrote:
If a type that could be defined either by `data` or `newtype` (i.e., a single-constructor type) is exported abstractly (without its constructor), can the user of the type tell how the type was declared?
Dean
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Hal Daume III wrote: | there is a difference between | | (N undefined) `seq` () | | and | | (D undefined) `seq` () The question stated "without its constructor". My guess is "no". /K
well, yes, but if you export: mkN :: Int -> N mkD :: Int -> D or something like that, then they'll still bea ble to tell the difference, right? -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume On Sun, 9 Mar 2003, Koen Claessen wrote:
Hal Daume III wrote:
| there is a difference between | | (N undefined) `seq` () | | and | | (D undefined) `seq` ()
The question stated "without its constructor". My guess is "no".
/K
On Sun, 9 Mar 2003, Hal Daume III wrote:
well, yes, but if you export:
mkN :: Int -> N mkD :: Int -> D
or something like that, then they'll still bea ble to tell the difference, right?
Well, yes, but I don't. In fact the type in question is an MVar which my abstraction ensures is always defined. My question came up in the context of describing such an abstract type for users of the type. Like many others, I like to include actual Haskell code where appropriate in the documentation. It didn't seem right to commit there to either `data` or `newtype`. Perhaps I'll use: type Foo a -- abstract Does that disturb anyone? Any other ideas? Dean
Dean Herington writes: : | My question came up in the context of describing such an abstract type for | users of the type. Like many others, I like to include actual Haskell | code where appropriate in the documentation. It didn't seem right to | commit there to either `data` or `newtype`. Perhaps I'll use: | | type Foo a -- abstract | | Does that disturb anyone? Any other ideas? That's pretty close to Haddock's approach. For example, see newtype N4 in http://www.haskell.org/haddock/Test.hs : "An abstract newtype - we show this one as data rather than newtype because the difference isn't visible to the programmer for an abstract type."
On 09-Mar-2003, Hal Daume III <hdaume@ISI.EDU> wrote:
well, yes, but if you export:
mkN :: Int -> N mkD :: Int -> D
or something like that, then they'll still bea ble to tell the difference, right?
Not necessarily. For example mkD could be defined as mkD x = x `seq` D x in which case I think it would behave exactly the same as mkN. -- Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit The University of Melbourne | of excellence is a lethal habit" WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
my guess is no too. An informal argument to that: imagine the datatype is abstract and no functions which act on it are exported .call it 'Type'. since there are no non-bottom values of this type that are exported, the only way to create them is with bottom as in: (undefined :: Type) (or an equivalant) which is equivalant for a newtype (N undefined :: Type) and for a data (undefined :: Type) note that there is no way to create the (D undefined) which is what lets you observe the difference. therefore you cannot tell the difference... Just my line of thought which led to saying 'no', interpret it as you will. John On Sun, Mar 09, 2003 at 12:58:49PM +0100, Koen Claessen wrote:
Hal Daume III wrote:
| there is a difference between | | (N undefined) `seq` () | | and | | (D undefined) `seq` ()
The question stated "without its constructor". My guess is "no".
/K
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- --------------------------------------------------------------------------- John Meacham - California Institute of Technology, Alum. - john@foo.net ---------------------------------------------------------------------------
participants (6)
-
Dean Herington -
Fergus Henderson -
Hal Daume III -
John Meacham -
Koen Claessen -
Tom Pledger