Skip to content

Commit 0028852

Browse files
committed
Move erroring instances of HasLink to separate file
1 parent e86736e commit 0028852

File tree

4 files changed

+70
-24
lines changed

4 files changed

+70
-24
lines changed

servant/servant.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ library
7575
exposed-modules:
7676
Servant.Links
7777

78+
other-modules:
79+
Servant.Links.Internal
80+
Servant.Links.TypeErrors
81+
7882
-- Bundled with GHC: Lower bound to not force re-installs
7983
-- text and mtl are bundled starting with GHC-8.4
8084
--

servant/src/Servant/Links.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- | Wrapper for Servant.Links.Internal, which brings in scope the instance declarations
2+
-- in Servant.Links.TypeErrors
3+
module Servant.Links
4+
( module Servant.Links.Internal
5+
) where
6+
7+
import Servant.Links.Internal
8+
import Servant.Links.TypeErrors ()

servant/src/Servant/Links/Internal.hs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
-- `IsElem'` as a last resort.
101101
--
102102
-- @since 0.14.1
103-
module Servant.Links (
103+
module Servant.Links.Internal (
104104
module Servant.API.TypeLevel,
105105

106106
-- * Building and using safe links
@@ -141,7 +141,7 @@ import qualified Data.Text.Encoding as TE
141141
import Data.Type.Bool
142142
(If)
143143
import GHC.TypeLits
144-
(KnownSymbol, TypeError, symbolVal)
144+
(KnownSymbol, symbolVal)
145145
import Network.URI
146146
(URI (..), escapeURIString, isUnreserved)
147147
import Prelude ()
@@ -184,7 +184,6 @@ import Servant.API.Stream
184184
(Stream, StreamBody')
185185
import Servant.API.Sub
186186
(type (:>))
187-
import Servant.API.TypeErrors
188187
import Servant.API.TypeLevel
189188
import Servant.API.UVerb
190189
import Servant.API.Vault
@@ -194,8 +193,6 @@ import Servant.API.Verbs
194193
import Servant.API.WithNamedContext
195194
(WithNamedContext)
196195
import Web.HttpApiData
197-
import Data.Kind
198-
(Type)
199196

200197
-- | A safe link datatype.
201198
-- The only way of constructing a 'Link' is using 'safeLink', which means any
@@ -648,22 +645,3 @@ simpleToLink _ toA _ = toLink toA (Proxy :: Proxy sub)
648645
-- $setup
649646
-- >>> import Servant.API
650647
-- >>> import Data.Text (Text)
651-
652-
-- Erroring instance for 'HasLink' when a combinator is not fully applied
653-
instance TypeError (PartialApplication
654-
#if __GLASGOW_HASKELL__ >= 904
655-
@(Type -> Constraint)
656-
#endif
657-
HasLink arr) => HasLink ((arr :: a -> b) :> sub)
658-
where
659-
type MkLink (arr :> sub) _ = TypeError (PartialApplication (HasLink :: * -> Constraint) arr)
660-
toLink = error "unreachable"
661-
662-
-- Erroring instances for 'HasLink' for unknown API combinators
663-
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceForSub
664-
#if __GLASGOW_HASKELL__ >= 904
665-
@(Type -> Constraint)
666-
#endif
667-
HasLink ty) => HasLink (ty :> sub)
668-
669-
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceFor (HasLink api)) => HasLink api
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{-# LANGUAGE AllowAmbiguousTypes #-}
2+
{-# LANGUAGE CPP #-}
3+
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE PolyKinds #-}
5+
{-# LANGUAGE TypeFamilies #-}
6+
{-# LANGUAGE TypeOperators #-}
7+
{-# LANGUAGE UndecidableInstances #-}
8+
9+
{-# OPTIONS_GHC -fno-warn-orphans #-}
10+
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
11+
12+
#if __GLASGOW_HASKELL__ >= 904
13+
{-# LANGUAGE TypeApplications #-}
14+
#endif
15+
16+
-- | This module contains erroring instances for @Servant.Links.Internal@.
17+
-- They are separated from the bulk of the code, because they raise "missing methods"
18+
-- warnings. These warnings are expected, but ignoring them would lead to missing
19+
-- relevant warnings in @Servant.Links.Internal@. Therefore, we put them in a separate
20+
-- file, and ignore the warnings here.
21+
module Servant.Links.TypeErrors ()
22+
where
23+
24+
import Data.Constraint
25+
import GHC.TypeLits
26+
(TypeError)
27+
import Prelude ()
28+
import Prelude.Compat
29+
30+
import Servant.API.Sub
31+
(type (:>))
32+
import Servant.API.TypeErrors
33+
import Servant.Links.Internal
34+
35+
#if __GLASGOW_HASKELL__ >= 904
36+
import Data.Kind (Type)
37+
#endif
38+
39+
-- Erroring instance for 'HasLink' when a combinator is not fully applied
40+
instance TypeError (PartialApplication
41+
#if __GLASGOW_HASKELL__ >= 904
42+
@(Type -> Constraint)
43+
#endif
44+
HasLink arr) => HasLink ((arr :: a -> b) :> sub)
45+
where
46+
type MkLink (arr :> sub) _ = TypeError (PartialApplication (HasLink :: * -> Constraint) arr)
47+
toLink = error "unreachable"
48+
49+
-- Erroring instances for 'HasLink' for unknown API combinators
50+
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceForSub
51+
#if __GLASGOW_HASKELL__ >= 904
52+
@(Type -> Constraint)
53+
#endif
54+
HasLink ty) => HasLink (ty :> sub)
55+
56+
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceFor (HasLink api)) => HasLink api

0 commit comments

Comments
 (0)