servant/servant/src/Servant/Utils/Map.hs
2016-04-07 20:54:11 +08:00

21 lines
712 B
Haskell

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Servant.Utils.Map (mapLeaves) where
import Servant.API
class Mappable s t a b where
mapLeaves :: (forall x . a x -> b x) -> s -> t
instance Mappable (a x) (b x) a b where
mapLeaves f a = f a
instance Mappable s t a b => Mappable (arg -> s) (arg -> t) a b where
mapLeaves f s = mapLeaves f $ s
instance (Mappable left left' a b, Mappable right right' a b) => Mappable (left :<|> right) (left' :<|> right') a b where
mapLeaves f (left :<|> right) = mapLeaves f left :<|> mapLeaves f right