StdClass.dcl 2.28 KB
Newer Older
1 2
definition module StdClass

Camil Staps's avatar
Camil Staps committed
3 4 5 6
/**
 * Meta-classes with derived functions.
 */

7 8 9 10 11 12 13 14 15 16 17 18
// ****************************************************************************************
//	Concurrent Clean Standard Library Module Version 2.0
//	Copyright 1998 University of Nijmegen
// ****************************************************************************************

import StdOverloaded
from StdBool import not

//	Remark: derived class members are not implemented yet!
//	For the time-being, macro definitions are used for this purpose
//	This may cause misleading error messages in case of type errors 

Camil Staps's avatar
Camil Staps committed
19
//* Meta-class describing interval types with an absolute zero.
20 21
class PlusMin a | + , - , zero a

Camil Staps's avatar
Camil Staps committed
22
//* Meta-class describing ratio types.
23 24
class MultDiv a | * , / , one a

Camil Staps's avatar
Camil Staps committed
25
//* Meta-class describing arithmetical types.
26 27
class Arith a 	| PlusMin , MultDiv , abs , sign , ~ a 

Camil Staps's avatar
Camil Staps committed
28
//* Meta-class describing types that can be incremented and decremented.
29 30
class IncDec a	| + , - , one , zero a
where
Camil Staps's avatar
Camil Staps committed
31
  //* Increment a value by one.
32 33 34
  inc :: !a -> a | + , one a
  inc x :== x + one

Camil Staps's avatar
Camil Staps committed
35
  //* Decrement a value by one.
36 37 38
  dec :: !a -> a | - , one a
  dec x :== x - one

Camil Staps's avatar
Camil Staps committed
39
//* Meta-class describing types that can be enumerated.
40 41
class Enum a | < , IncDec a

Camil Staps's avatar
Camil Staps committed
42 43 44 45
/**
 * Equality.
 * @var The type for which values can be equated
 */
46 47
class Eq a | == a	
where
Camil Staps's avatar
Camil Staps committed
48 49 50 51
  /**
   * Inequality.
   * @result True iff the parameters are not equal
   */
52 53 54
  (<>) infix  4 :: !a	!a	->	Bool | Eq a
  (<>) x y :== not (x == y)

Camil Staps's avatar
Camil Staps committed
55 56 57 58
/**
 * Ordering.
 * @var The type that can be ordered.
 */
59 60
class Ord a	| < a
where
Camil Staps's avatar
Camil Staps committed
61 62 63 64
  /**
   * Greater than.
   * @result True iff the first value is strictly greater than the second value.
   */
65 66 67
  (>) infix  4 :: !a !a	-> Bool | Ord a
  (>) x y  :== y < x 

Camil Staps's avatar
Camil Staps committed
68 69 70 71
  /**
   * Smaller than or equal to.
   * @result True iff the first value is smaller than or equal to the second value.
   */
72 73 74
  (<=) infix 4 :: !a !a -> Bool | Ord a
  (<=) x y :== not (y<x)

Camil Staps's avatar
Camil Staps committed
75 76 77 78
  /**
   * Greater than or equal to.
   * @result True iff the first value is greater than or equal to the second value.
   */
79 80 81
  (>=) infix 4 :: !a !a -> Bool | Ord a
  (>=) x y :== not (x<y) 

Camil Staps's avatar
Camil Staps committed
82
  //* The minimum of two values.
83 84 85
  min::!a !a ->	a | Ord a
  min x y  :== case (x<y) of True = x; _ = y

Camil Staps's avatar
Camil Staps committed
86
  //* The maximum of two values.
87 88
  max::!a !a ->	a | Ord a
  max x y  :== case (x<y) of True = y; _ = x