bjornbm / dimensional-classic

Automatically exported from code.google.com/p/dimensional
BSD 3-Clause "New" or "Revised" License
3 stars 1 forks source link

Investigate making 'DimensionLess' an instance of 'Num' #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The main incentive is to avoid having to multiply literal numbers with the
unit 'one'. In order for this to be useful the type must have a reasonable
chance of being inferred. This will require consolidation of type classes
and "reverse" functional dependencies, e.g. replacing 'mul' and 'div with:

class Prod d d' d'' | d d' -> d'', d d'' -> d' where
    (*) :: Quantity d a -> Quantity d' a -> Quantity d'' a
    (/) :: Quantity d'' a -> Quantity d a -> Quantity d' a

Original issue reported on code.google.com by bjorn.bu...@gmail.com on 28 Dec 2006 at 5:02

GoogleCodeExporter commented 9 years ago
This would allow e.g. the type 'Length DimensionLess' which isn't desirable. 
Would
this be a problem in practice or would the type inference always figure out 
that we
want e.g. 'Length Double'?

Original comment by bjorn.bu...@gmail.com on 30 Dec 2006 at 5:55

GoogleCodeExporter commented 9 years ago
Perhaps a better solution is for the user to create 'Num' (et c) instances for 
the
specific 'Num' instances he intends to use. An implementation could be provided 
for
e.g. 'Dimensionless Double'. (Can we derive this automatically using e.g. 
DrIFT?)

Original comment by bjorn.bu...@gmail.com on 31 Jan 2007 at 6:45

GoogleCodeExporter commented 9 years ago
Concerning comment #1 -- this probably isn't a practical concern since, after 
all,
this is probably the most common idiom for instances of num.

Original comment by bjorn.bu...@gmail.com on 12 Mar 2007 at 11:18

GoogleCodeExporter commented 9 years ago

Original comment by bjorn.bu...@gmail.com on 13 Mar 2007 at 11:39