Hi Hennig
On 6 March 2017 at 10:35, Henning Thielemann
<email obscured>> wrote:
> Btw. you can omit TypeSynonymInstances if you have FlexibleInstances.
> Your posted code does not need RankNTypes.
Ah I've been collecting these while experimenting. Cargo cult programming ftw!
> An alternative would be to fix the type of the first parameter of
> 'density' to Pattern Time and define instance Num (Pattern time), such
> that the literal 2 is interpreted as Pattern Time. However, I consider it
> abuse of the Num class because you will be hardly able to define sensible
> arithmetic on "Pattern time".
Oh my ... *click*
:set -XFlexibleInstances
instance Num a => Num (Pattern a) where
negate = fmap negate
(+) = liftA2 (+)
(*) = liftA2 (*)
fromInteger = pure . fromInteger
abs = fmap abs
signum = fmap signum
Thanks so much for all the other insightful thoughts but this makes
total sense to me so far, seems to sidestep my issue with parameters
and as a huge added bonus allows me to do things like `sine1 + (0.5 <~
sine1)`.. This is amazing!
Thanks again!