From 9bd55d15409959aae1c4e59b8fd220d665fc6cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Wed, 10 May 2023 12:11:40 +0200 Subject: [PATCH 1/3] Allow GHC 9.6 --- flake.nix | 1 + monad-bayes.cabal | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index ceeecdd2..008d694a 100644 --- a/flake.nix +++ b/flake.nix @@ -84,6 +84,7 @@ "ghc902" "ghc927" "ghc945" + "ghc964" ]; buildForVersion = ghcVersion: (builtins.getAttr ghcVersion pkgs.haskell.packages).developPackage opts; in lib.attrsets.genAttrs ghcs buildForVersion; diff --git a/monad-bayes.cabal b/monad-bayes.cabal index 56a95b35..3fc2e938 100644 --- a/monad-bayes.cabal +++ b/monad-bayes.cabal @@ -7,7 +7,7 @@ copyright: 2015-2020 Adam Scibior maintainer: dominic.steinitz@tweag.io author: Adam Scibior stability: experimental -tested-with: GHC ==9.0.2 || ==9.2.7 || ==9.4.5 +tested-with: GHC ==9.0.2 || ==9.2.7 || ==9.4.5 || ==9.6.4 homepage: http://github.com/tweag/monad-bayes#readme bug-reports: https://github.com/tweag/monad-bayes/issues synopsis: A library for probabilistic programming. @@ -38,7 +38,7 @@ flag dev common deps build-depends: - , base >=4.15 && <4.18 + , base >=4.15 && <4.19 , brick >=1.0 && <2.0 , containers >=0.5.10 && <0.7 , foldl ^>=1.4 From 080028aa41ece98a9729dc5694929dff859a983f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Thu, 11 May 2023 17:37:39 +0200 Subject: [PATCH 2/3] Remove unneeded overrides --- flake.nix | 1 - monad-bayes.cabal | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 008d694a..dd63341a 100644 --- a/flake.nix +++ b/flake.nix @@ -77,7 +77,6 @@ # https://github.com/tweag/monad-bayes/pull/256: Don't run tests on Mac because of machine precision issues modifier = drv: if system == "x86_64-linux" then drv else pkgs.haskell.lib.dontCheck drv; overrides = self: super: with pkgs.haskell.lib; { # Please check after flake.lock updates whether some of these overrides can be removed - hspec = super.hspec_2_11_7; }; }; ghcs = [ # Always keep this up to date with the tested-with section in monad-bayes.cabal! diff --git a/monad-bayes.cabal b/monad-bayes.cabal index 3fc2e938..ba54dc22 100644 --- a/monad-bayes.cabal +++ b/monad-bayes.cabal @@ -53,7 +53,7 @@ common deps , matrix ^>=0.3 , monad-coroutine ^>=0.9.0 , monad-extras ^>=0.6 - , mtl >=2.2 && <2.4 + , mtl >=2.2.2 && <2.4 , mwc-random >=0.13.6 && <0.16 , pipes ^>=4.3 , pretty-simple ^>=4.1 @@ -72,7 +72,7 @@ common test-deps , abstract-par ^>=0.3 , criterion >=1.5 && <1.7 , directory ^>=1.3 - , hspec ^>=2.11 + , hspec >=2.10 && <2.12 , monad-bayes , optparse-applicative >=0.17 && <0.19 , process ^>=1.6 From 5b00f1daca2d00a6ff17e9334a320ccf17fc08e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Mon, 4 Mar 2024 16:58:56 +0100 Subject: [PATCH 3/3] Order imports so they are compatible with GHC 9.6 and lower --- benchmark/Single.hs | 8 ++++++-- models/ConjugatePriors.hs | 7 +++++-- models/Dice.hs | 6 +++++- src/Control/Monad/Bayes/Enumerator.hs | 4 +++- src/Control/Monad/Bayes/Integrator.hs | 4 ++++ src/Control/Monad/Bayes/Sampler/Lazy.hs | 3 ++- src/Control/Monad/Bayes/Traced/Basic.hs | 6 +++++- src/Control/Monad/Bayes/Traced/Static.hs | 6 +++++- 8 files changed, 35 insertions(+), 9 deletions(-) diff --git a/benchmark/Single.hs b/benchmark/Single.hs index cc8f94f5..4d390786 100644 --- a/benchmark/Single.hs +++ b/benchmark/Single.hs @@ -1,12 +1,12 @@ {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE ImportQualifiedPost #-} +import Control.Applicative (Applicative (..)) import Control.Monad.Bayes.Sampler.Strict import Data.Time (diffUTCTime, getCurrentTime) import Helper import Options.Applicative - ( Applicative (liftA2), - ParserInfo, + ( ParserInfo, auto, execParser, fullDesc, @@ -17,6 +17,10 @@ import Options.Applicative option, short, ) +-- Prelude exports liftA2 from GHC 9.6 on, see https://github.com/haskell/core-libraries-committee/blob/main/guides/export-lifta2-prelude.md +-- import Control.Applicative further up can be removed once we don't support GHC <= 9.4 anymore + +import Prelude hiding (Applicative (..)) infer :: Model -> Alg -> IO () infer model alg = do diff --git a/models/ConjugatePriors.hs b/models/ConjugatePriors.hs index 64a72967..093b3612 100644 --- a/models/ConjugatePriors.hs +++ b/models/ConjugatePriors.hs @@ -4,12 +4,15 @@ module ConjugatePriors where -import Control.Applicative (Applicative (liftA2)) +import Control.Applicative (Applicative (..)) import Control.Foldl (fold) import Control.Foldl qualified as F import Control.Monad.Bayes.Class (Bayesian (..), MonadDistribution (bernoulli, beta, gamma, normal), MonadMeasure, normalPdf) import Numeric.Log (Log (Exp)) -import Prelude +-- Prelude exports liftA2 from GHC 9.6 on, see https://github.com/haskell/core-libraries-committee/blob/main/guides/export-lifta2-prelude.md +-- import Control.Applicative further up can be removed once we don't support GHC <= 9.4 anymore + +import Prelude hiding (Applicative (..)) type GammaParams = (Double, Double) diff --git a/models/Dice.hs b/models/Dice.hs index 4cafc393..5a2660fd 100644 --- a/models/Dice.hs +++ b/models/Dice.hs @@ -3,13 +3,17 @@ module Dice (diceHard, diceSoft) where -- A toy model for dice rolling from http://dl.acm.org/citation.cfm?id=2804317 -- Exact results can be obtained using Dist monad -import Control.Applicative (liftA2) +import Control.Applicative (Applicative (..)) import Control.Monad.Bayes.Class ( MonadDistribution (uniformD), MonadFactor (score), MonadMeasure, condition, ) +-- Prelude exports liftA2 from GHC 9.6 on, see https://github.com/haskell/core-libraries-committee/blob/main/guides/export-lifta2-prelude.md +-- import Control.Applicative further up can be removed once we don't support GHC <= 9.4 anymore + +import Prelude hiding (Applicative (..)) -- | A toss of a six-sided die. die :: (MonadDistribution m) => m Int diff --git a/src/Control/Monad/Bayes/Enumerator.hs b/src/Control/Monad/Bayes/Enumerator.hs index cd7e7e1a..18d2dd5e 100644 --- a/src/Control/Monad/Bayes/Enumerator.hs +++ b/src/Control/Monad/Bayes/Enumerator.hs @@ -32,16 +32,18 @@ where import Control.Applicative (Alternative) import Control.Arrow (second) +import Control.Monad (MonadPlus) import Control.Monad.Bayes.Class ( MonadDistribution (bernoulli, categorical, logCategorical, random), MonadFactor (..), MonadMeasure, ) -import Control.Monad.Writer +import Control.Monad.Writer (WriterT (..)) import Data.AEq (AEq, (===), (~==)) import Data.List (sortOn) import Data.Map qualified as Map import Data.Maybe (fromMaybe) +import Data.Monoid (Product (..)) import Data.Ord (Down (Down)) import Data.Vector qualified as VV import Data.Vector.Generic qualified as V diff --git a/src/Control/Monad/Bayes/Integrator.hs b/src/Control/Monad/Bayes/Integrator.hs index a38e4d8c..0c1cf5c9 100644 --- a/src/Control/Monad/Bayes/Integrator.hs +++ b/src/Control/Monad/Bayes/Integrator.hs @@ -48,6 +48,10 @@ import Numeric.Integration.TanhSinh (Result (result), trap) import Numeric.Log (Log (ln)) import Statistics.Distribution qualified as Statistics import Statistics.Distribution.Uniform qualified as Statistics +-- Prelude exports liftA2 from GHC 9.6 on, see https://github.com/haskell/core-libraries-committee/blob/main/guides/export-lifta2-prelude.md +-- import Control.Applicative further up can be removed once we don't support GHC <= 9.4 anymore + +import Prelude hiding (Applicative (..)) newtype Integrator a = Integrator {getIntegrator :: Cont Double a} deriving newtype (Functor, Applicative, Monad) diff --git a/src/Control/Monad/Bayes/Sampler/Lazy.hs b/src/Control/Monad/Bayes/Sampler/Lazy.hs index 71fcebce..a5a95e0b 100644 --- a/src/Control/Monad/Bayes/Sampler/Lazy.hs +++ b/src/Control/Monad/Bayes/Sampler/Lazy.hs @@ -7,10 +7,11 @@ -- | This is a port of the implementation of LazyPPL: https://lazyppl.bitbucket.io/ module Control.Monad.Bayes.Sampler.Lazy where +import Control.Monad (ap) import Control.Monad.Bayes.Class (MonadDistribution (random)) import Control.Monad.Bayes.Weighted (WeightedT, runWeightedT) import Control.Monad.IO.Class -import Control.Monad.Identity +import Control.Monad.Identity (Identity (runIdentity)) import Control.Monad.Trans import Numeric.Log (Log (..)) import System.Random diff --git a/src/Control/Monad/Bayes/Traced/Basic.hs b/src/Control/Monad/Bayes/Traced/Basic.hs index d2b727d1..e6167fe8 100644 --- a/src/Control/Monad/Bayes/Traced/Basic.hs +++ b/src/Control/Monad/Bayes/Traced/Basic.hs @@ -17,7 +17,7 @@ module Control.Monad.Bayes.Traced.Basic ) where -import Control.Applicative (liftA2) +import Control.Applicative (Applicative (..)) import Control.Monad.Bayes.Class ( MonadDistribution (random), MonadFactor (..), @@ -34,6 +34,10 @@ import Control.Monad.Bayes.Traced.Common import Control.Monad.Bayes.Weighted (WeightedT) import Data.Functor.Identity (Identity) import Data.List.NonEmpty as NE (NonEmpty ((:|)), toList) +-- Prelude exports liftA2 from GHC 9.6 on, see https://github.com/haskell/core-libraries-committee/blob/main/guides/export-lifta2-prelude.md +-- import Control.Applicative further up can be removed once we don't support GHC <= 9.4 anymore + +import Prelude hiding (Applicative (..)) -- | Tracing monad that records random choices made in the program. data TracedT m a = TracedT diff --git a/src/Control/Monad/Bayes/Traced/Static.hs b/src/Control/Monad/Bayes/Traced/Static.hs index fc99b327..b78225a1 100644 --- a/src/Control/Monad/Bayes/Traced/Static.hs +++ b/src/Control/Monad/Bayes/Traced/Static.hs @@ -18,7 +18,7 @@ module Control.Monad.Bayes.Traced.Static ) where -import Control.Applicative (liftA2) +import Control.Applicative (Applicative (..)) import Control.Monad.Bayes.Class ( MonadDistribution (random), MonadFactor (..), @@ -35,6 +35,10 @@ import Control.Monad.Bayes.Traced.Common import Control.Monad.Bayes.Weighted (WeightedT) import Control.Monad.Trans (MonadTrans (..)) import Data.List.NonEmpty as NE (NonEmpty ((:|)), toList) +-- Prelude exports liftA2 from GHC 9.6 on, see https://github.com/haskell/core-libraries-committee/blob/main/guides/export-lifta2-prelude.md +-- import Control.Applicative further up can be removed once we don't support GHC <= 9.4 anymore + +import Prelude hiding (Applicative (..)) -- | A tracing monad where only a subset of random choices are traced. --