git.iko.soy/typeable/servant
on master help sign in
Remove redundant second argument of ToSample class
0082d2bNickolay Kudasov
servant-docs/example/greet.hs+2−2
@@ -53,13 +53,13 @@ instance ToParam (MatrixParam "lang" String) where
53 "Get the greeting message selected language. Default is en."
53 "Get the greeting message selected language. Default is en."
54 Normal
54 Normal
55
55
56−instance ToSample Greet Greet where
56+instance ToSample Greet where
57 toSamples _ =
57 toSamples _ =
58 [ ("If you use ?capital=true", Greet "HELLO, HASKELLER")
58 [ ("If you use ?capital=true", Greet "HELLO, HASKELLER")
59 , ("If you use ?capital=false", Greet "Hello, haskeller")
59 , ("If you use ?capital=false", Greet "Hello, haskeller")
60 ]
60 ]
61
61
62−instance ToSample Int Int where
62+instance ToSample Int where
63 toSamples _ = singleSample 1729
63 toSamples _ = singleSample 1729
64
64
65-- We define some introductory sections, these will appear at the top of the
65-- We define some introductory sections, these will appear at the top of the
servant-docs/src/Servant/Docs/Internal.hs+46−49
@@ -403,13 +403,13 @@ class HasDocs layout where
403-- 'toSample': it lets you specify different responses along with
403-- 'toSample': it lets you specify different responses along with
404-- some context (as 'Text') that explains when you're supposed to
404-- some context (as 'Text') that explains when you're supposed to
405-- get the corresponding response.
405-- get the corresponding response.
406−class ToSample a b | a -> b where
406+class ToSample a where
407− toSamples :: Proxy a -> [(Text, b)]
407+ toSamples :: Proxy a -> [(Text, a)]
408− default toSamples :: (Generic a, Generic b, GToSample (Rep a) (Rep b)) => Proxy a -> [(Text, b)]
408+ default toSamples :: (Generic a, GToSample (Rep a)) => Proxy a -> [(Text, a)]
409 toSamples = defaultSamples
409 toSamples = defaultSamples
410
410
411-- | Sample input or output (if there is at least one).
411-- | Sample input or output (if there is at least one).
412−toSample :: forall a b. ToSample a b => Proxy a -> Maybe b
412+toSample :: forall a. ToSample a => Proxy a -> Maybe a
413toSample _ = snd <$> listToMaybe (toSamples (Proxy :: Proxy a))
413toSample _ = snd <$> listToMaybe (toSamples (Proxy :: Proxy a))
414
414
415-- | No samples.
415-- | No samples.
@@ -425,22 +425,22 @@ samples :: [a] -> [(Text, a)]
425samples = map ("",)
425samples = map ("",)
426
426
427-- | Default sample Generic-based inputs/outputs.
427-- | Default sample Generic-based inputs/outputs.
428−defaultSamples :: forall a b. (Generic a, Generic b, GToSample (Rep a) (Rep b)) => Proxy a -> [(Text, b)]
428+defaultSamples :: forall a. (Generic a, GToSample (Rep a)) => Proxy a -> [(Text, a)]
429defaultSamples _ = Omega.runOmega $ second to <$> gtoSamples (Proxy :: Proxy (Rep a))
429defaultSamples _ = Omega.runOmega $ second to <$> gtoSamples (Proxy :: Proxy (Rep a))
430
430
431-- | @'ToSample'@ for Generics.
431-- | @'ToSample'@ for Generics.
432--
432--
433-- The use of @'Omega'@ allows for more productive sample generation.
433-- The use of @'Omega'@ allows for more productive sample generation.
434−class GToSample t s where
434+class GToSample t where
435− gtoSamples :: proxy t -> Omega.Omega (Text, s x)
435+ gtoSamples :: proxy t -> Omega.Omega (Text, t x)
436
436
437−instance GToSample U1 U1 where
437+instance GToSample U1 where
438 gtoSamples _ = Omega.each (singleSample U1)
438 gtoSamples _ = Omega.each (singleSample U1)
439
439
440−instance GToSample V1 V1 where
440+instance GToSample V1 where
441 gtoSamples _ = empty
441 gtoSamples _ = empty
442
442
443−instance (GToSample p p', GToSample q q') => GToSample (p :*: q) (p' :*: q') where
443+instance (GToSample p, GToSample q) => GToSample (p :*: q) where
444 gtoSamples _ = render <$> ps <*> qs
444 gtoSamples _ = render <$> ps <*> qs
445 where
445 where
446 ps = gtoSamples (Proxy :: Proxy p)
446 ps = gtoSamples (Proxy :: Proxy p)
@@ -449,21 +449,18 @@ instance (GToSample p p', GToSample q q') => GToSample (p :*: q) (p' :*: q') whe
449 | T.null ta || T.null tb = (ta <> tb, a :*: b)
449 | T.null ta || T.null tb = (ta <> tb, a :*: b)
450 | otherwise = (ta <> ", " <> tb, a :*: b)
450 | otherwise = (ta <> ", " <> tb, a :*: b)
451
451
452−instance (GToSample p p', GToSample q q') => GToSample (p :+: q) (p' :+: q') where
452+instance (GToSample p, GToSample q) => GToSample (p :+: q) where
453 gtoSamples _ = lefts <|> rights
453 gtoSamples _ = lefts <|> rights
454 where
454 where
455 lefts = second L1 <$> gtoSamples (Proxy :: Proxy p)
455 lefts = second L1 <$> gtoSamples (Proxy :: Proxy p)
456 rights = second R1 <$> gtoSamples (Proxy :: Proxy q)
456 rights = second R1 <$> gtoSamples (Proxy :: Proxy q)
457
457
458−instance ToSample a b => GToSample (K1 i a) (K1 i b) where
458+instance ToSample a => GToSample (K1 i a) where
459 gtoSamples _ = second K1 <$> Omega.each (toSamples (Proxy :: Proxy a))
459 gtoSamples _ = second K1 <$> Omega.each (toSamples (Proxy :: Proxy a))
460
460
461−instance (GToSample f g) => GToSample (M1 i a f) (M1 i a g) where
461+instance (GToSample f) => GToSample (M1 i a f) where
462 gtoSamples _ = second M1 <$> gtoSamples (Proxy :: Proxy f)
462 gtoSamples _ = second M1 <$> gtoSamples (Proxy :: Proxy f)
463
463
464−instance ToSample a b => ToSample (Headers ls a) b where
465− toSamples _ = toSamples (Proxy :: Proxy a)
466−
467
464
468class AllHeaderSamples ls where
465class AllHeaderSamples ls where
469 allHeaderToSample :: Proxy ls -> [HTTP.Header]
466 allHeaderToSample :: Proxy ls -> [HTTP.Header]
@@ -471,7 +468,7 @@ class AllHeaderSamples ls where
471instance AllHeaderSamples '[] where
468instance AllHeaderSamples '[] where
472 allHeaderToSample _ = []
469 allHeaderToSample _ = []
473
470
474−instance (ToByteString l, AllHeaderSamples ls, ToSample l l, KnownSymbol h)
471+instance (ToByteString l, AllHeaderSamples ls, ToSample l, KnownSymbol h)
475 => AllHeaderSamples (Header h l ': ls) where
472 => AllHeaderSamples (Header h l ': ls) where
476 allHeaderToSample _ = (mkHeader (toSample (Proxy :: Proxy l))) :
473 allHeaderToSample _ = (mkHeader (toSample (Proxy :: Proxy l))) :
477 allHeaderToSample (Proxy :: Proxy ls)
474 allHeaderToSample (Proxy :: Proxy ls)
@@ -481,7 +478,7 @@ instance (ToByteString l, AllHeaderSamples ls, ToSample l l, KnownSymbol h)
481
478
482-- | Synthesise a sample value of a type, encoded in the specified media types.
479-- | Synthesise a sample value of a type, encoded in the specified media types.
483sampleByteString
480sampleByteString
484− :: forall ctypes a b. (ToSample a b, IsNonEmpty ctypes, AllMimeRender ctypes b)
481+ :: forall ctypes a. (ToSample a, IsNonEmpty ctypes, AllMimeRender ctypes a)
485 => Proxy ctypes
482 => Proxy ctypes
486 -> Proxy a
483 -> Proxy a
487 -> [(M.MediaType, ByteString)]
484 -> [(M.MediaType, ByteString)]
@@ -491,7 +488,7 @@ sampleByteString ctypes@Proxy Proxy =
491-- | Synthesise a list of sample values of a particular type, encoded in the
488-- | Synthesise a list of sample values of a particular type, encoded in the
492-- specified media types.
489-- specified media types.
493sampleByteStrings
490sampleByteStrings
494− :: forall ctypes a b. (ToSample a b, IsNonEmpty ctypes, AllMimeRender ctypes b)
491+ :: forall ctypes a. (ToSample a, IsNonEmpty ctypes, AllMimeRender ctypes a)
495 => Proxy ctypes
492 => Proxy ctypes
496 -> Proxy a
493 -> Proxy a
497 -> [(Text, M.MediaType, ByteString)]
494 -> [(Text, M.MediaType, ByteString)]
@@ -728,7 +725,7 @@ instance
728#if MIN_VERSION_base(4,8,0)
725#if MIN_VERSION_base(4,8,0)
729 {-# OVERLAPPABLe #-}
726 {-# OVERLAPPABLe #-}
730#endif
727#endif
731− (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
728+ (ToSample a, IsNonEmpty cts, AllMimeRender cts a, SupportedTypes cts)
732 => HasDocs (Delete cts a) where
729 => HasDocs (Delete cts a) where
733 docsFor Proxy (endpoint, action) DocOptions{..} =
730 docsFor Proxy (endpoint, action) DocOptions{..} =
734 single endpoint' action'
731 single endpoint' action'
@@ -743,7 +740,7 @@ instance
743#if MIN_VERSION_base(4,8,0)
740#if MIN_VERSION_base(4,8,0)
744 {-# OVERLAPPING #-}
741 {-# OVERLAPPING #-}
745#endif
742#endif
746− (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
743+ (ToSample a, IsNonEmpty cts, AllMimeRender cts a, SupportedTypes cts
747 , AllHeaderSamples ls , GetHeaders (HList ls) )
744 , AllHeaderSamples ls , GetHeaders (HList ls) )
748 => HasDocs (Delete cts (Headers ls a)) where
745 => HasDocs (Delete cts (Headers ls a)) where
749 docsFor Proxy (endpoint, action) DocOptions{..} =
746 docsFor Proxy (endpoint, action) DocOptions{..} =
@@ -761,7 +758,7 @@ instance
761#if MIN_VERSION_base(4,8,0)
758#if MIN_VERSION_base(4,8,0)
762 {-# OVERLAPPABLe #-}
759 {-# OVERLAPPABLe #-}
763#endif
760#endif
764− (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
761+ (ToSample a, IsNonEmpty cts, AllMimeRender cts a, SupportedTypes cts)
765 => HasDocs (Get cts a) where
762 => HasDocs (Get cts a) where
766 docsFor Proxy (endpoint, action) DocOptions{..} =
763 docsFor Proxy (endpoint, action) DocOptions{..} =
767 single endpoint' action'
764 single endpoint' action'
@@ -776,7 +773,7 @@ instance
776#if MIN_VERSION_base(4,8,0)
773#if MIN_VERSION_base(4,8,0)
777 {-# OVERLAPPING #-}
774 {-# OVERLAPPING #-}
778#endif
775#endif
779− (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
776+ (ToSample a, IsNonEmpty cts, AllMimeRender cts a, SupportedTypes cts
780 , AllHeaderSamples ls , GetHeaders (HList ls) )
777 , AllHeaderSamples ls , GetHeaders (HList ls) )
781 => HasDocs (Get cts (Headers ls a)) where
778 => HasDocs (Get cts (Headers ls a)) where
782 docsFor Proxy (endpoint, action) DocOptions{..} =
779 docsFor Proxy (endpoint, action) DocOptions{..} =
@@ -803,7 +800,7 @@ instance
803#if MIN_VERSION_base(4,8,0)
800#if MIN_VERSION_base(4,8,0)
804 {-# OVERLAPPABLE #-}
801 {-# OVERLAPPABLE #-}
805#endif
802#endif
806− (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
803+ (ToSample a, IsNonEmpty cts, AllMimeRender cts a, SupportedTypes cts)
807 => HasDocs (Post cts a) where
804 => HasDocs (Post cts a) where
808 docsFor Proxy (endpoint, action) DocOptions{..} =
805 docsFor Proxy (endpoint, action) DocOptions{..} =
809 single endpoint' action'
806 single endpoint' action'
@@ -819,7 +816,7 @@ instance
819#if MIN_VERSION_base(4,8,0)
816#if MIN_VERSION_base(4,8,0)
820 {-# OVERLAPPING #-}
817 {-# OVERLAPPING #-}
821#endif
818#endif
822− (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
819+ (ToSample a, IsNonEmpty cts, AllMimeRender cts a, SupportedTypes cts
823 , AllHeaderSamples ls , GetHeaders (HList ls) )
820 , AllHeaderSamples ls , GetHeaders (HList ls) )
824 => HasDocs (Post cts (Headers ls a)) where
821 => HasDocs (Post cts (Headers ls a)) where
825 docsFor Proxy (endpoint, action) DocOptions{..} =
822 docsFor Proxy (endpoint, action) DocOptions{..} =
@@ -838,7 +835,7 @@ instance
838#if MIN_VERSION_base(4,8,0)
835#if MIN_VERSION_base(4,8,0)
839 {-# OVERLAPPABLE #-}
836 {-# OVERLAPPABLE #-}
840#endif
837#endif
841− (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
838+ (ToSample a, IsNonEmpty cts, AllMimeRender cts a, SupportedTypes cts)
842 => HasDocs (Put cts a) where
839 => HasDocs (Put cts a) where
843 docsFor Proxy (endpoint, action) DocOptions{..} =
840 docsFor Proxy (endpoint, action) DocOptions{..} =
844 single endpoint' action'
841 single endpoint' action'
@@ -854,7 +851,7 @@ instance
854#if MIN_VERSION_base(4,8,0)
851#if MIN_VERSION_base(4,8,0)
855 {-# OVERLAPPING #-}
852 {-# OVERLAPPING #-}
856#endif
853#endif
857− (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
854+ (ToSample a, IsNonEmpty cts, AllMimeRender cts a, SupportedTypes cts
858 , AllHeaderSamples ls , GetHeaders (HList ls) )
855 , AllHeaderSamples ls , GetHeaders (HList ls) )
859 => HasDocs (Put cts (Headers ls a)) where
856 => HasDocs (Put cts (Headers ls a)) where
860 docsFor Proxy (endpoint, action) DocOptions{..} =
857 docsFor Proxy (endpoint, action) DocOptions{..} =
@@ -951,7 +948,7 @@ instance HasDocs Raw where
951-- example data. However, there's no reason to believe that the instances of
948-- example data. However, there's no reason to believe that the instances of
952-- 'AllMimeUnrender' and 'AllMimeRender' actually agree (or to suppose that
949-- 'AllMimeUnrender' and 'AllMimeRender' actually agree (or to suppose that
953-- both are even defined) for any particular type.
950-- both are even defined) for any particular type.
954−instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, HasDocs sublayout
951+instance (ToSample a, IsNonEmpty cts, AllMimeRender cts a, HasDocs sublayout
955 , SupportedTypes cts)
952 , SupportedTypes cts)
956 => HasDocs (ReqBody cts a :> sublayout) where
953 => HasDocs (ReqBody cts a :> sublayout) where
957
954
@@ -990,32 +987,32 @@ instance HasDocs sublayout => HasDocs (Vault :> sublayout) where
990 docsFor (Proxy :: Proxy sublayout) ep
987 docsFor (Proxy :: Proxy sublayout) ep
991
988
992-- ToSample instances for simple types
989-- ToSample instances for simple types
993−instance ToSample () ()
990+instance ToSample ()
994−instance ToSample Bool Bool
991+instance ToSample Bool
995−instance ToSample Ordering Ordering
992+instance ToSample Ordering
996
993
997-- polymorphic ToSample instances
994-- polymorphic ToSample instances
998−instance (ToSample a a, ToSample b b) => ToSample (a, b) (a, b)
995+instance (ToSample a, ToSample b) => ToSample (a, b)
999−instance (ToSample a a, ToSample b b, ToSample c c) => ToSample (a, b, c) (a, b, c)
996+instance (ToSample a, ToSample b, ToSample c) => ToSample (a, b, c)
1000−instance (ToSample a a, ToSample b b, ToSample c c, ToSample d d) => ToSample (a, b, c, d) (a, b, c, d)
997+instance (ToSample a, ToSample b, ToSample c, ToSample d) => ToSample (a, b, c, d)
1001−instance (ToSample a a, ToSample b b, ToSample c c, ToSample d d, ToSample e e) => ToSample (a, b, c, d, e) (a, b, c, d, e)
998+instance (ToSample a, ToSample b, ToSample c, ToSample d, ToSample e) => ToSample (a, b, c, d, e)
1002−instance (ToSample a a, ToSample b b, ToSample c c, ToSample d d, ToSample e e, ToSample f f) => ToSample (a, b, c, d, e, f) (a, b, c, d, e, f)
999+instance (ToSample a, ToSample b, ToSample c, ToSample d, ToSample e, ToSample f) => ToSample (a, b, c, d, e, f)
1003−instance (ToSample a a, ToSample b b, ToSample c c, ToSample d d, ToSample e e, ToSample f f, ToSample g g) => ToSample (a, b, c, d, e, f, g) (a, b, c, d, e, f, g)
1000+instance (ToSample a, ToSample b, ToSample c, ToSample d, ToSample e, ToSample f, ToSample g) => ToSample (a, b, c, d, e, f, g)
1004
1001
1005−instance ToSample a a => ToSample (Maybe a) (Maybe a)
1002+instance ToSample a => ToSample (Maybe a)
1006−instance (ToSample a a, ToSample b b) => ToSample (Either a b) (Either a b)
1003+instance (ToSample a, ToSample b) => ToSample (Either a b)
1007−instance ToSample a a => ToSample [a] [a]
1004+instance ToSample a => ToSample [a]
1008
1005
1009-- ToSample instances for Control.Applicative types
1006-- ToSample instances for Control.Applicative types
1010−instance ToSample a a => ToSample (Const a b) (Const a b)
1007+instance ToSample a => ToSample (Const a b)
1011−instance ToSample a a => ToSample (ZipList a) (ZipList a)
1008+instance ToSample a => ToSample (ZipList a)
1012
1009
1013-- ToSample instances for Data.Monoid newtypes
1010-- ToSample instances for Data.Monoid newtypes
1014−instance ToSample All All
1011+instance ToSample All
1015−instance ToSample Any Any
1012+instance ToSample Any
1016−instance ToSample a a => ToSample (Sum a) (Sum a)
1013+instance ToSample a => ToSample (Sum a)
1017−instance ToSample a a => ToSample (Product a) (Product a)
1014+instance ToSample a => ToSample (Product a)
1018−instance ToSample a a => ToSample (First a) (First a)
1015+instance ToSample a => ToSample (First a)
1019−instance ToSample a a => ToSample (Last a) (Last a)
1016+instance ToSample a => ToSample (Last a)
1020−instance ToSample a a => ToSample (Dual a) (Dual a)
1017+instance ToSample a => ToSample (Dual a)
1021
1018
servant-examples/tutorial/T10.hs+4−4
@@ -23,7 +23,7 @@ instance ToCapture (Capture "x" Int) where
23instance ToCapture (Capture "y" Int) where
23instance ToCapture (Capture "y" Int) where
24 toCapture _ = DocCapture "y" "(integer) position on the y axis"
24 toCapture _ = DocCapture "y" "(integer) position on the y axis"
25
25
26−instance ToSample T3.Position T3.Position where
26+instance ToSample T3.Position where
27 toSamples _ = singleSample (T3.Position 3 14)
27 toSamples _ = singleSample (T3.Position 3 14)
28
28
29instance ToParam (QueryParam "name" String) where
29instance ToParam (QueryParam "name" String) where
@@ -33,7 +33,7 @@ instance ToParam (QueryParam "name" String) where
33 "Name of the person to say hello to."
33 "Name of the person to say hello to."
34 Normal
34 Normal
35
35
36−instance ToSample T3.HelloMessage T3.HelloMessage where
36+instance ToSample T3.HelloMessage where
37 toSamples _ =
37 toSamples _ =
38 [ ("When a value is provided for 'name'", T3.HelloMessage "Hello, Alp")
38 [ ("When a value is provided for 'name'", T3.HelloMessage "Hello, Alp")
39 , ("When 'name' is not specified", T3.HelloMessage "Hello, anonymous coward")
39 , ("When 'name' is not specified", T3.HelloMessage "Hello, anonymous coward")
@@ -42,10 +42,10 @@ instance ToSample T3.HelloMessage T3.HelloMessage where
42ci :: T3.ClientInfo
42ci :: T3.ClientInfo
43ci = T3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
43ci = T3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
44
44
45−instance ToSample T3.ClientInfo T3.ClientInfo where
45+instance ToSample T3.ClientInfo where
46 toSamples _ = singleSample ci
46 toSamples _ = singleSample ci
47
47
48−instance ToSample T3.Email T3.Email where
48+instance ToSample T3.Email where
49 toSamples _ = singleSample (T3.emailForClient ci)
49 toSamples _ = singleSample (T3.emailForClient ci)
50
50
51api :: Proxy DocsAPI
51api :: Proxy DocsAPI