-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move max_, min_, all_, any_, sum_, and product_ to *.Disambiguation m…
…odules This moves `max_` and `min_` to `D.S.Prelude.Ord.Disambiguation`, and `all_`, `any_`, `sum_`, and `product_` to `D.S.Prelude.Semigroup.Internal.Disambiguation`. This has two benefits: 1. This brings their treatment in line with existing precedent, as there is already a `D.S.Prelude.List.Internal.Disambiguation` module. 2. The defunctionalization symbols used on the right-hand sides of `Max_` and `Min_` no longer clash with other definitions in `D.S.Prelude.Semigroup.Internal`, so they can now be defined using Template Haskell, which cuts out quite a bit of boilerplate.
- Loading branch information
1 parent
e24d655
commit d06c203
Showing
6 changed files
with
82 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Data/Singletons/Prelude/Semigroup/Internal/Disambiguation.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|]) |