Id = MkId Word ܕͷ্Ͱ۠ผ Ͱ෦తʹWord {-# LANGUAGE GeneralizedNewtypeDeriving #-} newtype Id = MkId Word deriving (Num, Eq) ຊདྷಋग़ෆՄͰ Wordͷ࣮͕ڞ༗Ͱ͖Δ %FSJWJOH7JB ͰߋʹਐԽ ֎෦ʹσʔλߏஙࢠ MkIdӅṭ
= MkId Word deriving (Num, Eq) ຊདྷಋग़ෆՄͰ Wordͷ࣮͕ڞ༗Ͱ͖Δ %FSJWJOH7JB ͰߋʹਐԽ module Data.Id (Id ()) where newtype Id = MkId Word ܕͷ্Ͱ۠ผ Ͱ෦తʹWord ֎෦ʹσʔλߏஙࢠ MkIdӅṭ
deriving (Num, Integral) instance Num a 㱺 Monoid (Sum a) where (<>) = (+); ε = 0 newtype Max a = Max { getMax :: a } deriving (Num, Integral, Ord) instance Ord a 㱺 Semigroup (Max a) where (<>) = max
deriving (Num, Integral) instance Num a 㱺 Monoid (Sum a) where (<>) = (+); ε = 0 newtype Max a = Max { getMax :: a } deriving (Num, Integral, Ord) instance Ord a 㱺 Semigroup (Max a) where (<>) = max ͷՃ๏ʹؔ͢Δ ϞϊΠυ
deriving (Num, Integral) instance Num a 㱺 Monoid (Sum a) where (<>) = (+); ε = 0 newtype Max a = Max { getMax :: a } deriving (Num, Integral, Ord) instance Ord a 㱺 Semigroup (Max a) where (<>) = max ͷՃ๏ʹؔ͢Δ ϞϊΠυ ࠷େݶʹؔ͢Δ ܈
deriving (Num, Integral) instance Num a 㱺 Monoid (Sum a) where (<>) = (+); ε = 0 newtype Max a = Max { getMax :: a } deriving (Num, Integral, Ord) instance Ord a 㱺 Semigroup (Max a) where (<>) = max ͷՃ๏ʹؔ͢Δ ϞϊΠυ ࠷େݶʹؔ͢Δ ܈ (/%ʹΑΔ ࣮ͷڞ༗
fromList [1,2,3] :: Heap Int ghci> minView (coerce h :: Heap (Down Int)) Just 1 w ͦ͜Ͱ3PMFΛࢦఆɿ ghci> minView (coerce h :: Heap (Down Int)) error: Couldn't match type ‘Int’ with ‘Down Int’ Just 3Ͱ͋Δ͖ʂ
fromList [1,2,3] :: Heap Int ghci> minView (coerce h :: Heap (Down Int)) Just 1 w ͦ͜Ͱ3PMFΛࢦఆɿ ghci> minView (coerce h :: Heap (Down Int)) error: Couldn't match type ‘Int’ with ‘Down Int’ Just 3Ͱ͋Δ͖ʂ w σʔλߏஙࢠΛ࿐ग़͠ͳ͚ΕɺଞͷϞδϡʔϧͰOPNJOBMʹਪ͞ΕΔഺ
fromList [1,2,3] :: Heap Int ghci> minView (coerce h :: Heap (Down Int)) Just 1 w ͦ͜Ͱ3PMFΛࢦఆɿ ghci> minView (coerce h :: Heap (Down Int)) error: Couldn't match type ‘Int’ with ‘Down Int’ Just 3Ͱ͋Δ͖ʂ w σʔλߏஙࢠΛ࿐ग़͠ͳ͚ΕɺଞͷϞδϡʔϧͰOPNJOBMʹਪ͞ΕΔഺ w OFXUZQFߏஙࢠͷใΛJNQPSU͠ͳ͍ͱDPFSDFͰ͖ͳ͍
SFQSʮ͜͜෦දݱ͕ಉ͡ͳΒಉʯ w OPNJOBMʮશʹಉ͡ܕ͡Όͳ͍ͱͩΊʯ w QIBOUPNʮλμͷ০Γʂதʹؔͳ͠ʯ w ()$దٓ࠷ҰൠతͳSPMFΛਪͯ͘͠ΕΔ w σʔλܕݻ༗ͷҙຯϢʔβ͔͠Βͳ͍ͷͰɺࠓճͷΑ ͏ͳέʔεͰϥΠϒϥϦ࣮ऀ͕ࢦఆ w OFXUZQFߏஙࢠͷใ͕ͳ͍ͱcoerceෆՄೳ
= MkId2 (Id1 a) deriving (UnsafeCast b) type family Discern a b type instance Discern (Id1 a) b = a type instance Discern (Id2 a) b = b class UnsafeCast to from where unsafe :: from ! Discern from to instance UnsafeCast b (Id1 a) where unsafe (MkId1 x) = x unsafeCoerce :: a ! b unsafeCoerce x = unsafe (MkId2 (MkId1 x))
= MkId2 (Id1 a) deriving (UnsafeCast b) type family Discern a b type instance Discern (Id1 a) b = a type instance Discern (Id2 a) b = b class UnsafeCast to from where unsafe :: from ! Discern from to instance UnsafeCast b (Id1 a) where unsafe (MkId1 x) = x unsafeCoerce :: a ! b unsafeCoerce x = unsafe (MkId2 (MkId1 x)) (/%
= MkId2 (Id1 a) deriving (UnsafeCast b) type family Discern a b type instance Discern (Id1 a) b = a type instance Discern (Id2 a) b = b class UnsafeCast to from where unsafe :: from ! Discern from to instance UnsafeCast b (Id1 a) where unsafe (MkId1 x) = x unsafeCoerce :: a ! b unsafeCoerce x = unsafe (MkId2 (MkId1 x)) (/% ҙͷܕؒͷΩϟετʂ
= MkId2 (Id1 a) deriving (UnsafeCast b) type family Discern a b type instance Discern (Id1 a) b = a type instance Discern (Id2 a) b = b class UnsafeCast to from where unsafe :: from ! Discern from to instance UnsafeCast b (Id1 a) where unsafe (MkId1 x) = x unsafeCoerce :: a ! b unsafeCoerce x = unsafe (MkId2 (MkId1 x))
= MkId2 (Id1 a) deriving (UnsafeCast b) type family Discern a b type instance Discern (Id1 a) b = a type instance Discern (Id2 a) b = b class UnsafeCast to from where unsafe :: from ! Discern from to instance UnsafeCast b (Id1 a) where unsafe (MkId1 x) = x unsafeCoerce :: a ! b unsafeCoerce x = unsafe (MkId2 (MkId1 x)) (/%DPFSDF Λܦ༝͢ΔΑ͏ʹ
= MkId2 (Id1 a) deriving (UnsafeCast b) type family Discern a b type instance Discern (Id1 a) b = a type instance Discern (Id2 a) b = b class UnsafeCast to from where unsafe :: from ! Discern from to instance UnsafeCast b (Id1 a) where unsafe (MkId1 x) = x unsafeCoerce :: a ! b unsafeCoerce x = unsafe (MkId2 (MkId1 x)) (/%DPFSDF Λܦ༝͢ΔΑ͏ʹ ()$ݡ͍ͷͰ BΛOPNJOBMʹਪ
= MkId2 (Id1 a) deriving (UnsafeCast b) type family Discern a b type instance Discern (Id1 a) b = a type instance Discern (Id2 a) b = b class UnsafeCast to from where unsafe :: from ! Discern from to instance UnsafeCast b (Id1 a) where unsafe (MkId1 x) = x unsafeCoerce :: a ! b unsafeCoerce x = unsafe (MkId2 (MkId1 x)) (/%DPFSDF Λܦ༝͢ΔΑ͏ʹ ()$ݡ͍ͷͰ BΛOPNJOBMʹਪ 3FKFDU
WordIdͱಉҰදݱɺ NBY ʹؔ͠ϞϊΠυ w %FSJWJOH7JB͜ͷ࣮Λࣗಈతʹ*Eʹ্࣋ͪ͛ͯ͘ΕΔʂ {-# LANGUAGE DerivingVia #-} newtype Id = MkId Word deriving (Semigroup, Monoid) via Max Word
:: a } type Iso a b = (Generic a, Generic b, Coercible (Rep a ()) (Rep b ())) instance (Semigroup b, Iso a b) 㱺 Semigroup (SameRepAs a b) where SameRepAs a <> SameRepAs b = ... instance (Monoid b, Iso a b) 㱺 Monoid (SameRepAs a b) where mempty = SameRepAs $ toA mempty where toA :: b -> a toA = to . (coerce :: Rep b () -> Rep a ()) . from
and S. Weirich, Safe Zero-cost Coercions for Haskell, ICFP 2014. 2. Baldur Blöndal, Andres Löh and Ryan Scott, Deriving Via: How to Turn Hand-Written Instances into an Anti-Pattern, ICFP18.
' <latexit sha1_base64="tdNbhyHmLM0k2MhCNVTaF9VDoQE=">AAAHwnicjVRNj9xEEK0dPiYMkGSBAxKXhk2iRHIGT0gEAs1qBQhxiZQPNok0HlYeu2fHGdtt3D1f6/WBK3+AAyeQEEL8DC78AQ75CYhjkLhw4HXZm9ld7c7G1tjdVe9Vvarq8SCLI21c98la44UXX3q5ee6V1quvvX7+wsX1Nx5oNckDuR2oWOWPBr6WcZTKbROZWD7Kcukng1g+HIw/s/6HU5nrSKVfmUUm+4m/m0bDKPANTDvra794A7kbpYWJxntZFJhJLsuWl/gmj+aiV7/VUGA1EqkKpXYE0k6SVGiZdTvtW0HiiFzNqm2Q9EXREmL/6he5lGJ4bV8UNtrImGJYesLz42zkl+IKEIl13i49j/EVtHbDVn7S8jIQe9c3nTD3Z30BGFBChruSlfT0zM8cf2KUM1Sp6Xo6yKPM6GhPQsQlb+rn2Si6VApkAtdeS+6SVhzilZbYg8wgVM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ance (Pointed f, Foldable f, ∀a. Monoid (f a)) 㱺 FreeMonoid f fold :: (FreeMonoid f) 㱺 (a ! b ! b) ! b ! f a ! b fold g n xs = appEndo (foldMap (Endo . g) xs) n traverseF :: (FreeMonoid f, Applicative t) 㱺 (a ! t b) ! f a ! t (f b) traverseF f = fold (λa tb ! (<>) <$> (iota <$> f a) <*> tb) (pure mempty) ͔ΒೖΔ QuantifiedConstraints $PNQMFUFDPEFɿsrc/Data/Foldable/Monoid.hs