File tree 2 files changed +9
-26
lines changed
2 files changed +9
-26
lines changed Original file line number Diff line number Diff line change @@ -347,13 +347,12 @@ var MyNullableExtended = {
347
347
348
348
function area ( shape ) {
349
349
switch ( shape . TAG ) {
350
- case "Circle" :
351
- return Math . PI * Math . pow ( shape . _0 . radius , 2 ) ;
352
- case "Square" :
353
- return Math . pow ( shape . _0 . sideLength , 2 ) ;
354
- case "Rectangle" :
355
- var match = shape . _0 ;
356
- return match . width * match . height ;
350
+ case 1 :
351
+ return Math . PI * Math . pow ( shape . radius , 2 ) ;
352
+ case "square" :
353
+ return Math . pow ( shape . sideLength , 2 ) ;
354
+ case "rectangle" :
355
+ return shape . width * shape . height ;
357
356
358
357
}
359
358
}
Original file line number Diff line number Diff line change @@ -237,26 +237,10 @@ module TaggedUnions = {
237
237
}
238
238
}
239
239
*/
240
- type circle = {
241
- kind : string ,
242
- radius : float ,
243
- }
244
-
245
- type square = {
246
- kind : string ,
247
- sideLength : float ,
248
- }
249
-
250
- type rectangle = {
251
- kind : string ,
252
- width : float ,
253
- height : float ,
254
- }
255
-
256
240
type shape =
257
- | Circle (circle )
258
- | Square ( square )
259
- | Rectangle ( rectangle )
241
+ | @ as ( 1 ) Circle ({ kind : string , radius : float } )
242
+ | @ as ( " square" ) Square ({ kind : string , sideLength : float } )
243
+ | @ as ( " rectangle" ) Rectangle ({ kind : string , width : float , height : float } )
260
244
261
245
let area = (shape : shape ): float => {
262
246
switch shape {
You can’t perform that action at this time.
0 commit comments