Slide 1

Slide 1 text

ຊ౰͸͍͢͝ newtype !NS@LPOO IUUQTLPOOTBODPN 4MJEFTBSFBWBJMBCMFBUhttp://bit.ly/derivia
 &YBNQMFDPEFTBSFPO(JU)VCkonn/newtype-talk-five

Slide 2

Slide 2 text

ࣗݾ঺հ w ੴҪେւʢ!NS@LPOOʣ ͍ ͠ ͍ ͻ Ζ Έ w ਺ֶઐ߈ത࢜՝ఔ೥ w ਺ཧ࿦ཧֶͱܭࢉػՊֶͱ͔ w ؾ͚ͮ͹)BTLFMMྺ೥

Slide 3

Slide 3 text

ຊ౰͸͍͢͝newtype 3PMFT 4BGF[FSPDPTUDPFSDJPOT BOE%FSJWJOH7JB ʙ.POPJE&'PMEBCMF΋͋ΔΑʙ ͍͢͝ʂ

Slide 4

Slide 4 text

newtype

Slide 5

Slide 5 text

newtype newtype Foo α = Bar α newtype Id = MkId Word

Slide 6

Slide 6 text

newtype w ͨͩҰͭͷߏஙࢠͱϑΟʔϧυΛ࣋ͭσʔλܕ newtype Foo α = Bar α newtype Id = MkId Word

Slide 7

Slide 7 text

newtype w ͨͩҰͭͷߏஙࢠͱϑΟʔϧυΛ࣋ͭσʔλܕ w ಺෦දݱ͕།ҰͷϑΟʔϧυͷܕͱಉҰ newtype Foo α = Bar α newtype Id = MkId Word

Slide 8

Slide 8 text

newtype w ͨͩҰͭͷߏஙࢠͱϑΟʔϧυΛ࣋ͭσʔλܕ w ಺෦දݱ͕།ҰͷϑΟʔϧυͷܕͱಉҰ w ܕͷ্Ͱ͸۠ผ͞ΕΔ͕ɺϝϞϦ্Ͱͷදݱ ͸ಉҰͰɺϑΟʔϧυ΋ʮਖ਼֨ʯʹධՁ͞ΕΔ newtype Foo α = Bar α newtype Id = MkId Word

Slide 9

Slide 9 text

ॳ৺ऀ͋Δ͋Δ

Slide 10

Slide 10 text

ॳ৺ऀ͋Δ͋Δ ʮ;ͭ͏ͷdataએݴͱԿ͕ҧ͏ͷʁʯ

Slide 11

Slide 11 text

ॳ৺ऀ͋Δ͋Δ ʮ;ͭ͏ͷdataએݴͱԿ͕ҧ͏ͷʁʯ ʮ಺෦දݱ͕ಉ͔ͩ͡Βޮ཰తͩΑʯ

Slide 12

Slide 12 text

ॳ৺ऀ͋Δ͋Δ ʮ;ͭ͏ͷdataએݴͱԿ͕ҧ͏ͷʁʯ ʮ಺෦දݱ͕ಉ͔ͩ͡Βޮ཰తͩΑʯ ʮޮ཰·ͩͲ͏Ͱ΋͍͍͠dataͰ͍͍΍ʯ

Slide 13

Slide 13 text

ॳ৺ऀ͋Δ͋Δ ʮ;ͭ͏ͷdataએݴͱԿ͕ҧ͏ͷʁʯ ʮ಺෦දݱ͕ಉ͔ͩ͡Βޮ཰తͩΑʯ ʮޮ཰·ͩͲ͏Ͱ΋͍͍͠dataͰ͍͍΍ʯ ʮࠓ͸VOQBDLTUSJDUpFME΋͋Δ͠ʜʜʯ

Slide 14

Slide 14 text

ͦΜͳ͜ͱ͸ͳ͍

Slide 15

Slide 15 text

newtypeͷͭͷ༻్

Slide 16

Slide 16 text

newtypeͷͭͷ༻్ ࣮૷ͷӅṭ module Data.Id (Id ()) where newtype Id = MkId Word

Slide 17

Slide 17 text

newtypeͷͭͷ༻్ ࣮૷ͷӅṭ module Data.Id (Id ()) where newtype Id = MkId Word ܕͷ্Ͱ͸۠ผ Ͱ΋಺෦తʹ͸Word

Slide 18

Slide 18 text

newtypeͷͭͷ༻్ ࣮૷ͷӅṭ module Data.Id (Id ()) where newtype Id = MkId Word ܕͷ্Ͱ͸۠ผ Ͱ΋಺෦తʹ͸Word ֎෦ʹ͸σʔλߏஙࢠ MkId͸Ӆṭ

Slide 19

Slide 19 text

newtypeͷͭͷ༻్ ࣮૷ͷӅṭ ࣮૷ͷڞ༗ module Data.Id (Id ()) where newtype Id = MkId Word ܕͷ্Ͱ͸۠ผ Ͱ΋಺෦తʹ͸Word {-# LANGUAGE GeneralizedNewtypeDeriving #-} newtype Id = MkId Word deriving (Num, Eq) ֎෦ʹ͸σʔλߏஙࢠ MkId͸Ӆṭ

Slide 20

Slide 20 text

newtypeͷͭͷ༻్ ࣮૷ͷӅṭ ࣮૷ͷڞ༗ module Data.Id (Id ()) where newtype Id = MkId Word ܕͷ্Ͱ͸۠ผ Ͱ΋಺෦తʹ͸Word {-# LANGUAGE GeneralizedNewtypeDeriving #-} newtype Id = MkId Word deriving (Num, Eq) ຊདྷ͸ಋग़ෆՄͰ΋ Wordͷ࣮૷͕ڞ༗Ͱ͖Δ ֎෦ʹ͸σʔλߏஙࢠ MkId͸Ӆṭ

Slide 21

Slide 21 text

newtypeͷͭͷ༻్ ࣮૷ͷӅṭ ࣮૷ͷڞ༗ module Data.Id (Id ()) where newtype Id = MkId Word ܕͷ্Ͱ͸۠ผ Ͱ΋಺෦తʹ͸Word {-# LANGUAGE GeneralizedNewtypeDeriving #-} newtype Id = MkId Word deriving (Num, Eq) ຊདྷ͸ಋग़ෆՄͰ΋ Wordͷ࣮૷͕ڞ༗Ͱ͖Δ %FSJWJOH7JB ͰߋʹਐԽ ֎෦ʹ͸σʔλߏஙࢠ MkId͸Ӆṭ

Slide 22

Slide 22 text

newtypeͷͭͷ༻్ ࣮૷ͷӅṭ ࣮૷ͷڞ༗ ࣮૷ͷબ୒ module Data.Id (Id ()) where newtype Id = MkId Word ܕͷ্Ͱ͸۠ผ Ͱ΋಺෦తʹ͸Word {-# LANGUAGE GeneralizedNewtypeDeriving #-} newtype Id = MkId Word deriving (Num, Eq) ຊདྷ͸ಋग़ෆՄͰ΋ Wordͷ࣮૷͕ڞ༗Ͱ͖Δ %FSJWJOH7JB ͰߋʹਐԽ ֎෦ʹ͸σʔλߏஙࢠ MkId͸Ӆṭ

Slide 23

Slide 23 text

newtypeͷͭͷ༻్ ࣮૷ͷӅṭ ࣮૷ͷڞ༗ ࣮૷ͷબ୒ {-# LANGUAGE GeneralizedNewtypeDeriving #-} newtype Id = MkId Word deriving (Num, Eq) ຊདྷ͸ಋग़ෆՄͰ΋ Wordͷ࣮૷͕ڞ༗Ͱ͖Δ %FSJWJOH7JB ͰߋʹਐԽ module Data.Id (Id ()) where newtype Id = MkId Word ܕͷ্Ͱ͸۠ผ Ͱ΋಺෦తʹ͸Word ֎෦ʹ͸σʔλߏஙࢠ MkId͸Ӆṭ

Slide 24

Slide 24 text

࣮૷ͷબ୒

Slide 25

Slide 25 text

࣮૷ͷબ୒ .POPJEͱ'PMEBCMFΛྫʹ

Slide 26

Slide 26 text

ྫ୊ɿϦετͷ૸ࠪ ໰ ੔਺ͷϦετ͕༩͑ΒΕͨ࣌ɺͦͷ࠷େ஋ͱ ૯࿨ΛҰճͷ૸ࠪͰٻΊΑɻ ˞foldl͓Αͼfoldsύοέʔδ͸Έͳ͔ͬͨࣄʹ͍ͯͩ͘͠͞

Slide 27

Slide 27 text

ղ౴ྫ

Slide 28

Slide 28 text

ղ౴ྫ ৞ΈࠐΈͩʂ

Slide 29

Slide 29 text

ղ౴ྫ ৞ΈࠐΈͩʂ aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = foldr (λ a (m, s) ! (Just a `max` m, a + s)) (Nothing, 0) ˞ℕ͸*OUFHFSͷུͩͱࢥ͍ͬͯͩ͘͞

Slide 30

Slide 30 text

ղ౴ྫ ৞ΈࠐΈͩʂ aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = foldr (λ a (m, s) ! (Just a `max` m, a + s)) (Nothing, 0) Կ͔ࣅͨΑ͏ͳ͜ͱ΍ͬͯΜͳʜʜ ˞ℕ͸*OUFHFSͷུͩͱࢥ͍ͬͯͩ͘͞

Slide 31

Slide 31 text

ղ౴ྫ ৞ΈࠐΈͩʂ aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = foldr (λ a (m, s) ! (Just a `max` m, a + s)) (Nothing, 0) Կ͔ࣅͨΑ͏ͳ͜ͱ΍ͬͯΜͳʜʜ ˞ℕ͸*OUFHFSͷུͩͱࢥ͍ͬͯͩ͘͞

Slide 32

Slide 32 text

ղ౴ྫ ৞ΈࠐΈͩʂ aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = foldr (λ a (m, s) ! (Just a `max` m, a + s)) (Nothing, 0) Կ͔ࣅͨΑ͏ͳ͜ͱ΍ͬͯΜͳʜʜ ม׵ʴೋ߲ԋࢉ ˞ℕ͸*OUFHFSͷུͩͱࢥ͍ͬͯͩ͘͞

Slide 33

Slide 33 text

ղ౴ྫ ৞ΈࠐΈͩʂ aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = foldr (λ a (m, s) ! (Just a `max` m, a + s)) (Nothing, 0) Կ͔ࣅͨΑ͏ͳ͜ͱ΍ͬͯΜͳʜʜ ม׵ʴೋ߲ԋࢉ ˞ℕ͸*OUFHFSͷུͩͱࢥ͍ͬͯͩ͘͞

Slide 34

Slide 34 text

ղ౴ྫ ৞ΈࠐΈͩʂ aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = foldr (λ a (m, s) ! (Just a `max` m, a + s)) (Nothing, 0) Կ͔ࣅͨΑ͏ͳ͜ͱ΍ͬͯΜͳʜʜ ม׵ʴೋ߲ԋࢉ ୯Ґݩ ˞ℕ͸*OUFHFSͷུͩͱࢥ͍ͬͯͩ͘͞

Slide 35

Slide 35 text

ղ౴ྫ ৞ΈࠐΈͩʂ aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = foldr (λ a (m, s) ! (Just a `max` m, a + s)) (Nothing, 0) Կ͔ࣅͨΑ͏ͳ͜ͱ΍ͬͯΜͳʜʜ .POPJEͩʂ ม׵ʴೋ߲ԋࢉ ୯Ґݩ ˞ℕ͸*OUFHFSͷུͩͱࢥ͍ͬͯͩ͘͞

Slide 36

Slide 36 text

.POPJE w ࠨӈͷผͳ͘ܭࢉͰ͖ͯɺ୯Ґݩ͕͋Δ΍ͭ • max ΋ + ΋…… • ࠨ͔Β΍ͬͯ΋ӈ͔Β΍ͬͯ΋ಉ͡ • Nothing (࠷େ஋ແ͠) ͱ 0 ͕୯Ґݩ (ɛ) • ϞϊΠυม׵ʴ৞ΈࠐΈ ⤳ Foldable! x ∙ (y ∙ z) = (x ∙ y) ∙ z x ∙ ε = x = ε ∙ x

Slide 37

Slide 37 text

'PMEBCMFܕΫϥε class Foldable t where foldMap :: Monoid m 㱺 (a ! m) ! t a ! m …

Slide 38

Slide 38 text

'PMEBCMFܕΫϥε class Foldable t where foldMap :: Monoid m 㱺 (a ! m) ! t a ! m … ϞϊΠυʹม׵
 ࠨ͔Β৞ΈࠐΈ

Slide 39

Slide 39 text

'PMEBCMFܕΫϥε ͜ͷ࿮૊ΈʹNBY ΛམͱͤΕ͹Αͦ͞͏ class Foldable t where foldMap :: Monoid m 㱺 (a ! m) ! t a ! m … ϞϊΠυʹม׵
 ࠨ͔Β৞ΈࠐΈ

Slide 40

Slide 40 text

'PMEBCMFܕΫϥε ͜ͷ࿮૊ΈʹNBY ΛམͱͤΕ͹Αͦ͞͏ Monoid WordΠϯελϯε͸ߴʑҰ͔ͭ͠ॻ͚ͳ͍ʜʜ class Foldable t where foldMap :: Monoid m 㱺 (a ! m) ! t a ! m … ϞϊΠυʹม׵
 ࠨ͔Β৞ΈࠐΈ

Slide 41

Slide 41 text

'PMEBCMFܕΫϥε ͜ͷ࿮૊ΈʹNBY ΛམͱͤΕ͹Αͦ͞͏ Monoid WordΠϯελϯε͸ߴʑҰ͔ͭ͠ॻ͚ͳ͍ʜʜ ͦ͜ͰnewtypeʹΑΔ࣮૷ͷબ୒ʂ class Foldable t where foldMap :: Monoid m 㱺 (a ! m) ! t a ! m … ϞϊΠυʹม׵
 ࠨ͔Β৞ΈࠐΈ

Slide 42

Slide 42 text

Πϯελϯεྫ newtype Sum a = Sum { getSum :: a} 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

Slide 43

Slide 43 text

Πϯελϯεྫ newtype Sum a = Sum { getSum :: a} 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 ਺ͷՃ๏ʹؔ͢Δ
 ϞϊΠυ

Slide 44

Slide 44 text

Πϯελϯεྫ newtype Sum a = Sum { getSum :: a} 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 ਺ͷՃ๏ʹؔ͢Δ
 ϞϊΠυ ࠷େݶʹؔ͢Δ
 ൒܈

Slide 45

Slide 45 text

Πϯελϯεྫ newtype Sum a = Sum { getSum :: a} 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 ਺ͷՃ๏ʹؔ͢Δ
 ϞϊΠυ ࠷େݶʹؔ͢Δ
 ൒܈ (/%ʹΑΔ
 ࣮૷ͷڞ༗

Slide 46

Slide 46 text

࣮ࡍ্ͷ஫ҙ w ༗քͳܕ͔͠ϞϊΠυʹͳΒͳ͍ʂʢ࠷େখݩ͕ͳ͍ͱ୯ ҐݩʹͳΒͳ͍ͷͰʣ w ୯Ґݩͷͳ͍൒܈ʹ͸ͳΔ w ൒܈͔ΒϞϊΠυʹม׵͠ͳ͍ͱ'PMEBCMF͸࢖͑ͳ͍ʂ newtype Max a = Max a instance Ord a 㱺 Semigroup (Max a) instance Bounded a 㱺 Monoid (Max a)

Slide 47

Slide 47 text

࣮ࡍ্ͷ஫ҙ newtype Option a = Option (Maybe a) instance Semigroup a 㱺 Monoid (Option a)

Slide 48

Slide 48 text

࣮ࡍ্ͷ஫ҙ 0QUJPO͸൒܈ʹ୯ҐݩΛ෇͚଍ͯ͠ϞϊΠυʹ͢Δ newtype Option a = Option (Maybe a) instance Semigroup a 㱺 Monoid (Option a)

Slide 49

Slide 49 text

࣮ࡍ্ͷ஫ҙ 0QUJPO͸൒܈ʹ୯ҐݩΛ෇͚଍ͯ͠ϞϊΠυʹ͢Δ ʙ()$ɿ.BZCF͸੍໿ͱͯ͠.POPJEBΛཁٻʂ newtype Option a = Option (Maybe a) instance Semigroup a 㱺 Monoid (Option a) instance Monoid a 㱺 Monoid (Maybe a)

Slide 50

Slide 50 text

࣮ࡍ্ͷ஫ҙ 0QUJPO͸൒܈ʹ୯ҐݩΛ෇͚଍ͯ͠ϞϊΠυʹ͢Δ ʙ()$ɿ.BZCF͸੍໿ͱͯ͠.POPJEBΛཁٻʂ ()$ʙɿ4FNJHSPVQBʹͳΓɺ0QUJPO͸ෆཁʹʂ newtype Option a = Option (Maybe a) instance Semigroup a 㱺 Monoid (Option a) instance Monoid a 㱺 Monoid (Maybe a) instance Semigroup a 㱺 Monoid (Maybe a)

Slide 51

Slide 51 text

࣮ࡍ্ͷ஫ҙ 0QUJPO͸൒܈ʹ୯ҐݩΛ෇͚଍ͯ͠ϞϊΠυʹ͢Δ ʙ()$ɿ.BZCF͸੍໿ͱͯ͠.POPJEBΛཁٻʂ ()$ʙɿ4FNJHSPVQBʹͳΓɺ0QUJPO͸ෆཁʹʂ ͱ͸͍͑ɺϙʔλϒϧͳίʔυΛॻ͜͏ͱࢥͬͨΒ0QUJPOʹཔΔ ඞཁ͋Γʜʜɻ newtype Option a = Option (Maybe a) instance Semigroup a 㱺 Monoid (Option a) instance Monoid a 㱺 Monoid (Maybe a) instance Semigroup a 㱺 Monoid (Maybe a)

Slide 52

Slide 52 text

'PMEBCMF/FXUZQF൛ import Control.Arrow aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = fmap getMax *** getSum ○ foldMap (Just . Max &&& Sum)

Slide 53

Slide 53 text

'PMEBCMF/FXUZQF൛ ਵ෼͖ͬ͢Γʂ import Control.Arrow aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = fmap getMax *** getSum ○ foldMap (Just . Max &&& Sum)

Slide 54

Slide 54 text

'PMEBCMF/FXUZQF൛ ਵ෼͖ͬ͢Γʂ Ͱ΋Ұʑ.BY 4VNΛണ͢ͷ͸μϧ͍ͳ͋ʜʜωε τͯ͠Δ͠ʜʜ import Control.Arrow aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = fmap getMax *** getSum ○ foldMap (Just . Max &&& Sum)

Slide 55

Slide 55 text

'PMEBCMF/FXUZQF൛ ਵ෼͖ͬ͢Γʂ Ͱ΋Ұʑ.BY 4VNΛണ͢ͷ͸μϧ͍ͳ͋ʜʜωε τͯ͠Δ͠ʜʜ import Control.Arrow aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = fmap getMax *** getSum ○ foldMap (Just . Max &&& Sum) ‎;FSP$PTU$PFSDJPOT

Slide 56

Slide 56 text

4BGF;FSP$PTU $PFSDJPOTBOE3PMFT

Slide 57

Slide 57 text

4BGF;FSP$PTU $PFSDJPOTBOE3PMFT [1] Breitner, Eisenberg, Peyton Jones and Weirich, 2014 ʙOFXUZQFͷະདྷΛ੾Γ୓͍ͨେൃ໌ʙ

Slide 58

Slide 58 text

೥Ҏલͷ )BTLFMMFSͷ΅΍͖ɿ

Slide 59

Slide 59 text

͔ͨ͠ʹ࣮૷ͷબ୒ʹ OFXUZQF͸ศར͚ͩͲ͞ʜʜ

Slide 60

Slide 60 text

݁ہҰຕҰຕണͯ͠
 ͍͔ͳ͍ͱ͍͚ͳ͍͠

Slide 61

Slide 61 text

ͦ͏͢Δͱޮ཰͸
 ѱ͍͡ΌΜ

Slide 62

Slide 62 text

҆શ͔ͩΒVOTBGF$PFSDF ࢖͏ख΋͋Δ͚Ͳ

Slide 63

Slide 63 text

͋Μ·៉ྷ͡Όͳ͍ʜʜ

Slide 64

Slide 64 text

͔͠͠

Slide 65

Slide 65 text

ɹ೥ɺ OFXUZQFʹ ֵ໋͕ى͖ͨ

Slide 66

Slide 66 text

;FSP$PTU$PFSDJPO

Slide 67

Slide 67 text

;FSP$PTU$PFSDJPO import Data.Coerce (coerce) coerce :: Coercible a b 㱺 a ! b

Slide 68

Slide 68 text

;FSP$PTU$PFSDJPO w $PFSDJCMF͸಺෦දݱ͕ಉ͡ܕಉ࢜Λؔ࿈͚ͮΔܕ੍໿ import Data.Coerce (coerce) coerce :: Coercible a b 㱺 a ! b

Slide 69

Slide 69 text

;FSP$PTU$PFSDJPO w $PFSDJCMF͸಺෦දݱ͕ಉ͡ܕಉ࢜Λؔ࿈͚ͮΔܕ੍໿ w ҰݟܕΫϥε͕ͩɺ࣮ࡍʹ͸()$͕ίϯύΠϧ࣌ʹ৘ใΛੜ੒ ͠ɺউखʹΠϯελϯεΛ௥ՃͰ͖ͳ͍ import Data.Coerce (coerce) coerce :: Coercible a b 㱺 a ! b

Slide 70

Slide 70 text

;FSP$PTU$PFSDJPO w $PFSDJCMF͸಺෦දݱ͕ಉ͡ܕಉ࢜Λؔ࿈͚ͮΔܕ੍໿ w ҰݟܕΫϥε͕ͩɺ࣮ࡍʹ͸()$͕ίϯύΠϧ࣌ʹ৘ใΛੜ੒ ͠ɺউखʹΠϯελϯεΛ௥ՃͰ͖ͳ͍ w Data.Coerceͷcoerceؔ਺ͰθϩίετͷΩϟετ͕Ͱ͖Δʂ import Data.Coerce (coerce) coerce :: Coercible a b 㱺 a ! b

Slide 71

Slide 71 text

;FSP$PTU$PFSDJPO w $PFSDJCMF͸಺෦දݱ͕ಉ͡ܕಉ࢜Λؔ࿈͚ͮΔܕ੍໿ w ҰݟܕΫϥε͕ͩɺ࣮ࡍʹ͸()$͕ίϯύΠϧ࣌ʹ৘ใΛੜ੒ ͠ɺউखʹΠϯελϯεΛ௥ՃͰ͖ͳ͍ w Data.Coerceͷcoerceؔ਺ͰθϩίετͷΩϟετ͕Ͱ͖Δʂ w Ϟδϡʔϧຖʹਪ࿦ɺcoerceʹ͸σʔλߏஙࢠͷ৘ใ͕ඞཁ import Data.Coerce (coerce) coerce :: Coercible a b 㱺 a ! b

Slide 72

Slide 72 text

͜ΕΛ࢖͑͹ʜʜ import Control.Arrow aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = fmap getMax *** getSum ○ foldMap (Just . Max &&& Sum)

Slide 73

Slide 73 text

͜͏ͳΓ·͢ import Control.Arrow import Data.Coerce aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = coerce ○ foldMap (Just . Max &&& Sum)

Slide 74

Slide 74 text

͜͏ͳΓ·͢ import Control.Arrow import Data.Coerce aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = coerce ○ foldMap (Just . Max &&& Sum) ω ε τ ܕ ΋ θ ϩ ί ε τ Ͱ ม ׵ ʂ

Slide 75

Slide 75 text

͜͏ͳΓ·͢ import Control.Arrow import Data.Coerce aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = coerce ○ foldMap (Just . Max &&& Sum) coerce :: (Maybe (Max ), Sum ) → (Maybe , ) ω ε τ ܕ ΋ θ ϩ ί ε τ Ͱ ม ׵ ʂ

Slide 76

Slide 76 text

͜͏ͳΓ·͢ import Control.Arrow import Data.Coerce aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = coerce ○ foldMap (Just . Max &&& Sum) w θϩίετͳͷͰɺ૸ࠪ͸Ұճ͚ͩ coerce :: (Maybe (Max ), Sum ) → (Maybe , ) ω ε τ ܕ ΋ θ ϩ ί ε τ Ͱ ม ׵ ʂ

Slide 77

Slide 77 text

͜͏ͳΓ·͢ import Control.Arrow import Data.Coerce aggregate :: [ℕ] ! (Maybe ℕ, ℕ) aggregate = coerce ○ foldMap (Just . Max &&& Sum) w θϩίετͳͷͰɺ૸ࠪ͸Ұճ͚ͩ w લޙͷܕ͕͔ͬ͠Γܾ·͍ͬͯΔͷͰDPFSDFҰൃͰऴྃ coerce :: (Maybe (Max ), Sum ) → (Maybe , ) ω ε τ ܕ ΋ θ ϩ ί ε τ Ͱ ม ׵ ʂ

Slide 78

Slide 78 text

ωετܕͷม׵

Slide 79

Slide 79 text

ωετܕͷม׵ ͲΜͳίϯςφதͷܕ΋ม׵Ͱ͖ͯศརʂ

Slide 80

Slide 80 text

ωετܕͷม׵ ͲΜͳίϯςφதͷܕ΋ม׵Ͱ͖ͯศརʂ ຊ౰ʹʁ

Slide 81

Slide 81 text

ωετܕͷม׵ ͲΜͳίϯςφதͷܕ΋ม׵Ͱ͖ͯศརʂ ຊ౰ʹʁ newtype Down a = Down a instance Ord a 㱺 Ord (Down a) where a ≤ b = b ≤ a data Heap a minView :: Heap a ! Maybe a

Slide 82

Slide 82 text

ωετܕͷม׵ ͲΜͳίϯςφதͷܕ΋ม׵Ͱ͖ͯศརʂ ຊ౰ʹʁ newtype Down a = Down a instance Ord a 㱺 Ord (Down a) where a ≤ b = b ≤ a data Heap a minView :: Heap a ! Maybe a ٯॱΛೖΕΔ

Slide 83

Slide 83 text

ωετܕͷม׵ ͲΜͳίϯςφதͷܕ΋ม׵Ͱ͖ͯศརʂ ຊ౰ʹʁ newtype Down a = Down a instance Ord a 㱺 Ord (Down a) where a ≤ b = b ≤ a data Heap a minView :: Heap a ! Maybe a ٯॱΛೖΕΔ ώʔϓ

Slide 84

Slide 84 text

ωετܕͷม׵ ͲΜͳίϯςφதͷܕ΋ม׵Ͱ͖ͯศརʂ ຊ౰ʹʁ newtype Down a = Down a instance Ord a 㱺 Ord (Down a) where a ≤ b = b ≤ a data Heap a minView :: Heap a ! Maybe a ٯॱΛೖΕΔ ώʔϓ ࠷খݩ0

Slide 85

Slide 85 text

ωετܕͷม׵ ͲΜͳίϯςφதͷܕ΋ม׵Ͱ͖ͯศརʂ ຊ౰ʹʁ newtype Down a = Down a instance Ord a 㱺 Ord (Down a) where a ≤ b = b ≤ a data Heap a minView :: Heap a ! Maybe a ҙຯ࿦తʹ Heap aͱHeap (Down a)͸Ωϟετग़དྷͳ͍΂͖ ٯॱΛೖΕΔ ώʔϓ ࠷খݩ0

Slide 86

Slide 86 text

ͦ͜Ͱ3PMFT

Slide 87

Slide 87 text

ͦ͜Ͱ3PMFT w ͜ͷ··Ͱ͸DPFSDFͰม׵ग़དྷͯ͠·͏ʂ

Slide 88

Slide 88 text

ͦ͜Ͱ3PMFT w ͜ͷ··Ͱ͸DPFSDFͰม׵ग़དྷͯ͠·͏ʂ ghci> h = fromList [1,2,3] :: Heap Int ghci> minView (coerce h :: Heap (Down Int)) Just 1

Slide 89

Slide 89 text

ͦ͜Ͱ3PMFT w ͜ͷ··Ͱ͸DPFSDFͰม׵ग़དྷͯ͠·͏ʂ ghci> h = fromList [1,2,3] :: Heap Int ghci> minView (coerce h :: Heap (Down Int)) Just 1 Just 3Ͱ͋Δ΂͖ʂ

Slide 90

Slide 90 text

ͦ͜Ͱ3PMFT w ͜ͷ··Ͱ͸DPFSDFͰม׵ग़དྷͯ͠·͏ʂ ghci> h = fromList [1,2,3] :: Heap Int ghci> minView (coerce h :: Heap (Down Int)) Just 1 w ͦ͜Ͱ3PMFΛࢦఆɿ Just 3Ͱ͋Δ΂͖ʂ

Slide 91

Slide 91 text

ͦ͜Ͱ3PMFT w ͜ͷ··Ͱ͸DPFSDFͰม׵ग़དྷͯ͠·͏ʂ type role Heap nominal ghci> h = fromList [1,2,3] :: Heap Int ghci> minView (coerce h :: Heap (Down Int)) Just 1 w ͦ͜Ͱ3PMFΛࢦఆɿ Just 3Ͱ͋Δ΂͖ʂ

Slide 92

Slide 92 text

ͦ͜Ͱ3PMFT w ͜ͷ··Ͱ͸DPFSDFͰม׵ग़དྷͯ͠·͏ʂ type role Heap nominal ghci> h = 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Ͱ͋Δ΂͖ʂ

Slide 93

Slide 93 text

ͦ͜Ͱ3PMFT w ͜ͷ··Ͱ͸DPFSDFͰม׵ग़དྷͯ͠·͏ʂ type role Heap nominal ghci> h = 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ʹਪ࿦͞ΕΔഺ

Slide 94

Slide 94 text

ͦ͜Ͱ3PMFT w ͜ͷ··Ͱ͸DPFSDFͰม׵ग़དྷͯ͠·͏ʂ type role Heap nominal ghci> h = 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Ͱ͖ͳ͍

Slide 95

Slide 95 text

3PMFTৄࡉ

Slide 96

Slide 96 text

3PMFTৄࡉ w 3PMFʮ͜ͷܕม਺͸͜͏͍͏ౕͰ͢ʯ

Slide 97

Slide 97 text

3PMFTৄࡉ w 3PMFʮ͜ͷܕม਺͸͜͏͍͏ౕͰ͢ʯ w ࡾछɿrepresentational / nominal / phantom

Slide 98

Slide 98 text

3PMFTৄࡉ w 3PMFʮ͜ͷܕม਺͸͜͏͍͏ౕͰ͢ʯ w ࡾछɿrepresentational / nominal / phantom w SFQSʮ͜͜͸಺෦දݱ͕ಉ͡ͳΒಉ஋ʯ

Slide 99

Slide 99 text

3PMFTৄࡉ w 3PMFʮ͜ͷܕม਺͸͜͏͍͏ౕͰ͢ʯ w ࡾछɿrepresentational / nominal / phantom w SFQSʮ͜͜͸಺෦දݱ͕ಉ͡ͳΒಉ஋ʯ w OPNJOBMʮ׬શʹಉ͡ܕ͡Όͳ͍ͱͩΊʯ

Slide 100

Slide 100 text

3PMFTৄࡉ w 3PMFʮ͜ͷܕม਺͸͜͏͍͏ౕͰ͢ʯ w ࡾछɿrepresentational / nominal / phantom w SFQSʮ͜͜͸಺෦දݱ͕ಉ͡ͳΒಉ஋ʯ w OPNJOBMʮ׬શʹಉ͡ܕ͡Όͳ͍ͱͩΊʯ w QIBOUPNʮλμͷ০Γʂத਎ʹؔ܎ͳ͠ʯ

Slide 101

Slide 101 text

3PMFTৄࡉ w 3PMFʮ͜ͷܕม਺͸͜͏͍͏ౕͰ͢ʯ w ࡾछɿrepresentational / nominal / phantom w SFQSʮ͜͜͸಺෦දݱ͕ಉ͡ͳΒಉ஋ʯ w OPNJOBMʮ׬શʹಉ͡ܕ͡Όͳ͍ͱͩΊʯ w QIBOUPNʮλμͷ০Γʂத਎ʹؔ܎ͳ͠ʯ w ()$͸దٓ࠷΋ҰൠతͳSPMFΛਪ࿦ͯ͘͠ΕΔ

Slide 102

Slide 102 text

3PMFTৄࡉ w 3PMFʮ͜ͷܕม਺͸͜͏͍͏ౕͰ͢ʯ w ࡾछɿrepresentational / nominal / phantom w SFQSʮ͜͜͸಺෦දݱ͕ಉ͡ͳΒಉ஋ʯ w OPNJOBMʮ׬શʹಉ͡ܕ͡Όͳ͍ͱͩΊʯ w QIBOUPNʮλμͷ০Γʂத਎ʹؔ܎ͳ͠ʯ w ()$͸దٓ࠷΋ҰൠతͳSPMFΛਪ࿦ͯ͘͠ΕΔ w σʔλܕݻ༗ͷҙຯ࿦͸Ϣʔβ͔͠஌Βͳ͍ͷͰɺࠓճͷΑ ͏ͳέʔεͰ͸ϥΠϒϥϦ࣮૷ऀ͕ࢦఆ

Slide 103

Slide 103 text

3PMFTৄࡉ w 3PMFʮ͜ͷܕม਺͸͜͏͍͏ౕͰ͢ʯ w ࡾछɿrepresentational / nominal / phantom w SFQSʮ͜͜͸಺෦දݱ͕ಉ͡ͳΒಉ஋ʯ w OPNJOBMʮ׬શʹಉ͡ܕ͡Όͳ͍ͱͩΊʯ w QIBOUPNʮλμͷ০Γʂத਎ʹؔ܎ͳ͠ʯ w ()$͸దٓ࠷΋ҰൠతͳSPMFΛਪ࿦ͯ͘͠ΕΔ w σʔλܕݻ༗ͷҙຯ࿦͸Ϣʔβ͔͠஌Βͳ͍ͷͰɺࠓճͷΑ ͏ͳέʔεͰ͸ϥΠϒϥϦ࣮૷ऀ͕ࢦఆ w OFXUZQFߏஙࢠͷ৘ใ͕ͳ͍ͱcoerce͸ෆՄೳ

Slide 104

Slide 104 text

$PFSDJPO3PMFT·ͱΊ w DPFSDFؔ਺Λ࢖͏ͱ಺෦දݱͷಉ͡ܕ͸ωε τ͍ͯͯ͠΋θϩίετͰม׵Մೳ w OFXUZQFͷར༻͕ΑΓ҆શɾ؆୯ʹʂ w ࡉ͔ͳม׵Մೳੑ͸3PMFΛࢦఆ੍ͯ͠ޚ w ීஈ͸3PMF͸ਪ࿦͞ΕΔͷͰ໰୊ͳ͠ w ҙຯ࿦্ม׵͞ΕΔͱࠔΔʗม׵ग़དྷͯ΄͠ ͍΋ͷ͸ࣗ෼Ͱࢦఆ

Slide 105

Slide 105 text

͜Ε͜Εɺ
 ͜͏͍͏ͷཉ͔ͬͨ͠

Slide 106

Slide 106 text

͔ͯͳΜͰͳ͔ͬͨͷʁ

Slide 107

Slide 107 text

;FSP$PTU$PFSDJPOલ࢙ɿ (/%ͷड೉ w (FOFSBMJ[FE/FXUZQF%FSJWJOH (/% ͸()$ ͷࠒʹ͸طʹ͋ͬͨ w ͜ͷࠒ͸()$͸ܕγεςϜ͕߇͑໨Ͱɺશͯ ͸্ख͘ճ͍ͬͯͨ w ͦͷޙɺܕ଒΍("%5TͳͲ͕ೖΓʜʜ w ؾ෇͘ͱ(/%͸ෆ݈શʹͳ͍ͬͯͨʂ

Slide 108

Slide 108 text

(/%͸ෆ݈શ newtype Id1 a = MkId1 a newtype Id2 a = 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))

Slide 109

Slide 109 text

(/%͸ෆ݈શ newtype Id1 a = MkId1 a newtype Id2 a = 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)) (/%

Slide 110

Slide 110 text

(/%͸ෆ݈શ newtype Id1 a = MkId1 a newtype Id2 a = 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)) (/% ೚ҙͷܕؒͷΩϟετʂ

Slide 111

Slide 111 text

͜Ε͸·͍ͣʜʜ

Slide 112

Slide 112 text

(/%Λٹ͍͍ͨʜʜ

Slide 113

Slide 113 text

ʜʜͱ͍͏ܦҢͰ 3PMF͕ݱΕͨ

Slide 114

Slide 114 text

(/%͸ෆ݈શ newtype Id1 a = MkId1 a newtype Id2 a = 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))

Slide 115

Slide 115 text

(/%͸ෆ݈શ newtype Id1 a = MkId1 a newtype Id2 a = 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 Λܦ༝͢ΔΑ͏ʹ

Slide 116

Slide 116 text

(/%͸ෆ݈શ newtype Id1 a = MkId1 a newtype Id2 a = 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ʹਪ࿦

Slide 117

Slide 117 text

(/%͸ෆ݈શ newtype Id1 a = MkId1 a newtype Id2 a = 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

Slide 118

Slide 118 text

Slide 119

Slide 119 text

3PMFTͷొ৔Ͱ OFXUZQF͸
 ໾ׂΛՌͤΔΑ͏ʹ

Slide 120

Slide 120 text

໾ׂɿ

Slide 121

Slide 121 text

࣮૷ͷӅṭ

Slide 122

Slide 122 text

࣮૷ͷڞ༗

Slide 123

Slide 123 text

࣮૷ͷબ୒

Slide 124

Slide 124 text

͜Ε͕ݱࡏͷ
 ͍ · OFXUZQF

Slide 125

Slide 125 text

͔͜͜Β͸ ະདྷͷOFXUZQF ͷ࿩ ͋ͨ͠

Slide 126

Slide 126 text

OFXUZQFͷະདྷ ·ͨ͸ɺ%FSJWJOH7JB ͋ͨ͠

Slide 127

Slide 127 text

OFXUZQFͷະདྷ ·ͨ͸ɺ%FSJWJOH7JB ʙ࣮૷ͷڞ༗ͱબ୒͕Ͱ͋͏ͱ͖ʙ [2] Blöndal, Löh and Scott, 2018 ͋ͨ͠

Slide 128

Slide 128 text

%FSJWJOH7JBΑΓॊೈͳ ࣮૷ͷڞ༗

Slide 129

Slide 129 text

%FSJWJOH7JBΑΓॊೈͳ ࣮૷ͷڞ༗ w ()$͔ΒೖΔ৽ػೳ

Slide 130

Slide 130 text

%FSJWJOH7JBΑΓॊೈͳ ࣮૷ͷڞ༗ w ()$͔ΒೖΔ৽ػೳ w ݱ࣌఺Ͱ()$BMQIB͕ग़͍ͯΔ

Slide 131

Slide 131 text

%FSJWJOH7JBΑΓॊೈͳ ࣮૷ͷڞ༗ w ()$͔ΒೖΔ৽ػೳ w ݱ࣌఺Ͱ()$BMQIB͕ग़͍ͯΔ w OFXUZQFΛEFSJWJOHઅͷώϯτͱͯ͠༻͍Δ ͜ͱ͕Ͱ͖ΔΑ͏ʹͳΔ

Slide 132

Slide 132 text

ྫɿ*EͷϞϊΠυߏ଄ {-# LANGUAGE DerivingVia #-} newtype Id = MkId Word deriving (Semigroup, Monoid) via Max Word

Slide 133

Slide 133 text

ྫɿ*EͷϞϊΠυߏ଄ w લʹݟͨΑ͏ʹɺ8PSEͷϞϊΠυ࣮૷͸ෳ਺͋Δ {-# LANGUAGE DerivingVia #-} newtype Id = MkId Word deriving (Semigroup, Monoid) via Max Word

Slide 134

Slide 134 text

ྫɿ*EͷϞϊΠυߏ଄ w લʹݟͨΑ͏ʹɺ8PSEͷϞϊΠυ࣮૷͸ෳ਺͋Δ w *EͰ͸ʮҰ൪৽͍͠*E ࠷େͷ*E ΛબͿʯԋࢉΛϞϊΠυԋ ࢉͱͯ͠࢖͍͔ͨͬͨͱ͢Δ {-# LANGUAGE DerivingVia #-} newtype Id = MkId Word deriving (Semigroup, Monoid) via Max Word

Slide 135

Slide 135 text

ྫɿ*EͷϞϊΠυߏ଄ w લʹݟͨΑ͏ʹɺ8PSEͷϞϊΠυ࣮૷͸ෳ਺͋Δ w *EͰ͸ʮҰ൪৽͍͠*E ࠷େͷ*E ΛબͿʯԋࢉΛϞϊΠυԋ ࢉͱͯ͠࢖͍͔ͨͬͨͱ͢Δ w Max Word͸IdͱಉҰදݱɺ NBY ʹؔ͠ϞϊΠυ {-# LANGUAGE DerivingVia #-} newtype Id = MkId Word deriving (Semigroup, Monoid) via Max Word

Slide 136

Slide 136 text

ྫɿ*EͷϞϊΠυߏ଄ w લʹݟͨΑ͏ʹɺ8PSEͷϞϊΠυ࣮૷͸ෳ਺͋Δ w *EͰ͸ʮҰ൪৽͍͠*E ࠷େͷ*E ΛબͿʯԋࢉΛϞϊΠυԋ ࢉͱͯ͠࢖͍͔ͨͬͨͱ͢Δ w Max Word͸IdͱಉҰදݱɺ NBY ʹؔ͠ϞϊΠυ w %FSJWJOH7JB͸͜ͷ࣮૷Λࣗಈతʹ*Eʹ্࣋ͪ͛ͯ͘ΕΔʂ {-# LANGUAGE DerivingVia #-} newtype Id = MkId Word deriving (Semigroup, Monoid) via Max Word

Slide 137

Slide 137 text

%FSJWJOH7JBWT(/%

Slide 138

Slide 138 text

%FSJWJOH7JBWT(/% w %FSJWJOH7JB͸(/%ͷεʔύʔηοτ

Slide 139

Slide 139 text

%FSJWJOH7JBWT(/% w %FSJWJOH7JB͸(/%ͷεʔύʔηοτ w (/%͸แ·ΕΔҰ൪಺ଆͷܕͷ࣮૷ΛݟΔ

Slide 140

Slide 140 text

%FSJWJOH7JBWT(/% w %FSJWJOH7JB͸(/%ͷεʔύʔηοτ w (/%͸แ·ΕΔҰ൪಺ଆͷܕͷ࣮૷ΛݟΔ w %FSJWJOH7JB͸$PFSDJCMFͳ೚ҙͷܕͷ࣮ ૷ΛɺίετθϩͰ࠶ར༻͢Δ͜ͱ͕Ͱ͖Δʂ

Slide 141

Slide 141 text

%FSJWJOH7JBͷࣹఔ͸ OFXUZQFʹݶΒͳ͍

Slide 142

Slide 142 text

%FSJWJOH7JBͷࣹఔ͸ OFXUZQFʹݶΒͳ͍ w ݪ࿦จͰ͸೚ҙͷಉܕͳܕͷؒͰ࣮૷Λڞ༗ ͢Δํ๏΋ఏҊ͞Ε͍ͯΔ ˞͜ͷlಉܕz͸ਖ਼֬ʹ͸ʮ૯শతͳදݱ͕$PFSDJCMFʯͱ͍͏΍΍ڧ͍৚݅

Slide 143

Slide 143 text

%FSJWJOH7JBͷࣹఔ͸ OFXUZQFʹݶΒͳ͍ w ݪ࿦จͰ͸೚ҙͷಉܕͳܕͷؒͰ࣮૷Λڞ༗ ͢Δํ๏΋ఏҊ͞Ε͍ͯΔ ૯শϓϩάϥϛϯάͱ$PFSDJPOͷ߹Θٕͤ ˞͜ͷlಉܕz͸ਖ਼֬ʹ͸ʮ૯শతͳදݱ͕$PFSDJCMFʯͱ͍͏΍΍ڧ͍৚݅

Slide 144

Slide 144 text

%FNP +40/ม׵Πϯελϯεͷ੩తఆٛ ಉܕͳܕͷؒͰͷ࣮૷ͷڞ༗ ˞$PNQMFUFDPEFJTBWBJMBCMFBUhttp://bit.ly/derivia

Slide 145

Slide 145 text

ෳࡶͳྫ w ܕϨϕϧͰΤϯίʔυͷ࢓༷Λࢦఆ w 'SPN+40/5P+40/Ͱ࢓༷͕ڞ༗͞ΕΔ͜ͱΛ੩తʹอূ data OtherConfig = OtherConfig { otrNameOfProcess :: Maybe String , otrArgsToProcess :: [String] } deriving (Read, Show, Eq, Ord, Generic) deriving (ToJSON, FromJSON) via WithOptions '[ FieldLabelModifier '[CamelTo2 "-"] , ConstructorTagModifier '[CamelTo2 "-"] , OmitNothingFields 'True ] OtherConfig

Slide 146

Slide 146 text

ಉܕͷྫ data Blog = Blog { authors :: [Author] , articles :: [Article] } deriving (Generic) deriving (Semigroup, Monoid) via Blog `SameRepAs` ([Author], Dual [Article]) {- ghci> mconcat [Blog ["1"] ["1"], Blog ["2"] ["3","4"]] Blog {authors = ["1","2"], articles = ["3","4","1"]} -}

Slide 147

Slide 147 text

ಉܕͷྫ DPOU newtype SameRepAs a b = SameRepAs { runSameRepAs :: 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

Slide 148

Slide 148 text

%FSJWJOH7JB·ͱΊ

Slide 149

Slide 149 text

%FSJWJOH7JB·ͱΊ w ()$͔Βར༻Մೳ

Slide 150

Slide 150 text

%FSJWJOH7JB·ͱΊ w ()$͔Βར༻Մೳ w OFXUZQFΛ࢖ͬͯEFSJWJOHʹ࢖͏࣮૷Λબ୒ ग़དྷΔ

Slide 151

Slide 151 text

%FSJWJOH7JB·ͱΊ w ()$͔Βར༻Մೳ w OFXUZQFΛ࢖ͬͯEFSJWJOHʹ࢖͏࣮૷Λબ୒ ग़དྷΔ w DPFSDFͱ(FOFSJDTͱ૊Έ߹ΘͤΕ͹ɺදݱ͕ ಉ͡ͱ͸ݶΒͳ͍͕ಉܕͳܕͷ࣮૷΋ಋग़Մೳ

Slide 152

Slide 152 text

%FSJWJOH7JB·ͱΊ w ()$͔Βར༻Մೳ w OFXUZQFΛ࢖ͬͯEFSJWJOHʹ࢖͏࣮૷Λબ୒ ग़དྷΔ w DPFSDFͱ(FOFSJDTͱ૊Έ߹ΘͤΕ͹ɺදݱ͕ ಉ͡ͱ͸ݶΒͳ͍͕ಉܕͳܕͷ࣮૷΋ಋग़Մೳ w ੍໿ͰදݱͰ͖ΔಉܕͳΒଞʹ΋ద༻Մೳ

Slide 153

Slide 153 text

·ͱΊ

Slide 154

Slide 154 text

·ͱΊ

Slide 155

Slide 155 text

·ͱΊ w OFXUZQFͷ༻్͸ࡾͭ

Slide 156

Slide 156 text

·ͱΊ w OFXUZQFͷ༻్͸ࡾͭ w ࣮૷ͷӅṭʗ࣮૷ͷڞ༗ʗ࣮૷ͷબ୒

Slide 157

Slide 157 text

·ͱΊ w OFXUZQFͷ༻్͸ࡾͭ w ࣮૷ͷӅṭʗ࣮૷ͷڞ༗ʗ࣮૷ͷબ୒ w %BUB$PFSDFΛ࢖͏ͱ಺෦දݱ͕ಉ͡ܕಉ࢜Λθϩ ίετͰΩϟετՄೳ

Slide 158

Slide 158 text

·ͱΊ w OFXUZQFͷ༻్͸ࡾͭ w ࣮૷ͷӅṭʗ࣮૷ͷڞ༗ʗ࣮૷ͷબ୒ w %BUB$PFSDFΛ࢖͏ͱ಺෦දݱ͕ಉ͡ܕಉ࢜Λθϩ ίετͰΩϟετՄೳ w OFXUZQFͷग़ੈ͸͔͜͜Β࢝·ͬͨ

Slide 159

Slide 159 text

·ͱΊ w OFXUZQFͷ༻్͸ࡾͭ w ࣮૷ͷӅṭʗ࣮૷ͷڞ༗ʗ࣮૷ͷબ୒ w %BUB$PFSDFΛ࢖͏ͱ಺෦දݱ͕ಉ͡ܕಉ࢜Λθϩ ίετͰΩϟετՄೳ w OFXUZQFͷग़ੈ͸͔͜͜Β࢝·ͬͨ w ෳ߹ܕ΋3PMFਪ࿦ɾḼऍͰద੾ʹѻ͑Δ

Slide 160

Slide 160 text

·ͱΊ w OFXUZQFͷ༻్͸ࡾͭ w ࣮૷ͷӅṭʗ࣮૷ͷڞ༗ʗ࣮૷ͷબ୒ w %BUB$PFSDFΛ࢖͏ͱ಺෦දݱ͕ಉ͡ܕಉ࢜Λθϩ ίετͰΩϟετՄೳ w OFXUZQFͷग़ੈ͸͔͜͜Β࢝·ͬͨ w ෳ߹ܕ΋3PMFਪ࿦ɾḼऍͰద੾ʹѻ͑Δ w ()$͔Β%FSJWJOH7JBͰOFXUZQFʹΑΓ
 ಋग़અΛΧελϚΠζՄೳʹʂ

Slide 161

Slide 161 text

ࢀߟจݙ 1. J. Breitner, R. A. Eisenberg, S. P. Jones 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.

Slide 162

Slide 162 text

ޚਗ਼ௌ
 ͋Γ͕ͱ͏͍͟͝·ͨ͠

Slide 163

Slide 163 text

"OZ2VFTUJPO w OFXUZQFͷ༻్͸ࡾͭ w ࣮૷ͷӅṭʗ࣮૷ͷڞ༗ʗ࣮૷ͷબ୒ w %BUB$PFSDFΛ࢖͏ͱ಺෦දݱ͕ಉ͡ܕಉ࢜Λθϩ ίετͰΩϟετՄೳ w OFXUZQFͷग़ੈ͸͔͜͜Β࢝·ͬͨ w ෳ߹ܕ΋3PMFਪ࿦ɾḼऍͰద੾ʹѻ͑Δ w ()$͔Β%FSJWJOH7JBͰOFXUZQFʹΑΓ
 ಋग़અΛΧελϚΠζՄೳʹʂ

Slide 164

Slide 164 text

͓·͚

Slide 165

Slide 165 text

ͳͥ.POPJEͱ'PMEBCMF͸
 ஥͕͍͍ͷ͔ʁ w 'PMEBCMFͷ࠷খఆٛ w ࣮͸͜Ε͸ࣗ༝ϞϊΠυͷීวੑͷҰ෦͕༝དྷ class Foldable t where foldMap :: Monoid m 㱺 (a ! m) ! t a ! m

Slide 166

Slide 166 text

7 ↵ M ↵ ' [ · ] 9! 7QH/JT ' AAAHwnicjVRNj9xEEK0dPiYMkGSBAxKXhk2iRHIGT0gEAs1qBQhxiZQPNok0HlYeu2fHGdtt3D1f6/WBK3+AAyeQEEL8DC78AQ75CYhjkLhw4HXZm9ld7c7G1tjdVe9Vvarq8SCLI21c98la44UXX3q5ee6V1quvvX7+wsX1Nx5oNckDuR2oWOWPBr6WcZTKbROZWD7Kcukng1g+HIw/s/6HU5nrSKVfmUUm+4m/m0bDKPANTDvra794A7kbpYWJxntZFJhJ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5SBWFSTBCMF w 5SBWFSTBCMF͸ࣗ༝ϞϊΠυͱ'PMEBCMFͷதؒ w USBWFSTF͸ࣗ༝ϞϊΠυͳΒ؆୯ʹॻ͚Δ class (Pointed f, Foldable f, ∀a. Monoid (f a)) 㱺 FreeMonoid f instance (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