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

Make sdl2 compatible with base < 4.11 #310

Open
ivanperez-keera opened this issue Nov 5, 2024 · 4 comments
Open

Make sdl2 compatible with base < 4.11 #310

ivanperez-keera opened this issue Nov 5, 2024 · 4 comments

Comments

@ivanperez-keera
Copy link

ivanperez-keera commented Nov 5, 2024

The module SDL.Input.Mouse assumes that (<>) is defined in Prelude, but that only happened in base 4.11. Until then, the symbol was defined in Data.Semigroup, and another is defined in Data.Monoid (for some types, the two are equivalent).

It's being used here: https://github.com/haskell-game/sdl2/blob/master/src/SDL/Input/Mouse.hs#L307

We are trying to move dunai to use sdl2, and we are hitting a problem with supporting older versions of GHC.

Would it be possible to add a conditional import so that sdl2 compiles with older versions of GHC as well?

Since <> is used on Strings, which are lists of characters, and lists are monoids, then it's safe to pick the version from Data.Monoid because they are equivalent per the definition of Semigroup:

class Semigroup a where
  (<>) :: a -> a -> a

  default (<>) :: Monoid a => a -> a -> a
  (<>) = mappend

Therefore, something along the following lines would do:

#if !MIN_VERSION_base(4,11,0)
import Data.Monoid ((<>))
#endif
@ivanperez-keera ivanperez-keera changed the title Make SDL2 compatible with base < 4.12 Make SDL2 compatible with base < 4.11 Nov 5, 2024
@ivanperez-keera ivanperez-keera changed the title Make SDL2 compatible with base < 4.11 Make sdl2 compatible with base < 4.11 Nov 5, 2024
@ocharles
Copy link
Member

ocharles commented Nov 5, 2024

base-4.11 is over 4 years old. Pre 4.11 puts you all the way back to GHC 8.2. I'm not sure we've ever decided what our support policy is, but that is a whopping huge window and not sure we have the resources to actually commit to that

@ivanperez-keera
Copy link
Author

ivanperez-keera commented Nov 5, 2024

From the current version of the same file in sdl2:

#if !MIN_VERSION_base(4,8,0)
import Control.Applicative
#endif

Those three lines help support the GHC 7 series (the last version of which was released 9 years ago; incidentally, both dunai and Yampa work well with all versions of GHC since 7.6 and they are tested with those regularly).

I'm not trying to stir a debate on where the line should be drawn. All I'm asking is if you'd accept a 3 line patch in the same file :)

@ocharles
Copy link
Member

ocharles commented Nov 5, 2024

Of course we could accept such a patch, I'm just saying don't expect it to not just break again :)

ivanperez-keera added a commit to ivanperez-keera/sdl2 that referenced this issue Nov 5, 2024
This commit enables compatibility of sdl2 with base versions prior to
4.11 (corresponding to GHC versions prior to 8.4). The patch requires
introducing protections around a warning flag that didn't exist prior
to GHC 8.4, and a conditional import.
@ivanperez-keera
Copy link
Author

ivanperez-keera commented Nov 5, 2024

Thanks!

I've sent a PR. I tried it with GHC 7.10 (since base 4.8, which is currently mentioned, came with GHC 7.10) and it compiles.

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

No branches or pull requests

2 participants