You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why not make `Quantity` an instance of `Num`, `Fractional`, `Floating` och `Functor`? The reason is that the functions of those type classes have the following type
363
+
Why not make `Quantity` an instance of `Num`, `Fractional` and `Floating`? The reason is that the functions of those type classes have the following type
363
364
364
365
< (*):: (Numa) =>a->a->a
365
366
@@ -372,7 +373,7 @@ The input here may actually be of *different* types, and the output has a type d
372
373
373
374
However, operations with only scalars (type `One`) has types compatible with `Num`.
374
375
375
-
**Exercise** `Quantity One` has compatible types. Make it an instance of `Num`, `Fractional`, `Floating` and `Functor`.
376
+
**Exercise** `Quantity One` has compatible types. Make it an instance of `Num`, `Fractional`and `Floating`.
376
377
377
378
<details>
378
379
<summary>**Solution**</summary>
@@ -382,8 +383,8 @@ However, operations with only scalars (type `One`) has types compatible with `Nu
382
383
>(+)=(+#)
383
384
>(-)=(-#)
384
385
>(*)=(*#)
385
-
>abs=qmapabs
386
-
>signum=qmapsignum
386
+
>abs=fmapabs
387
+
>signum=fmapsignum
387
388
>fromInteger n =ValQuantityV.one (fromInteger n)
388
389
389
390
> instance (Fractionalv) =>Fractional (QuantityOnev) where
@@ -399,14 +400,11 @@ However, operations with only scalars (type `One`) has types compatible with `Nu
399
400
>asin= asinq
400
401
>acos= acosq
401
402
>atan= atanq
402
-
>sinh= qmap sinh
403
-
>cosh= qmap cosh
404
-
>asinh= qmap asinh
405
-
>acosh= qmap acosh
406
-
>atanh= qmap atanh
407
-
408
-
> instanceFunctor (QuantityOne) where
409
-
>fmap= qmap
403
+
>sinh=fmapsinh
404
+
>cosh=fmapcosh
405
+
>asinh=fmapasinh
406
+
>acosh=fmapacosh
407
+
>atanh=fmapatanh
410
408
411
409
</div>
412
410
</details>
@@ -463,6 +461,7 @@ To solve these two problems we'll introduce some syntactic sugar. First some pre
0 commit comments