RE: [Haskell-cafe] Adding Ord constraint to instance Monad Set?

| "Constraints on datatype declarations are a misfeature of Haskell, and | have no useful effect." |=20 | Is this the final conclusion?
Yes, it is, I believe. Constraints on data type declarations are a mis-feature. I tried to get them removed, but there was some argument that they could be made useful
Might I try and pursuade you that mis-feature is a bit strong. A data type declaration creates two things - the data type itself and the constructor function. If you consider the constrains in the data type declaration to apply only to the constructor then it all makes sense. functions do not infer constrains from enclosed functions, for example: fna :: Num a => a -> a fna a = -a fnb :: a -> a fnb a = fna a In this case fna has a type error, the function is declared without the required Num a constraint. This is the same for data constructors, consider: data Num a => MyList a = MyList [a] This means that the constuctor for mylist has the (Num a) constraint. Simple! This is not a misfeature - more a mis-understood feature. So, using: print $ MyList ['a','b','c'] -- fails: No instance for (Num Char) print $ MyList [1,2,3] -- is Okay. and unexpectedly a use of the constructor does not get the constraint: fnc :: a -> MyList a fnc a = MyList [a] -- fails: Could not deduce (Num a) from the context () But if you consider the constructor to be just like a normal function this is perfectly consistant. This should definitely not be removed, as there is no other way to apply a constaint to a constructor function. Regards, Keean.

On Wed, 31 Mar 2004, MR K P SCHUPKE wrote:
| "Constraints on datatype declarations are a misfeature of Haskell, and | have no useful effect." |=20 | Is this the final conclusion?
Yes, it is, I believe. Constraints on data type declarations are a mis-feature. I tried to get them removed, but there was some argument that they could be made useful
Might I try and pursuade you that mis-feature is a bit strong.
A data type declaration creates two things - the data type itself and the constructor function.
If you consider the constrains in the data type declaration to apply only to the constructor then it all makes sense.
If this is the meaning then in my opinion the syntax is misleading and it should be instead like data Either a b = (Ord a) => Left a | (Num b) => Right b (just a fictive example)

Am Mittwoch, 31. März 2004 13:51 schrieb Henning Thielemann:
[...]
A data type declaration creates two things - the data type itself and the constructor function.
If you consider the constrains in the data type declaration to apply only to the constructor then it all makes sense.
If this is the meaning then in my opinion the syntax is misleading and it should be instead like data Either a b = (Ord a) => Left a
| (Num b) => Right b
(just a fictive example)
This syntax would also have the advantage that you can apply different contexts to different constructors. Wolfgang
participants (3)
-
Henning Thielemann
-
MR K P SCHUPKE
-
Wolfgang Jeltsch