Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made MSF and PureGameEnv newtypes. #225

Closed
wants to merge 1 commit into from

Conversation

Icelandjack
Copy link

@Icelandjack Icelandjack commented May 14, 2020

I wanted to test different monoid instances for MSF, I tried Ap but only the first one worked because MSF is defined as a data not a newtype. Making it a newtype means coerce and deriving works fully

deriving
  via MSF m a `Ap` b
  instance (Monad m, Semigroup b) => Semigroup (MSF m a b)
deriving
  via MSF m a `Ap` b
  instance (Monad m, Monoid b) => Monoid (MSF m a b)

vs

-- FAILS: MSF f a b is not represented as a function in memory
deriving
  via a -> Ap f (b, MSF f a b)
  instance (Applicative f, Semigroup b) => Semigroup (MSF f a b)
deriving
  via a -> Ap f (b, MSF f a b)
  instance (Applicative f, Monoid b) => Monoid (MSF f a b)

@freckletonj
Copy link

Is it just an oversight that MSF wasn't newtyped originally? I'd expect this PR to be an easy speedup without any costs.

@walseb
Copy link
Contributor

walseb commented Aug 21, 2021

There are pros and cons I believe: #169

@freckletonj
Copy link

ah, it eliminates one level of laziness. Interesting point.

@ivanperez-keera
Copy link
Owner

Indeed, the choice of not making MSF a newtype was deliberate. Thanks for pointing to that issue, @walseb .

I'd love to be able to answer these questions with data that shows whether it's better or worse. We've found many cases in FRP implementations where "obvious" optimizations introduce a penalty only larger examples or with newer GHC releases, so I'm always on the edge about performance improvements when I don't have the data to back up the decision.

We've had an open issue for some time of doing good data-driven, no-interaction-needed benchmarks on MSFs. It's not a research problem. It's an engineering problem. If we had that, we'd have a much better way of making decisions about code optimizations.

Additionally, and based on some experiments I did (with Martin Handley), a lot of Yampa has been optimized but is actually no faster than plain straightforward Haskell because GHC has changed so much. That opens the opportunity of reducing the Yampa codebase, and making it more abstract. The smaller that Yampa becomes, the more we can just put on top of dunai without any performance penalties. They would both become easier to maintain and more versatile.

I don't want to block the development of dunai, but, of course, my eyes are on the goal of data-driven benchmarks because it would just allow so much progress to be made.

@ivanperez-keera
Copy link
Owner

Also relevant: #233

@Icelandjack Icelandjack closed this by deleting the head repository May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants