@@ -32,12 +32,12 @@ class PathPiece s where
3232 -- | Convert from route piece.
3333 fromPathPiece :: S.Text -> Maybe s
3434 default fromPathPiece :: FromHttpApiData s => S.Text -> Maybe s
35− fromPathPiece = either (const Nothing) Just . parseUrlPiece
35+ fromPathPiece = defaultFromPathPiece
3636
3737 -- | Convert to route piece.
3838 toPathPiece :: s -> S.Text
3939 default toPathPiece :: ToHttpApiData s => s -> S.Text
40− toPathPiece = toUrlPiece
40+ toPathPiece = defaultToPathPiece
4141
4242instance PathPiece ()
4343instance PathPiece Char
@@ -70,32 +70,32 @@ instance PathPiece All
7070instance PathPiece Any
7171
7272instance PathPiece a => PathPiece (Dual a) where
73− toPathPiece = toPathPiece1
74− fromPathPiece = fromPathPiece1
73+ toPathPiece = defaultToPathPiece1
74+ fromPathPiece = defaultFromPathPiece1
7575
7676instance PathPiece a => PathPiece (Sum a) where
77− toPathPiece = toPathPiece1
78− fromPathPiece = fromPathPiece1
77+ toPathPiece = defaultToPathPiece1
78+ fromPathPiece = defaultFromPathPiece1
7979
8080instance PathPiece a => PathPiece (Product a) where
81− toPathPiece = toPathPiece1
82− fromPathPiece = fromPathPiece1
81+ toPathPiece = defaultToPathPiece1
82+ fromPathPiece = defaultFromPathPiece1
8383
8484instance PathPiece a => PathPiece (First a) where
85− toPathPiece = toPathPiece1
86− fromPathPiece = fromPathPiece1
85+ toPathPiece = defaultToPathPiece1
86+ fromPathPiece = defaultFromPathPiece1
8787
8888instance PathPiece a => PathPiece (Last a) where
89− toPathPiece = toPathPiece1
90− fromPathPiece = fromPathPiece1
89+ toPathPiece = defaultToPathPiece1
90+ fromPathPiece = defaultFromPathPiece1
9191
9292instance PathPiece a => PathPiece (Maybe a) where
93− toPathPiece = toPathPiece1
94− fromPathPiece = fromPathPiece1
93+ toPathPiece = defaultToPathPiece1
94+ fromPathPiece = defaultFromPathPiece1
9595
9696instance (PathPiece a, PathPiece b) => PathPiece (Either a b) where
97− toPathPiece = toPathPiece2
98− fromPathPiece = fromPathPiece2
97+ toPathPiece = defaultToPathPiece2
98+ fromPathPiece = defaultFromPathPiece2
9999
100100-- | Wrapped @'PathPiece'@ value.
101101newtype WrappedPathPiece a = WrappedPathPiece { unwrapPathPiece :: a }
@@ -106,21 +106,29 @@ instance PathPiece a => ToHttpApiData (WrappedPathPiece a) where
106106instance PathPiece a => FromHttpApiData (WrappedPathPiece a) where
107107 parseUrlPiece = fmap WrappedPathPiece . parseMaybeTextData fromPathPiece
108108
109+-- | Convert value to route piece using @'ToHttpApiData'@ implementation.
110+defaultToPathPiece :: ToHttpApiData a => a -> S.Text
111+defaultToPathPiece = toUrlPiece
112+
113+-- | Convert value from route piece using @'FromHttpApiData'@ implementation.
114+defaultFromPathPiece :: FromHttpApiData a => S.Text -> Maybe a
115+defaultFromPathPiece = either (const Nothing) Just . parseUrlPiece
116+
109117-- | Convert value to route piece using @'PathPiece'@ instance for its parameter.
110−toPathPiece1 :: forall f a. (PathPiece a, ToHttpApiData (f (WrappedPathPiece a))) => f a -> S.Text
111−toPathPiece1 = toUrlPiece . (unsafeCoerce :: f a -> f (WrappedPathPiece a))
118+defaultToPathPiece1 :: (PathPiece a, ToHttpApiData (f (WrappedPathPiece a))) => f a -> S.Text
119+defaultToPathPiece1 = toUrlPiece . (unsafeCoerce :: f a -> f (WrappedPathPiece a))
112120
113121-- | Parse value from route piece using @'PathPiece'@ instance for its parameter.
114−fromPathPiece1 :: forall f a. (PathPiece a, FromHttpApiData (f (WrappedPathPiece a))) => S.Text -> Maybe (f a)
115−fromPathPiece1 = either (const Nothing) (Just . (unsafeCoerce :: f (WrappedPathPiece a) -> f a)) . parseUrlPiece
122+defaultFromPathPiece1 :: (PathPiece a, FromHttpApiData (f (WrappedPathPiece a))) => S.Text -> Maybe (f a)
123+defaultFromPathPiece1 = fmap (unsafeCoerce :: f (WrappedPathPiece a) -> f a) . defaultFromPathPiece
116124
117125-- | Convert value to route piece using @'PathPiece'@ instance for its parameters.
118−toPathPiece2 :: forall f a b. (PathPiece a, PathPiece b, ToHttpApiData (f (WrappedPathPiece a) (WrappedPathPiece b))) => f a b -> S.Text
119−toPathPiece2 = toUrlPiece . (unsafeCoerce :: f a b -> f (WrappedPathPiece a) (WrappedPathPiece b))
126+defaultToPathPiece2 :: (PathPiece a, PathPiece b, ToHttpApiData (f (WrappedPathPiece a) (WrappedPathPiece b))) => f a b -> S.Text
127+defaultToPathPiece2 = toUrlPiece . (unsafeCoerce :: f a b -> f (WrappedPathPiece a) (WrappedPathPiece b))
120128
121129-- | Parse value from route piece using @'PathPiece'@ instance for its parameters.
122−fromPathPiece2 :: forall f a b. (PathPiece a, PathPiece b, FromHttpApiData (f (WrappedPathPiece a) (WrappedPathPiece b))) => S.Text -> Maybe (f a b)
123−fromPathPiece2 = either (const Nothing) (Just . (unsafeCoerce :: f (WrappedPathPiece a) (WrappedPathPiece b) -> f a b)) . parseUrlPiece
130+defaultFromPathPiece2 :: (PathPiece a, PathPiece b, FromHttpApiData (f (WrappedPathPiece a) (WrappedPathPiece b))) => S.Text -> Maybe (f a b)
131+defaultFromPathPiece2 = fmap (unsafeCoerce :: f (WrappedPathPiece a) (WrappedPathPiece b) -> f a b) . defaultFromPathPiece
124132
125133-- | Convert Haskell values to and from sequence of route pieces.
126134class PathMultiPiece s where