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
Copy file name to clipboardExpand all lines: Physics/src/Dimensions/Quantity.lhs
+4-11Lines changed: 4 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ Quantities
28
28
29
29
> importqualifiedDimensions.ValueLevelasV
30
30
> importDimensions.TypeLevelasT
31
-
> importPreludeasPhiding (length, div)
31
+
> importPreludeasPhiding (length)
32
32
33
33
We'll now create a data type for quantities and combine dimensions on value-level and type-level. Just as before, a bunch of GHC-extensions are necessary.
34
34
@@ -65,14 +65,7 @@ Let's get on to the actual data type declaration.
65
65
> dataQuantity (d::T.Dim) (v::*) where
66
66
> ValQuantity::V.Dim->v->Quantitydv
67
67
68
-
<<<<<<< HEAD
69
-
> lift::Quantitydima->a
70
-
> lift (Quantity _ v) = v
71
-
72
-
`data Quantity` creates a *type constructor*. Which means it takes two *types* (of certain *kinds*) to create another *type* (of a certain *kind*). For comparsion, here's a *value constructor* which takes two *values* (of certain *types*) as input to create another *value* (of a certain *type*).
73
-
=======
74
68
That was sure a mouthful! Let's break it down. `data Quantity (d :: T.Dim) (v :: *)` creates the *type constructor* `Quantity`. A type constructor takes types to create another type. In this case, the type constructor `Quantity` takes a type `d` of *kind* `T.Dim` and a type `v` of *kind* `*` to create the type `Quantity d v`. Let's see it in action
75
-
>>>>>>> master
76
69
77
70
< typeExampleType=QuantityT.LengthDouble
78
71
@@ -305,7 +298,7 @@ We often use `Double` as the value holding type. Doing exact comparsions isn't a
305
298
Testing if a quantity is zero is something which might be a common operation. So we define it here.
306
299
307
300
> isZero:: (Fractionalv, Ordv) =>Quantitydv->Bool
308
-
> isZero (ValQuantity _ v) =(abs v)<0.001
301
+
> isZero (ValQuantity _ v) =abs v <0.001
309
302
310
303
311
304
Arithmetic on quantities
@@ -361,10 +354,10 @@ We quickly realize a pattern, so let's generalize a bit.
0 commit comments