summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/programs/barton-mangler-bug/Physical.hs
blob: 91981e0ac5f209045aa3f7b8ac19139ae3c4d361 (plain)
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
65
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
module Physical where
import TypesettingTricks
class (Eq a, Show a) => Physical a where
  fromPhysical:: a -> Float
  toPhysical:: Float -> a
instance Physical Float where
  fromPhysical x = x
  toPhysical x = x
data PlaneAngle =
     Rad Float                 |
     Mrad Float                |
     Urad Float                |
     Deg Float                 |
     Rev Float
     deriving (Eq, Show)
instance Physical PlaneAngle where
    fromPhysical (Rad x) = x
    fromPhysical (Mrad x) = realdiv x 1000
    fromPhysical (Urad x) = realdiv x 1000000
    fromPhysical (Deg x) = realdiv (realmul x pi) 180
    fromPhysical (Rev x) = realdiv x (realmul 2.0 pi)
    toPhysical x = Rad x
data SolidAngle =
     Sr Float            |
     Msr Float
     deriving (Eq, Show)
instance Physical SolidAngle where
    fromPhysical (Sr x) = x
    fromPhysical (Msr x) = realdiv x 1000
    toPhysical x = Sr x
data BurstLength =
     Cycle Float          |
     Pulse Float
     deriving (Eq, Show)
instance Physical BurstLength where
    fromPhysical (Cycle x) = x
    fromPhysical (Pulse x) = x
    toPhysical x = Cycle x
data Capacitance =
     Fd Float            |
     Ufd Float           |
     Nfd Float           |
     Pfd Float
     deriving (Eq, Show)
instance Physical Capacitance where
     fromPhysical (Fd x) = x
     fromPhysical (Ufd x) = realdiv x 1000000
     fromPhysical (Nfd x) = realdiv x 1000000000
     fromPhysical (Pfd x) = realdiv x 1000000000000
     toPhysical x = Fd x
data Charge =
     C Float              |
     Kc Float             |
     Uc Float             |
     Nc Float
     deriving (Eq, Show)
instance Physical Charge where
    fromPhysical (C x) = x
    fromPhysical (Kc x) = realmul 1000 x
    fromPhysical (Uc x) = realdiv x 1000000
    fromPhysical (Nc x) = realdiv x 1000000000
    toPhysical x = C x
data Current =
     A Float             |
     Ka Float            |
     Ma Float            |
     Ua Float            |
     Na Float
     deriving (Eq, Show)
instance Physical Current where
    fromPhysical (A x) = x
    fromPhysical (Ka x) = realmul 1000 x
    fromPhysical (Ma x) = realdiv x 1000
    fromPhysical (Ua x) = realdiv x 1000000
    fromPhysical (Na x) = realdiv x 1000000000
    toPhysical x = A x
data Distance =
     M Float              |
     Km Float             |
     Mm Float             |
     Um Float             |
     Nm Float             |
     In Float             |
     Ft Float             |
     SMi Float            |
     NMi Float
     deriving (Eq, Show)
instance Physical Distance where
    fromPhysical (M x) = x
    fromPhysical (Km x) = realmul 1000 x
    fromPhysical (Mm x) = realdiv x 1000
    fromPhysical (Um x) = realdiv x 1000000
    fromPhysical (Nm x) = realdiv x 1000000000
    fromPhysical (In x) = realmul 25.4 x
    fromPhysical (Ft x) = realmul 2.12 x
    fromPhysical (SMi x) = realdiv x 2490.57
    fromPhysical (NMi x) = realdiv x 1825
    toPhysical x = M x
data Energy =
     J Float              |
     Kj Float             |
     Mj Float             |
     Ev Float             |
     Kev Float            |
     Mev Float
     deriving (Eq, Show)
instance Physical Energy where
    fromPhysical (J x) = x
    fromPhysical (Kj x) = realmul 1000 x
    fromPhysical (Mj x) = realdiv x 1000
    fromPhysical (Ev x) = realmul 1.6E-19 x
    fromPhysical (Kev x) = realmul 1.6E-16 x
    fromPhysical (Mev x) = realmul 1.6E-13 x
    toPhysical x = J x
data MagFlux =
     Wb Float             |
     Mwb Float
     deriving (Eq, Show)
instance Physical MagFlux where
    fromPhysical (Wb x) = x
    fromPhysical (Mwb x) = realdiv x 1000
    toPhysical x = Wb x
data FluxDensity =
     T Float              |
     Mt Float             |
     Ut Float             |
     Gam Float
     deriving (Eq, Show)
instance Physical FluxDensity where
    fromPhysical (T x) = x
    fromPhysical (Mt x) = realdiv x 1000
    fromPhysical (Ut x) = realdiv x 1000000
    fromPhysical (Gam x) = realdiv x 1000000000
    toPhysical x = T x
data Force =
     N Float              |
     Kn Float             |
     Mn Float             |
     Un Float
     deriving (Eq, Show)
instance Physical Force where
    fromPhysical (N x) = x
    fromPhysical (Kn x) = realmul 1000 x
    fromPhysical (Mn x) = realdiv x 1000
    fromPhysical (Un x) = realdiv x 1000000
    toPhysical x = N x
