[Haskell-cafe] Beginner problems with 'triple' code

Henning Thielemann iakd0 at clusterf.urz.uni-halle.de
Mon Jul 26 13:30:29 EDT 2004

On Mon, 26 Jul 2004, Stu White wrote:

> As part of a project, I'm trying to construct a data type that can
> represent three values as a 'triple' (as opposed to a 'tuple'), and then
> make a function so that I can sort these values into ascending ord er.

Since sorting requires equal types of the triple elements you wouldn't
loose generality if you use lists instead.  For lists the function 'sort'
is available in the libraries of GHC: 

Prelude> Data.List.sort [4,2,7]

> data Triple = Triple {
>     entry 1 :: a;
>     entry 2 :: a;
>     entry 3 :: a;
>     sortTriple :: Triple a -> Triple a;
>    } deriving (Show, Eq)

Are you sure you want 'sortTriple' be a part of the data structure?

More information about the Haskell-Cafe mailing list