on master help sign in
ToSample instances for tuples.
commite5259358db9b4a89f03f0468b9d94b1f154c3aba authorMatthias Fischmann <mf@zerobuzz.net> dateWed 16 Sep 2015, 11:35 (11 years ago) parent81e08f3
1 file changed+87
servant-docs/src/Servant/Docs/Internal.hs+87
servant-docs/src/Servant/Docs/Internal.hs+87
@@ -919,3 +919,90 @@ instance HasDocs sublayout => HasDocs (HttpVersion :> sublayout) where
919919instance HasDocs sublayout => HasDocs (Vault :> sublayout) where
920920 docsFor Proxy ep =
921921 docsFor (Proxy :: Proxy sublayout) ep
922+
923+
924+-- polymorphic 'ToSample' instances
925+
926+instance ( ToSample a a
927+ , ToSample b b
928+ ) => ToSample (a, b) (a, b) where
929+ toSample _ = (,)
930+ <$> toSample (Proxy :: Proxy a)
931+ <*> toSample (Proxy :: Proxy b)
932+ toSamples _ = render
933+ <$> toSamples (Proxy :: Proxy a)
934+ <*> toSamples (Proxy :: Proxy b)
935+ where render (ta, va) (tb, vb)
936+ = ("(" <> ta <>
937+ ", " <> tb <>
938+ ")"
939+ , (va, vb))
940+
941+instance ( ToSample a a
942+ , ToSample b b
943+ , ToSample c c
944+ ) => ToSample (a, b, c) (a, b, c) where
945+ toSample _ = (,,)
946+ <$> toSample (Proxy :: Proxy a)
947+ <*> toSample (Proxy :: Proxy b)
948+ <*> toSample (Proxy :: Proxy c)
949+ toSamples _ = render
950+ <$> toSamples (Proxy :: Proxy a)
951+ <*> toSamples (Proxy :: Proxy b)
952+ <*> toSamples (Proxy :: Proxy c)
953+ where render (ta, va) (tb, vb) (tc, vc)
954+ = ("(" <> ta <>
955+ ", " <> tb <>
956+ ", " <> tc <>
957+ ")"
958+ , (va, vb, vc))
959+
960+instance ( ToSample a a
961+ , ToSample b b
962+ , ToSample c c
963+ , ToSample d d
964+ ) => ToSample (a, b, c, d) (a, b, c, d) where
965+ toSample _ = (,,,)
966+ <$> toSample (Proxy :: Proxy a)
967+ <*> toSample (Proxy :: Proxy b)
968+ <*> toSample (Proxy :: Proxy c)
969+ <*> toSample (Proxy :: Proxy d)
970+ toSamples _ = render
971+ <$> toSamples (Proxy :: Proxy a)
972+ <*> toSamples (Proxy :: Proxy b)
973+ <*> toSamples (Proxy :: Proxy c)
974+ <*> toSamples (Proxy :: Proxy d)
975+ where render (ta, va) (tb, vb) (tc, vc) (td, vd)
976+ = ("(" <> ta <>
977+ ", " <> tb <>
978+ ", " <> tc <>
979+ ", " <> td <>
980+ ")"
981+ , (va, vb, vc, vd))
982+
983+instance ( ToSample a a
984+ , ToSample b b
985+ , ToSample c c
986+ , ToSample d d
987+ , ToSample e e
988+ ) => ToSample (a, b, c, d, e) (a, b, c, d, e) where
989+ toSample _ = (,,,,)
990+ <$> toSample (Proxy :: Proxy a)
991+ <*> toSample (Proxy :: Proxy b)
992+ <*> toSample (Proxy :: Proxy c)
993+ <*> toSample (Proxy :: Proxy d)
994+ <*> toSample (Proxy :: Proxy e)
995+ toSamples _ = render
996+ <$> toSamples (Proxy :: Proxy a)
997+ <*> toSamples (Proxy :: Proxy b)
998+ <*> toSamples (Proxy :: Proxy c)
999+ <*> toSamples (Proxy :: Proxy d)
1000+ <*> toSamples (Proxy :: Proxy e)
1001+ where render (ta, va) (tb, vb) (tc, vc) (td, vd) (te, ve)
1002+ = ("(" <> ta <>
1003+ ", " <> tb <>
1004+ ", " <> tc <>
1005+ ", " <> td <>
1006+ ", " <> te <>
1007+ ")"
1008+ , (va, vb, vc, vd, ve))