reflex-frp / reflex

Interactive programs without callbacks or side-effects. Functional Reactive Programming (FRP) uses composable events and time-varying values to describe interactive systems as pure functions. Just like other pure functional code, functional reactive code is easier to get right on the first try, maintain, and reuse.

Home Page:https://reflex-frp.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Floating instance for behaviors?

noughtmare opened this issue · comments

commented

I think this instance should work:

instance (Reflex t, Floating a) => Floating (Behavior t a) where
  pi = pure pi
  exp = fmap exp
  log = fmap log
  sqrt = fmap sqrt
  (**) = liftA2 (**)
  logBase = liftA2 logBase
  sin = fmap sin
  cos = fmap cos
  asin = fmap asin
  acos = fmap acos
  atan = fmap atan
  sinh = fmap sinh
  cosh = fmap cosh
  asinh = fmap asinh
  acosh = fmap acosh
  atanh = fmap atanh

I am not so sure this is a good idea? This is true for any Applicative, and I prefer to be explicit about operation on the side vs on the functor "container".

commented

There are already similar instances for Semigroup, Monoid, Num, and Fractional, so to me it's strange to draw the line here.

commented

I also noticed that there are Semigroup, Monoid and Num instances for Dynamic but no Fractional or Floating instances.