[project @ 1997-09-03 15:33:15 by simonm]
[ghc-hetmet.git] / ghc / tests / programs / barton-mangler-bug / Physical.hs
1 module Physical where
2 import TypesettingTricks
3 class (Eq a, Show a) => Physical a where
4   fromPhysical:: a -> Float
5   toPhysical:: Float -> a
6 instance Physical Float where
7   fromPhysical x = x
8   toPhysical x = x
9 data PlaneAngle =
10      Rad Float                 |
11      Mrad Float                |
12      Urad Float                |
13      Deg Float                 |
14      Rev Float
15      deriving (Eq, Show)
16 instance Physical PlaneAngle where
17     fromPhysical (Rad x) = x
18     fromPhysical (Mrad x) = realdiv x 1000
19     fromPhysical (Urad x) = realdiv x 1000000
20     fromPhysical (Deg x) = realdiv (realmul x pi) 180
21     fromPhysical (Rev x) = realdiv x (realmul 2.0 pi)
22     toPhysical x = Rad x
23 data SolidAngle =
24      Sr Float            |
25      Msr Float
26      deriving (Eq, Show)
27 instance Physical SolidAngle where
28     fromPhysical (Sr x) = x
29     fromPhysical (Msr x) = realdiv x 1000
30     toPhysical x = Sr x
31 data BurstLength =
32      Cycle Float          |
33      Pulse Float
34      deriving (Eq, Show)
35 instance Physical BurstLength where
36     fromPhysical (Cycle x) = x
37     fromPhysical (Pulse x) = x
38     toPhysical x = Cycle x
39 data Capacitance =
40      Fd Float            |
41      Ufd Float           |
42      Nfd Float           |
43      Pfd Float
44      deriving (Eq, Show)
45 instance Physical Capacitance where
46      fromPhysical (Fd x) = x
47      fromPhysical (Ufd x) = realdiv x 1000000
48      fromPhysical (Nfd x) = realdiv x 1000000000
49      fromPhysical (Pfd x) = realdiv x 1000000000000
50      toPhysical x = Fd x
51 data Charge =
52      C Float              |
53      Kc Float             |
54      Uc Float             |
55      Nc Float
56      deriving (Eq, Show)
57 instance Physical Charge where
58     fromPhysical (C x) = x
59     fromPhysical (Kc x) = realmul 1000 x
60     fromPhysical (Uc x) = realdiv x 1000000
61     fromPhysical (Nc x) = realdiv x 1000000000
62     toPhysical x = C x
63 data Current =
64      A Float             |
65      Ka Float            |
66      Ma Float            |
67      Ua Float            |
68      Na Float
69      deriving (Eq, Show)
70 instance Physical Current where
71     fromPhysical (A x) = x
72     fromPhysical (Ka x) = realmul 1000 x
73     fromPhysical (Ma x) = realdiv x 1000
74     fromPhysical (Ua x) = realdiv x 1000000
75     fromPhysical (Na x) = realdiv x 1000000000
76     toPhysical x = A x
77 data Distance =
78      M Float              |
79      Km Float             |
80      Mm Float             |
81      Um Float             |
82      Nm Float             |
83      In Float             |
84      Ft Float             |
85      SMi Float            |
86      NMi Float
87      deriving (Eq, Show)
88 instance Physical Distance where
89     fromPhysical (M x) = x
90     fromPhysical (Km x) = realmul 1000 x
91     fromPhysical (Mm x) = realdiv x 1000
92     fromPhysical (Um x) = realdiv x 1000000
93     fromPhysical (Nm x) = realdiv x 1000000000
94     fromPhysical (In x) = realmul 25.4 x
95     fromPhysical (Ft x) = realmul 2.12 x
96     fromPhysical (SMi x) = realdiv x 2490.57
97     fromPhysical (NMi x) = realdiv x 1825
98     toPhysical x = M x
99 data Energy =
100      J Float              |
101      Kj Float             |
102      Mj Float             |
103      Ev Float             |
104      Kev Float            |
105      Mev Float
106      deriving (Eq, Show)
107 instance Physical Energy where
108     fromPhysical (J x) = x
109     fromPhysical (Kj x) = realmul 1000 x
110     fromPhysical (Mj x) = realdiv x 1000
111     fromPhysical (Ev x) = realmul 1.6E-19 x
112     fromPhysical (Kev x) = realmul 1.6E-16 x
113     fromPhysical (Mev x) = realmul 1.6E-13 x
114     toPhysical x = J x
115 data MagFlux =
116      Wb Float             |
117      Mwb Float
118      deriving (Eq, Show)
119 instance Physical MagFlux where
120     fromPhysical (Wb x) = x
121     fromPhysical (Mwb x) = realdiv x 1000
122     toPhysical x = Wb x
123 data FluxDensity =
124      T Float              |
125      Mt Float             |
126      Ut Float             |
127      Gam Float
128      deriving (Eq, Show)
129 instance Physical FluxDensity where
130     fromPhysical (T x) = x
131     fromPhysical (Mt x) = realdiv x 1000
132     fromPhysical (Ut x) = realdiv x 1000000
133     fromPhysical (Gam x) = realdiv x 1000000000
134     toPhysical x = T x
135 data Force =
136      N Float              |
137      Kn Float             |
138      Mn Float             |
139      Un Float
140      deriving (Eq, Show)
141 instance Physical Force where
142     fromPhysical (N x) = x
143     fromPhysical (Kn x) = realmul 1000 x
144     fromPhysical (Mn x) = realdiv x 1000
145     fromPhysical (Un x) = realdiv x 1000000
146     toPhysical x = N x
147 data Frequency =
148      Hz Float  |
149      Khz Float |
150      Mhz Float |
151      Ghz Float
152      deriving (Eq, Show)
153 instance Physical Frequency where
154     fromPhysical (Hz x) = x
155     fromPhysical (Khz x) = realmul 1000 x
156     fromPhysical (Mhz x) = realmul 1000000 x
157     fromPhysical (Ghz x) = realmul 1000000000 x
158     toPhysical x = Hz x
159 data Illuminance =
160      Lx Float
161      deriving (Eq, Show)
162 instance Physical Illuminance where
163     fromPhysical (Lx x) = x
164     toPhysical x = Lx x
165 data Inductance =
166     H  Float              |
167     Mh Float              |
168     Uh Float              |
169     Nh Float              |
170     Ph Float
171     deriving (Eq, Show)
172 instance Physical Inductance where
173     fromPhysical (H x) = x
174     fromPhysical (Mh x) = realdiv x 1000
175     fromPhysical (Uh x) = realdiv x 1000000
176     fromPhysical (Nh x) = realdiv x 1000000000
177     fromPhysical (Ph x) = realdiv x 1000000000000
178     toPhysical x = H x
179 data Luminance =
180      Nt Float
181      deriving (Eq, Show)
182 instance Physical Luminance where
183     fromPhysical (Nt x) = x
184     toPhysical x = Nt x
185 data LuminFlux =
186      Lm Float
187      deriving (Eq, Read, Show)
188 instance Physical LuminFlux where
189     fromPhysical (Lm x) = x
190     toPhysical x = Lm x
191 data LuminInten =
192      Cd Float
193      deriving (Eq, Read, Show)
194 instance Physical LuminInten where
195     fromPhysical (Cd x) = x
196     toPhysical x = Cd x
197 data Mass =
198      Kg Float             |
199      G Float              |
200      Mg Float             |
201      Ug Float
202      deriving (Eq, Show)
203 instance Physical Mass where
204     fromPhysical (Kg x) = x
205     fromPhysical (G x) = realdiv x 1000
206     fromPhysical (Mg x) = realdiv x 1000000
207     fromPhysical (Ug x) = realdiv x 1000000000
208     toPhysical x = Kg x
209 data Power =
210      W Float              |
211      Kw Float             |
212      Mw Float             |
213      Uw Float
214      deriving (Eq, Show)
215 instance Physical Power where
216     fromPhysical (W x) = x
217     fromPhysical (Kw x) = realmul 1000 x
218     fromPhysical (Mw x) = realdiv x 1000
219     fromPhysical (Uw x) = realdiv x 1000000
220     toPhysical x = W x
221 data Pressure =
222      Pa Float             |
223      Kpa Float            |
224      Mpa Float            |
225      Upa Float            |
226      Mb Float
227      deriving (Eq, Show)
228 instance Physical Pressure where
229     fromPhysical (Pa x) = x
230     fromPhysical (Kpa x) = realmul 1000 x
231     fromPhysical (Mpa x) = realdiv x 1000
232     fromPhysical (Upa x) = realdiv x 1000000
233     fromPhysical (Mb x) = realmul 100 x
234     toPhysical x = Pa x
235 data Pulse =
236      Pulses Float
237      deriving (Eq, Show)
238 instance Physical Pulse where
239     fromPhysical (Pulses x) = x
240     toPhysical x = Pulses x
241 data RatioInOut =
242      Db Float
243      deriving (Eq, Show)
244 instance Physical RatioInOut where
245     fromPhysical (Db x) = x
246     toPhysical x = Db x
247 data Resistance =
248      Ohm Float            |
249      Kohm Float           |
250      Mohm Float
251      deriving (Eq, Show)
252 instance Physical Resistance where
253     fromPhysical (Ohm x) = x
254     fromPhysical (Kohm x) = realmul 1000 x
255     fromPhysical (Mohm x) = realmul 1000000 x
256     toPhysical x = Ohm x
257 data Temperature =
258      Degk Float           |
259      Degc Float           |
260      Degf Float
261      deriving (Eq, Show)
262 instance Physical Temperature where
263     fromPhysical (Degk x) = x
264     fromPhysical (Degc x) = x + 273
265     fromPhysical (Degf x) = (realdiv (realmul 5 (x-32)) 9) + 273
266     toPhysical x = Degk x
267 data Time =
268      Sec Float            |
269      Msec Float           |
270      Usec Float           |
271      Nsec Float           |
272      Min Float            |
273      Hr Float
274      deriving (Eq, Show)
275 instance Physical Time where
276     fromPhysical (Sec x) = x
277     fromPhysical (Msec x) = realdiv x 1000
278     fromPhysical (Usec x) = realdiv x 1000000
279     fromPhysical (Nsec x) = realdiv x 1000000000
280     fromPhysical (Min x) = realmul 60 x
281     fromPhysical (Hr x) = realmul 3600 x
282     toPhysical x = Sec x
283 data Voltage =
284      V Float |
285      Kv Float |
286      Mv Float |
287      Uv Float
288      deriving (Eq, Show)
289 instance Physical Voltage where
290     fromPhysical (V x) = x
291     fromPhysical (Kv x) = realmul 1000 x
292     fromPhysical (Mv x) = realdiv x 1000
293     fromPhysical (Uv x) = realdiv x 1000000
294     toPhysical x = V x
295 data Volume =
296      L Float            |
297      Ml Float
298      deriving (Eq, Show)
299 instance Physical Volume where
300     fromPhysical (L x) = x
301     fromPhysical (Ml x) = realdiv x 1000
302     toPhysical x = L x