StdIOBasic.dcl 2.6 KB
Newer Older
Peter Achten's avatar
Peter Achten committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
definition module StdIOBasic


//	********************************************************************************
//	Clean Standard Object I/O library, version 1.2
//	
//	StdIOBasic defines basic types and access functions for the I/O library.
//	********************************************************************************


import	StdOverloaded, StdString


/*	General type constructors for composing context-independent data structures.
*/
::	:^:		t1 t2			= (:^:) infixr 9 t1 t2


/*	General type constructors for composing context-dependent data structures.
*/
::	:~:		t1 t2		cs	= (:~:) infixr 9 (t1 cs) (t2 cs)
::	ListCS		t		cs	= ListCS [t cs]
::	NilCS				cs	= NilCS


/*	General type constructors for composing local and context-dependent 
	data structures.
*/
::	:+:		t1 t2	ls	cs	= (:+:) infixr 9 (t1 ls cs) (t2 ls cs)
::	ListLS		t	ls	cs	= ListLS [t ls cs]
::	NilLS			ls	cs	= NilLS
::	NewLS		t	ls	cs	= E..new: {newLS::new, newDef:: t   new		cs}
::	AddLS		t	ls	cs	= E..add: {addLS::add, addDef:: t *(add,ls)	cs}

noLS ::     (.a->.b)    (.c,.a) -> (.c,.b)	// Lift function    a  ->  b
											// to             (c,a)->(c,b)
noLS1:: (.x->.a->.b) .x (.c,.a) -> (.c,.b)	// Lift function x->  a  ->  b
											// to            x->(c,a)->(c,b)


::	Index			:==	Int
::	Title			:==	String


::	Vector2			=	{vx::!Int,vy::!Int}

instance			==			Vector2		// @1-@2==zero
instance			+			Vector2		// {vx=@1.vx+@2.vx,vy=@1.vy+@2.vy}
instance			-			Vector2		// {vx=@1.vx-@2.vx,vy=@1.vy-@2.vy}
instance			zero		Vector2		// {vx=0,vy=0}
instance			~			Vector2		// zero-@1
instance			toString	Vector2

class toVector		x :: !x ->	Vector2


::	Size			=	{w ::!Int,h ::!Int}

instance			==			Size		// @1.w==@2.w && @1.h==@2.h
instance			zero		Size		// {w=0,h=0}
instance			toVector	Size		// {w,h}->{vx=w,vy=h}
instance			toString	Size


65
::	Point2
Peter Achten's avatar
Peter Achten committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
	=	{	x		:: !Int
		,	y		:: !Int
		}
::	Rectangle
	=	{	corner1	:: !Point2
		,	corner2	:: !Point2
		}

instance			==			Point2		// @1-@2==zero
instance			+			Point2		// {x=@1.x+@2.x,y=@1.y+@2.y}
instance			-			Point2 		// {x=@1.x-@2.x,y=@1.y-@2.y}
instance			zero		Point2		// {x=0,y=0}
instance			~			Point2		// zero-@1
instance			toVector	Point2		// {x,y}->{vx=x,vy=y}
instance			toString	Point2

instance			==			Rectangle	//    @1.corner1==@2.corner1
											// && @1.corner2==@2.corner2
instance			zero		Rectangle	// {corner1=zero,corner2=zero}
instance			toString	Rectangle

rectangleSize		:: !Rectangle -> Size	// {w=abs (@1.corner1-@1.corner2).x,
											//  h=abs (@1.corner1-@1.corner2).y}
movePoint	:: !Vector2 !Point2 -> .Point2	// {vx,vy} {x,y} -> {vx+x,vy+y}


::	IdFun st		:==	st -> st
93

94
::	Void			=	Void