
Stu White
type Triple = Triple {
data Triple = Triple { -- 'type' is for synonyms, 'data' for user-defined
entry 1 :: a; entry 2 :: a; entry 3 :: a;
entry_1 :: a; -- field names must be a single identifier entry_2 :: a; entry_3 :: a;
sortTriple :: Triple a -> Triple a;
sortTriple :: (Ord a) => Triple a -> Triple a -- an ordering constraint on the 'a' is implied
} deriving (Show, Eq) where
-- You can't have a 'where' clause on a datatype definition. Presumably you -- are trying to express that the 'sortTriple' component is invariant. If -- so, then remove it from the datatype and write it at the toplevel. If -- you rather mean that it has a default definition that can be overridden, -- then you can keep it in the datatype, but you will need to add the default -- functional value to each new Triple you create, perhaps with a 'smart' -- constructor: -- mkTriple x y z = Triple x y z sortTriple
sortTriple t@(Triple x y z) | (y
sortTriple t@(Triple x y z s) -- you omitted the fourth component of the Triple
| (y