From 5018a34abd68f90bf7dc33c1a8d264c051f40270 Mon Sep 17 00:00:00 2001 From: Denis Redozubov Date: Tue, 22 Sep 2015 14:02:52 +0300 Subject: [PATCH] fix Elem type family to enable sane error reporting --- servant-foreign/src/Servant/Foreign.hs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/servant-foreign/src/Servant/Foreign.hs b/servant-foreign/src/Servant/Foreign.hs index cdfebc31..c42ccdc3 100644 --- a/servant-foreign/src/Servant/Foreign.hs +++ b/servant-foreign/src/Servant/Foreign.hs @@ -1,13 +1,14 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE ConstraintKinds #-} -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE UndecidableInstances #-} -- | Generalizes all the data needed to make code generation work with -- arbitrary programming languages. @@ -140,7 +141,12 @@ captureArg _ = error "captureArg called on non capture" defReq :: Req defReq = Req defUrl "GET" [] False [] +-- | To be used exclusively as a "negative" return type/constraint +-- by @'Elem`@ type family. +class NotFound + type family Elem (a :: *) (ls::[*]) :: Constraint where + Elem a '[] = NotFound Elem a (a ': list) = () Elem a (b ': list) = Elem a list