Add an instance for tagging values

This commit is contained in:
Taylor Fausak 2022-10-01 13:52:31 +00:00 committed by GitHub
parent 30284b95c5
commit 7c5226d034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import qualified Data.Map as Map
import qualified Data.Ratio as Ratio
import qualified Data.Sequence as Seq
import qualified Data.Set as Set
import qualified Data.Tagged as Tagged
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Data.Text.Lazy as LazyText
@ -1272,6 +1273,11 @@ instance From.From Time.NominalDiffTime Time.CalendarDiffTime where
instance From.From Time.ZonedTime Time.UTCTime where
from = Time.zonedTimeToUTC
-- Tagged
-- | Uses @coerce@. Essentially the same as 'Tagged.Tagged'.
instance From.From a (Tagged.Tagged t a)
--
realFloatToRational ::

View File

@ -20,6 +20,7 @@ import qualified Data.Map as Map
import qualified Data.Ratio as Ratio
import qualified Data.Sequence as Seq
import qualified Data.Set as Set
import qualified Data.Tagged as Tagged
import qualified Data.Text as Text
import qualified Data.Text.Lazy as LazyText
import qualified Data.Time as Time
@ -2070,6 +2071,11 @@ spec = describe "Witch" $ do
it "works" $ do
f (Time.ZonedTime (Time.LocalTime (Time.ModifiedJulianDay 0) (Time.TimeOfDay 0 0 0)) Time.utc) `shouldBe` Time.UTCTime (Time.ModifiedJulianDay 0) 0
describe "From a (Tagged t a)" $ do
let f = Witch.from @Bool @(Tagged.Tagged () Bool)
it "works" $ do
f False `shouldBe` Tagged.Tagged False
newtype Age
= Age Int.Int8
deriving (Eq, Show)

View File

@ -26,6 +26,7 @@ common library
, base >= 4.10 && < 4.18
, bytestring >= 0.10.8 && < 0.12
, containers >= 0.5.10 && < 0.7
, tagged >= 0.8.6 && < 0.9
, text >= 1.2.3 && < 1.3 || >= 2.0 && < 2.1
, time >= 1.9.1 && < 1.13
default-language: Haskell2010