diff --git a/singletons.cabal b/singletons.cabal index 519bb0a9..60ab9b84 100644 --- a/singletons.cabal +++ b/singletons.cabal @@ -120,7 +120,9 @@ library Data.Singletons.Prelude.List.Internal Data.Singletons.Prelude.List.Internal.Disambiguation Data.Singletons.Prelude.Monad.Internal + Data.Singletons.Prelude.Ord.Disambiguation Data.Singletons.Prelude.Semigroup.Internal + Data.Singletons.Prelude.Semigroup.Internal.Disambiguation Data.Singletons.Promote Data.Singletons.Promote.Monad Data.Singletons.Promote.Eq diff --git a/src/Data/Singletons/Prelude/Foldable.hs b/src/Data/Singletons/Prelude/Foldable.hs index e86b9ee8..64868089 100644 --- a/src/Data/Singletons/Prelude/Foldable.hs +++ b/src/Data/Singletons/Prelude/Foldable.hs @@ -129,6 +129,7 @@ import Data.Singletons.Prelude.Semigroup.Internal , LastSym0, LastSym1, SLast , ProductSym0(..), ProductSym1, SProduct , SumSym0(..), SumSym1, SSum ) +import Data.Singletons.Prelude.Semigroup.Internal.Disambiguation import Data.Singletons.Promote import Data.Singletons.Single import Data.Singletons.TypeLits.Internal diff --git a/src/Data/Singletons/Prelude/Ord/Disambiguation.hs b/src/Data/Singletons/Prelude/Ord/Disambiguation.hs new file mode 100644 index 00000000..c32648f9 --- /dev/null +++ b/src/Data/Singletons/Prelude/Ord/Disambiguation.hs @@ -0,0 +1,36 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE UndecidableInstances #-} + +----------------------------------------------------------------------------- +-- | +-- Module : Data.Singletons.Prelude.Ord.Disambiguation +-- Copyright : (C) 2019 Ryan Scott +-- License : BSD-style (see LICENSE) +-- Maintainer : Ryan Scott +-- Stability : experimental +-- Portability : non-portable +-- +-- TODO RGS +-- +---------------------------------------------------------------------------- + +module Data.Singletons.Prelude.Ord.Disambiguation where + +import Data.Singletons.Prelude.Ord +import Data.Singletons.Single + +-- We need these in Data.Singletons.Prelude.Semigroup, as we need to promote +-- code that simultaneously uses the Min/Max constructors and the min/max +-- functions, which have clashing defunctionalization symbol names. Our +-- workaround is to simply define synonyms for min/max and use those instead. +$(singletons [d| + min_, max_ :: Ord a => a -> a -> a + min_ = min + max_ = max + |]) diff --git a/src/Data/Singletons/Prelude/Semigroup.hs b/src/Data/Singletons/Prelude/Semigroup.hs index cdbc88cb..16c87b1f 100644 --- a/src/Data/Singletons/Prelude/Semigroup.hs +++ b/src/Data/Singletons/Prelude/Semigroup.hs @@ -80,6 +80,7 @@ import Data.Singletons.Prelude.Monoid hiding import Data.Singletons.Prelude.Num import Data.Singletons.Prelude.Ord hiding (MinSym0, MinSym1, MaxSym0, MaxSym1) +import Data.Singletons.Prelude.Ord.Disambiguation import Data.Singletons.Prelude.Semigroup.Internal import Data.Singletons.Prelude.Show import Data.Singletons.Prelude.Traversable diff --git a/src/Data/Singletons/Prelude/Semigroup/Internal.hs b/src/Data/Singletons/Prelude/Semigroup/Internal.hs index 3aa1ada7..de7345a7 100644 --- a/src/Data/Singletons/Prelude/Semigroup/Internal.hs +++ b/src/Data/Singletons/Prelude/Semigroup/Internal.hs @@ -47,7 +47,6 @@ import Data.Singletons.Prelude.Instances import Data.Singletons.Prelude.Monad.Internal import Data.Singletons.Prelude.Num import Data.Singletons.Prelude.Ord hiding (MinSym0, MinSym1, MaxSym0, MaxSym1) -import Data.Singletons.Promote import Data.Singletons.Single import Data.Singletons.TypeLits.Internal import Data.Singletons.Util @@ -231,52 +230,3 @@ instance SSemigroup Symbol where ex = someSymbolVal $ T.unpack $ a <> b in case ex of SomeSymbol (_ :: Proxy ab) -> unsafeCoerce (SSym :: Sing ab) - --- We need these in Data.Singletons.Prelude.Semigroup, as we need to promote --- code that simultaneously uses the Min/Max constructors and the min/max --- functions, which have clashing defunctionalization symbol names. Our --- workaround is to simply define synonyms for min/max and use those instead. -min_, max_ :: Ord a => a -> a -> a -min_ = min -max_ = max - -type Min_ x y = Min x y -type Max_ x y = Max x y -$(genDefunSymbols [''Min_, ''Max_]) - -sMin_ :: forall a (x :: a) (y :: a). SOrd a => Sing x -> Sing y -> Sing (x `Min_` y) -sMin_ = sMin - -sMax_ :: forall a (x :: a) (y :: a). SOrd a => Sing x -> Sing y -> Sing (x `Max_` y) -sMax_ = sMax - --- We need these in Data.Singletons.Prelude.Foldable. -all_ :: Bool -> All -all_ = All - -any_ :: Bool -> Any -any_ = Any - -sum_ :: a -> Sum a -sum_ = Sum - -product_ :: a -> Product a -product_ = Product - -type All_ a = 'All a -type Any_ a = 'Any a -type Sum_ a = 'Sum a -type Product_ a = 'Product a -$(genDefunSymbols [''All_, ''Any_, ''Sum_, ''Product_]) - -sAll_ :: forall (x :: Bool). Sing x -> Sing (All_ x) -sAll_ = SAll - -sAny_ :: forall (x :: Bool). Sing x -> Sing (Any_ x) -sAny_ = SAny - -sSum_ :: forall a (x :: a). Sing x -> Sing (Sum_ x) -sSum_ = SSum - -sProduct_ :: forall a (x :: a). Sing x -> Sing (Product_ x) -sProduct_ = SProduct diff --git a/src/Data/Singletons/Prelude/Semigroup/Internal/Disambiguation.hs b/src/Data/Singletons/Prelude/Semigroup/Internal/Disambiguation.hs new file mode 100644 index 00000000..afa1ba92 --- /dev/null +++ b/src/Data/Singletons/Prelude/Semigroup/Internal/Disambiguation.hs @@ -0,0 +1,42 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE UndecidableInstances #-} + +----------------------------------------------------------------------------- +-- | +-- Module : Data.Singletons.Prelude.Semigroup.Internal.Disambiguation +-- Copyright : (C) 2019 Ryan Scott +-- License : BSD-style (see LICENSE) +-- Maintainer : Ryan Scott +-- Stability : experimental +-- Portability : non-portable +-- +-- TODO RGS +-- +---------------------------------------------------------------------------- + +module Data.Singletons.Prelude.Semigroup.Internal.Disambiguation where + +import Data.Semigroup +import Data.Singletons.Prelude.Semigroup.Internal +import Data.Singletons.Single + +-- We need these in Data.Singletons.Prelude.Foldable. +$(singletons [d| + all_ :: Bool -> All + all_ = All + + any_ :: Bool -> Any + any_ = Any + + sum_ :: a -> Sum a + sum_ = Sum + + product_ :: a -> Product a + product_ = Product + |])