-- Adapted from Data Field Haskell 040405/BjL. -- Some slight changes. module Pord (Pord(..)) where class Ord a => Pord a where glb :: a -> a -> a lub :: a -> a -> a lt :: a -> a -> Bool -- default definitions: glb x y = min x y lub x y = max x y lt x y = x <= y -- Default definition for basic types: instance Pord Bool instance Pord Char instance Pord Int instance Pord Integer instance Pord Ordering -- Tuple types (2- and 3-tuples): instance (Pord a, Pord b) => Pord (a,b) where glb (x1,y1) (x2,y2) = (glb x1 x2, glb y1 y2) lub (x1,y1) (x2,y2) = (lub x1 x2, lub y1 y2) lt (x1,y1) (x2,y2) = lt x1 x2 && lt y1 y2 instance (Pord a, Pord b, Pord c) => Pord (a,b,c) where glb (x1,y1,z1) (x2,y2,z2) = (glb x1 x2, glb y1 y2, glb z1 z2) lub (x1,y1,z1) (x2,y2,z2) = (lub x1 x2, lub y1 y2, lub z1 z2) lt (x1,y1,z1) (x2,y2,z2) = lt x1 x2 && lt y1 y2 && lt z1 z2