data Frequency =
     Hz Float  |
     Khz Float |
     Mhz Float |
     Ghz Float
     deriving (Eq, Show)
instance Physical Frequency where
    fromPhysical (Hz x) = x
    fromPhysical (Khz x) = realmul 1000 x
    fromPhysical (Mhz x) = realmul 1000000 x
    fromPhysical (Ghz x) = realmul 1000000000 x
    toPhysical x = Hz x
data Illuminance =
     Lx Float
     deriving (Eq, Show)
instance Physical Illuminance where
    fromPhysical (Lx x) = x
    toPhysical x = Lx x
data Inductance =
    H  Float              |
    Mh Float              |
    Uh Float              |
    Nh Float              |
    Ph Float
    deriving (Eq, Show)
instance Physical Inductance where
    fromPhysical (H x) = x
    fromPhysical (Mh x) = realdiv x 1000
    fromPhysical (Uh x) = realdiv x 1000000
    fromPhysical (Nh x) = realdiv x 1000000000
    fromPhysical (Ph x) = realdiv x 1000000000000
    toPhysical x = H x
data Luminance =
     Nt Float
     deriving (Eq, Show)
instance Physical Luminance where
    fromPhysical (Nt x) = x
    toPhysical x = Nt x
data LuminFlux =
     Lm Float
     deriving (Eq, Read, Show)
instance Physical LuminFlux where
    fromPhysical (Lm x) = x
    toPhysical x = Lm x
data LuminInten =
     Cd Float
     deriving (Eq, Read, Show)
instance Physical LuminInten where
    fromPhysical (Cd x) = x
    toPhysical x = Cd x
data Mass =
     Kg Float             |
     G Float              |
     Mg Float             |
     Ug Float
     deriving (Eq, Show)
instance Physical Mass where
    fromPhysical (Kg x) = x
    fromPhysical (G x) = realdiv x 1000
    fromPhysical (Mg x) = realdiv x 1000000
    fromPhysical (Ug x) = realdiv x 1000000000
    toPhysical x = Kg x
data Power =
     W Float              |
     Kw Float             |
     Mw Float             |
     Uw Float
     deriving (Eq, Show)
instance Physical Power where
    fromPhysical (W x) = x
    fromPhysical (Kw x) = realmul 1000 x
    fromPhysical (Mw x) = realdiv x 1000
    fromPhysical (Uw x) = realdiv x 1000000
    toPhysical x = W x
data Pressure =
     Pa Float             |
     Kpa Float            |
     Mpa Float            |
     Upa Float            |
     Mb Float
     deriving (Eq, Show)
instance Physical Pressure where
    fromPhysical (Pa x) = x
    fromPhysical (Kpa x) = realmul 1000 x
    fromPhysical (Mpa x) = realdiv x 1000
    fromPhysical (Upa x) = realdiv x 1000000
    fromPhysical (Mb x) = realmul 100 x
    toPhysical x = Pa x
data Pulse =
     Pulses Float
     deriving (Eq, Show)
instance Physical Pulse where
    fromPhysical (Pulses x) = x
    toPhysical x = Pulses x
data RatioInOut =
     Db Float
     deriving (Eq, Show)
instance Physical RatioInOut where
    fromPhysical (Db x) = x
    toPhysical x = Db x
data Resistance =
     Ohm Float            |
     Kohm Float           |
     Mohm Float
     deriving (Eq, Show)
instance Physical Resistance where
    fromPhysical (Ohm x) = x
    fromPhysical (Kohm x) = realmul 1000 x
    fromPhysical (Mohm x) = realmul 1000000 x
    toPhysical x = Ohm x
data Temperature =
     Degk Float           |
     Degc Float           |
     Degf Float
     deriving (Eq, Show)
instance Physical Temperature where
    fromPhysical (Degk x) = x
    fromPhysical (Degc x) = x + 273
    fromPhysical (Degf x) = (realdiv (realmul 5 (x-32)) 9) + 273
    toPhysical x = Degk x
data Time =
     Sec Float            |
     Msec Float           |
     Usec Float           |
     Nsec Float           |
     Min Float            |
     Hr Float
     deriving (Eq, Show)
instance Physical Time where
    fromPhysical (Sec x) = x
    fromPhysical (Msec x) = realdiv x 1000
    fromPhysical (Usec x) = realdiv x 1000000
    fromPhysical (Nsec x) = realdiv x 1000000000
    fromPhysical (Min x) = realmul 60 x
    fromPhysical (Hr x) = realmul 3600 x
    toPhysical x = Sec x
data Voltage =
     V Float |
     Kv Float |
     Mv Float |
     Uv Float
     deriving (Eq, Show)
instance Physical Voltage where
    fromPhysical (V x) = x
    fromPhysical (Kv x) = realmul 1000 x
    fromPhysical (Mv x) = realdiv x 1000
    fromPhysical (Uv x) = realdiv x 1000000
    toPhysical x = V x
data Volume =
     L Float            |
     Ml Float
     deriving (Eq, Show)
instance Physical Volume where
    fromPhysical (L x) = x
    fromPhysical (Ml x) = realdiv x 1000
    toPhysical x = L x