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

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 

19 20 21
/**
 * Meta-class describing interval types with an absolute zero.
 */
22 23
class PlusMin a | + , - , zero a

24 25 26
/**
 * Meta-class describing ratio types.
 */
27 28
class MultDiv a | * , / , one a

29 30 31
/**
 * Meta-class describing arithmetical types.
 */
32 33
class Arith a 	| PlusMin , MultDiv , abs , sign , ~ a 

34 35 36
/**
 * Meta-class describing types that can be incremented and decremented.
 */
37 38
class IncDec a	| + , - , one , zero a
where
39 40 41
  /**
   * Increment a value by one.
   */
42 43 44
  inc :: !a -> a | + , one a
  inc x :== x + one

45 46 47
  /**
   * Decrement a value by one.
   */
48 49 50
  dec :: !a -> a | - , one a
  dec x :== x - one

51 52 53
/**
 * Meta-class describing types that can be enumerated.
 */
54 55
class Enum a | < , IncDec a

56 57 58 59 60
/**
 * Equality.
 *
 * @var The type for which values can be equated
 */
61 62
class Eq a | == a	
where
63 64 65 66 67
  /**
   * Inequality.
   *
   * @result True iff the parameters are not equal
   */
68 69 70
  (<>) infix  4 :: !a	!a	->	Bool | Eq a
  (<>) x y :== not (x == y)

71 72 73 74 75
/**
 * Ordering.
 *
 * @var The type that can be ordered.
 */
76 77
class Ord a	| < a
where
78 79 80 81 82
  /**
   * Greater than.
   *
   * @result True iff the first value is strictly greater than the second value.
   */
83 84 85
  (>) infix  4 :: !a !a	-> Bool | Ord a
  (>) x y  :== y < x 

86 87 88 89 90
  /**
   * Smaller than or equal to.
   *
   * @result True iff the first value is smaller than or equal to the second value.
   */
91 92 93
  (<=) infix 4 :: !a !a -> Bool | Ord a
  (<=) x y :== not (y<x)

94 95 96 97 98
  /**
   * Greater than or equal to.
   *
   * @result True iff the first value is greater than or equal to the second value.
   */
99 100 101
  (>=) infix 4 :: !a !a -> Bool | Ord a
  (>=) x y :== not (x<y) 

102 103 104
  /**
   * The minimum of two values.
   */
105 106 107
  min::!a !a ->	a | Ord a
  min x y  :== case (x<y) of True = x; _ = y

108 109 110
  /**
   * The maximum of two values.
   */
111 112
  max::!a !a ->	a | Ord a
  max x y  :== case (x<y) of True = y; _ = x