contravariant-extras 0.3.5.3 → 0.3.5.4
raw patch · 9 files changed
+217/−190 lines, 9 filesdep ~template-haskell-compat-v0208setup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: template-haskell-compat-v0208
API changes (from Hackage documentation)
Files
- Setup.hs +0/−2
- contravariant-extras.cabal +66/−20
- library/Contravariant/Extras.hs +17/−22
- library/Contravariant/Extras/Contrazip.hs +3/−6
- library/Contravariant/Extras/ContrazipLifting.hs +10/−13
- library/Contravariant/Extras/Op.hs +4/−5
- library/Contravariant/Extras/Op/Contrazip.hs +3/−6
- library/Contravariant/Extras/Prelude.hs +16/−25
- library/Contravariant/Extras/TH.hs +98/−91
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
contravariant-extras.cabal view
@@ -1,36 +1,82 @@-name: contravariant-extras-version: 0.3.5.3-category: Control-synopsis: Extras for the "contravariant" package-homepage: https://github.com/nikita-volkov/contravariant-extras-bug-reports: https://github.com/nikita-volkov/contravariant-extras/issues-author: Nikita Volkov <nikita.y.volkov@mail.ru>-maintainer: Nikita Volkov <nikita.y.volkov@mail.ru>-copyright: (c) 2015, Nikita Volkov-license: MIT-license-file: LICENSE-build-type: Simple+name: contravariant-extras+version: 0.3.5.4+category: Control+synopsis: Extras for the "contravariant" package+description:+ Utilities for contravariant functors.+ Provides large sets of functions for contravariant composition+ of various arities.++homepage: https://github.com/nikita-volkov/contravariant-extras+bug-reports:+ https://github.com/nikita-volkov/contravariant-extras/issues++author: Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer: Nikita Volkov <nikita.y.volkov@mail.ru>+copyright: (c) 2015, Nikita Volkov+license: MIT+license-file: LICENSE+build-type: Simple cabal-version: >=1.10 source-repository head- type: git+ type: git location: git://github.com/nikita-volkov/contravariant-extras.git library- hs-source-dirs: library- default-extensions: Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples- default-language: Haskell2010+ hs-source-dirs: library+ default-extensions:+ NoImplicitPrelude+ NoMonomorphismRestriction+ Arrows+ BangPatterns+ ConstraintKinds+ DataKinds+ DefaultSignatures+ DeriveDataTypeable+ DeriveFoldable+ DeriveFunctor+ DeriveGeneric+ DeriveTraversable+ EmptyDataDecls+ FlexibleContexts+ FlexibleInstances+ FunctionalDependencies+ GADTs+ GeneralizedNewtypeDeriving+ LambdaCase+ LiberalTypeSynonyms+ MagicHash+ MultiParamTypeClasses+ MultiWayIf+ OverloadedStrings+ ParallelListComp+ PatternGuards+ QuasiQuotes+ RankNTypes+ RecordWildCards+ ScopedTypeVariables+ StandaloneDeriving+ TemplateHaskell+ TupleSections+ TypeFamilies+ TypeOperators+ UnboxedTuples++ default-language: Haskell2010 exposed-modules: Contravariant.Extras Contravariant.Extras.Contrazip Contravariant.Extras.ContrazipLifting Contravariant.Extras.Op Contravariant.Extras.Op.Contrazip+ other-modules: Contravariant.Extras.Prelude Contravariant.Extras.TH+ build-depends:- base >=4.10 && <5,- contravariant >=1.3 && <2,- template-haskell >=2.8 && <3,- template-haskell-compat-v0208 >=0.1.7 && <2+ base >=4.10 && <5+ , contravariant >=1.3 && <2+ , template-haskell >=2.8 && <3+ , template-haskell-compat-v0208 >=0.1.9.3 && <2
library/Contravariant/Extras.hs view
@@ -1,34 +1,29 @@ module Contravariant.Extras-(- {-|- @contrazip@ functions of multiple arities.- -}- module Contravariant.Extras.Contrazip,- {-|- @contrazipLifting@ functions of multiple arities.- -}- module Contravariant.Extras.ContrazipLifting,- (>*<),- contramany,- Supplied(..),-)+ ( -- |+ -- @contrazip@ functions of multiple arities.+ module Contravariant.Extras.Contrazip,+ -- |+ -- @contrazipLifting@ functions of multiple arities.+ module Contravariant.Extras.ContrazipLifting,+ (>*<),+ contramany,+ Supplied (..),+ ) where -import Contravariant.Extras.Prelude hiding ((<>)) import Contravariant.Extras.Contrazip import Contravariant.Extras.ContrazipLifting-import Data.Functor.Contravariant.Divisible+import Contravariant.Extras.Prelude hiding ((<>)) import Data.Semigroup (Semigroup ((<>))) - -- | -- An alias to 'divided'. {-# INLINE (>*<) #-}-(>*<) :: Divisible f => f a -> f b -> f (a, b)+(>*<) :: (Divisible f) => f a -> f b -> f (a, b) (>*<) = divided -contramany :: Decidable f => f a -> f [a]+contramany :: (Decidable f) => f a -> f [a] contramany f = loop where@@ -49,10 +44,10 @@ -- | -- A combination of a divisible functor with some input for it. -- Allows to use the 'Monoid' API for composition.-data Supplied divisible =- forall input. Supplied (divisible input) input+data Supplied divisible+ = forall input. Supplied (divisible input) input -instance Divisible divisible => Semigroup (Supplied divisible) where+instance (Divisible divisible) => Semigroup (Supplied divisible) where Supplied divisible1 input1 <> Supplied divisible2 input2 = Supplied divisible3 input3 where@@ -61,7 +56,7 @@ input3 = (input1, input2) -instance Divisible divisible => Monoid (Supplied divisible) where+instance (Divisible divisible) => Monoid (Supplied divisible) where mempty = Supplied conquer () mappend =
library/Contravariant/Extras/Contrazip.hs view
@@ -1,21 +1,18 @@ -- | -- A berserk collection of @contrazip@ functions with arities of up to 42.--- +-- -- Why 42? -- Well, naturally, because it's the answer to the ultimate question of life, -- the universe and everything.--- +-- -- It's exported as a separate module from "Contravariant.Extras" -- only to not pollute its documentation. -- The "Contravariant.Extras" module still reexports this module, -- so you can simply import that only.--- module Contravariant.Extras.Contrazip where import Contravariant.Extras.Prelude import qualified Contravariant.Extras.TH as TH - -- Generate the @contrazip@ functions:-return (join (map (TH.contrazipDecs "contrazip") (reverse [2..42])))-+return (join (map (TH.contrazipDecs "contrazip") (reverse [2 .. 42])))
library/Contravariant/Extras/ContrazipLifting.hs view
@@ -1,34 +1,31 @@ module Contravariant.Extras.ContrazipLifting where -import Contravariant.Extras.Prelude import Contravariant.Extras.Contrazip-import Data.Functor.Contravariant.Divisible-import qualified Contravariant.Extras.TH as TH-+import Contravariant.Extras.Prelude -contrazipLifting2 :: Divisible f => (forall x. g x -> f x) -> g a1 -> g a2 -> f (a1, a2)+contrazipLifting2 :: (Divisible f) => (forall x. g x -> f x) -> g a1 -> g a2 -> f (a1, a2) contrazipLifting2 fn a b = contrazip2 (fn a) (fn b) -contrazipLifting3 :: Divisible f => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> f (a1, a2, a3)+contrazipLifting3 :: (Divisible f) => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> f (a1, a2, a3) contrazipLifting3 fn a b c = contrazip3 (fn a) (fn b) (fn c) -contrazipLifting4 :: Divisible f => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> f (a1, a2, a3, a4)+contrazipLifting4 :: (Divisible f) => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> f (a1, a2, a3, a4) contrazipLifting4 fn a b c d = contrazip4 (fn a) (fn b) (fn c) (fn d) -contrazipLifting5 :: Divisible f => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> f (a1, a2, a3, a4, a5)+contrazipLifting5 :: (Divisible f) => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> f (a1, a2, a3, a4, a5) contrazipLifting5 fn a b c d e = contrazip5 (fn a) (fn b) (fn c) (fn d) (fn e) -contrazipLifting6 :: Divisible f => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> f (a1, a2, a3, a4, a5, a6)+contrazipLifting6 :: (Divisible f) => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> f (a1, a2, a3, a4, a5, a6) contrazipLifting6 fn a b c d e f = contrazip6 (fn a) (fn b) (fn c) (fn d) (fn e) (fn f) -contrazipLifting7 :: Divisible f => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> g a7 -> f (a1, a2, a3, a4, a5, a6, a7)+contrazipLifting7 :: (Divisible f) => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> g a7 -> f (a1, a2, a3, a4, a5, a6, a7) contrazipLifting7 fn a b c d e f g = contrazip7 (fn a) (fn b) (fn c) (fn d) (fn e) (fn f) (fn g) -contrazipLifting8 :: Divisible f => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> g a7 -> g a8 -> f (a1, a2, a3, a4, a5, a6, a7, a8)+contrazipLifting8 :: (Divisible f) => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> g a7 -> g a8 -> f (a1, a2, a3, a4, a5, a6, a7, a8) contrazipLifting8 fn a b c d e f g h = contrazip8 (fn a) (fn b) (fn c) (fn d) (fn e) (fn f) (fn g) (fn h) -contrazipLifting9 :: Divisible f => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> g a7 -> g a8 -> g a9 -> f (a1, a2, a3, a4, a5, a6, a7, a8, a9)+contrazipLifting9 :: (Divisible f) => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> g a7 -> g a8 -> g a9 -> f (a1, a2, a3, a4, a5, a6, a7, a8, a9) contrazipLifting9 fn a b c d e f g h i = contrazip9 (fn a) (fn b) (fn c) (fn d) (fn e) (fn f) (fn g) (fn h) (fn i) -contrazipLifting10 :: Divisible f => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> g a7 -> g a8 -> g a9 -> g a10 -> f (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)+contrazipLifting10 :: (Divisible f) => (forall x. g x -> f x) -> g a1 -> g a2 -> g a3 -> g a4 -> g a5 -> g a6 -> g a7 -> g a8 -> g a9 -> g a10 -> f (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) contrazipLifting10 fn a b c d e f g h i j = contrazip10 (fn a) (fn b) (fn c) (fn d) (fn e) (fn f) (fn g) (fn h) (fn i) (fn j)
library/Contravariant/Extras/Op.hs view
@@ -1,11 +1,10 @@ -- | -- This module exports functions specialized for the `Op` type. module Contravariant.Extras.Op-(- -- |- -- A berserk collection of @contrazip@ functions with arities of up to 42.- module Contravariant.Extras.Op.Contrazip,-)+ ( -- |+ -- A berserk collection of @contrazip@ functions with arities of up to 42.+ module Contravariant.Extras.Op.Contrazip,+ ) where import Contravariant.Extras.Op.Contrazip
library/Contravariant/Extras/Op/Contrazip.hs view
@@ -2,22 +2,19 @@ -- A berserk collection of @contrazip@ functions with arities of up to 42, -- which are specialized to the 'Op' type, -- and jump thru fewer hoops than their 'Divisible'-based siblings.--- +-- -- Why 42? -- Well, naturally, because it's the answer to the ultimate question of life, -- the universe and everything.--- +-- -- It's exported as a separate module from "Contravariant.Extras.Op" -- only to not pollute its documentation. -- The "Contravariant.Extras.Op" module still reexports this module, -- so you can simply import that only.--- module Contravariant.Extras.Op.Contrazip where import Contravariant.Extras.Prelude import qualified Contravariant.Extras.TH as TH - -- Generate the @contrazip@ functions:-return (join (map (TH.opContrazipDecs "contrazip") (reverse [2..42])))-+return (join (map (TH.opContrazipDecs "contrazip") (reverse [2 .. 42])))
library/Contravariant/Extras/Prelude.hs view
@@ -1,20 +1,17 @@ module Contravariant.Extras.Prelude-( - module Exports,-)+ ( module Exports,+ ) where --- base-------------------------- import Control.Applicative as Exports import Control.Arrow as Exports hiding (first, second) import Control.Category as Exports import Control.Concurrent as Exports import Control.Exception as Exports-import Control.Monad as Exports hiding (fail, mapM_, sequence_, forM_, msum, mapM, sequence, forM)-import Control.Monad.IO.Class as Exports+import Control.Monad as Exports hiding (fail, forM, forM_, mapM, mapM_, msum, sequence, sequence_) import Control.Monad.Fail as Exports import Control.Monad.Fix as Exports hiding (fix)+import Control.Monad.IO.Class as Exports import Control.Monad.ST as Exports import Data.Bifunctor as Exports import Data.Bits as Exports@@ -28,20 +25,21 @@ import Data.Fixed as Exports import Data.Foldable as Exports hiding (toList) import Data.Function as Exports hiding (id, (.))-import Data.Functor as Exports+import Data.Functor as Exports hiding (unzip) import Data.Functor.Contravariant as Exports+import Data.Functor.Contravariant.Divisible as Exports import Data.Functor.Identity as Exports-import Data.Int as Exports import Data.IORef as Exports+import Data.Int as Exports import Data.Ix as Exports-import Data.List as Exports hiding (sortOn, isSubsequenceOf, uncons, concat, foldr, foldl1, maximum, minimum, product, sum, all, and, any, concatMap, elem, foldl, foldr1, notElem, or, find, maximumBy, minimumBy, mapAccumL, mapAccumR, foldl')+import Data.List as Exports hiding (all, and, any, concat, concatMap, elem, find, foldl, foldl', foldl1, foldr, foldr1, isSubsequenceOf, mapAccumL, mapAccumR, maximum, maximumBy, minimum, minimumBy, notElem, or, product, sortOn, sum, uncons) import Data.Maybe as Exports-import Data.Monoid as Exports hiding (Last(..), First(..), (<>))+import Data.Monoid as Exports hiding (First (..), Last (..), (<>)) import Data.Ord as Exports import Data.Proxy as Exports import Data.Ratio as Exports-import Data.Semigroup as Exports import Data.STRef as Exports+import Data.Semigroup as Exports import Data.String as Exports import Data.Traversable as Exports import Data.Tuple as Exports@@ -53,13 +51,12 @@ import Foreign.ForeignPtr as Exports import Foreign.Ptr as Exports import Foreign.StablePtr as Exports-import Foreign.Storable as Exports hiding (sizeOf, alignment)-import GHC.Conc as Exports hiding (withMVar, threadWaitWriteSTM, threadWaitWrite, threadWaitReadSTM, threadWaitRead)-import GHC.Exts as Exports (lazy, inline, sortWith, groupWith, IsList(..))+import Foreign.Storable as Exports hiding (alignment, sizeOf)+import GHC.Conc as Exports hiding (threadWaitRead, threadWaitReadSTM, threadWaitWrite, threadWaitWriteSTM, withMVar)+import GHC.Exts as Exports (IsList (..), groupWith, inline, lazy, sortWith) import GHC.Generics as Exports (Generic, Generic1) import GHC.IO.Exception as Exports import Numeric as Exports-import Prelude as Exports hiding (fail, concat, foldr, mapM_, sequence_, foldl1, maximum, minimum, product, sum, all, and, any, concatMap, elem, foldl, foldr1, notElem, or, mapM, sequence, id, (.)) import System.Environment as Exports import System.Exit as Exports import System.IO as Exports@@ -68,13 +65,7 @@ import System.Mem as Exports import System.Mem.StableName as Exports import System.Timeout as Exports-import Text.ParserCombinators.ReadP as Exports (ReadP, ReadS, readP_to_S, readS_to_P)-import Text.ParserCombinators.ReadPrec as Exports (ReadPrec, readPrec_to_P, readP_to_Prec, readPrec_to_S, readS_to_Prec)-import Text.Printf as Exports (printf, hPrintf)-import Text.Read as Exports (Read(..), readMaybe, readEither)+import Text.Printf as Exports (hPrintf, printf)+import Text.Read as Exports (Read (..), readEither, readMaybe) import Unsafe.Coerce as Exports---- contravariant---------------------------import Data.Functor.Contravariant as Exports-import Data.Functor.Contravariant.Divisible as Exports+import Prelude as Exports hiding (all, and, any, concat, concatMap, elem, fail, foldl, foldl1, foldr, foldr1, id, mapM, mapM_, maximum, minimum, notElem, or, product, sequence, sequence_, sum, (.))
library/Contravariant/Extras/TH.hs view
@@ -1,28 +1,25 @@-module Contravariant.Extras.TH (- opContrazipDecs,+module Contravariant.Extras.TH+ ( opContrazipDecs, contrazipDecs, contrazipExp,- ) where+ )+where import Contravariant.Extras.Prelude-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Divisible-import Language.Haskell.TH.Syntax hiding (classP)+import Language.Haskell.TH.Syntax import qualified TemplateHaskell.Compat.V0208 as Compat --{-|-Generates declarations in the spirit of the following:--@-tuple3 :: Monoid a => Op a b1 -> Op a b2 -> Op a b3 -> Op a ( b1 , b2 , b3 )-tuple3 ( Op op1 ) ( Op op2 ) ( Op op3 ) =- Op $ \( v1 , v2 , v3 ) -> mconcat [ op1 v1 , op2 v2 , op3 v3 ]-@--}-opContrazipDecs :: String -> Int -> [ Dec ]+-- |+-- Generates declarations in the spirit of the following:+--+-- @+-- tuple3 :: Monoid a => Op a b1 -> Op a b2 -> Op a b3 -> Op a ( b1 , b2 , b3 )+-- tuple3 ( Op op1 ) ( Op op2 ) ( Op op3 ) =+-- Op $ \( v1 , v2 , v3 ) -> mconcat [ op1 v1 , op2 v2 , op3 v3 ]+-- @+opContrazipDecs :: String -> Int -> [Dec] opContrazipDecs baseName arity =- [ signature , value ]+ [signature, value] where name = mkName (showString baseName (show arity))@@ -41,13 +38,13 @@ b index = showString "b" (show index) cxt =- [ pred ]+ [pred] where pred =- Compat.classP ''Monoid [ a ]+ Compat.classP ''Monoid [a] where a =- VarT (mkName "a") + VarT (mkName "a") type_ = foldr appArrowT result params where@@ -78,7 +75,7 @@ FunD name clauses where clauses =- [ clause ]+ [clause] where clause = Clause pats body []@@ -87,10 +84,10 @@ map pat (enumFromTo 1 arity) where pat index =- Compat.conp 'Op pats+ Compat.conP 'Op pats where pats =- [ VarP name ]+ [VarP name] where name = mkName (showString "op" (show index))@@ -101,7 +98,7 @@ LamE pats exp where pats =- [ TupP pats ]+ [TupP pats] where pats = map pat (enumFromTo 1 arity)@@ -122,77 +119,87 @@ varName = mkName (showString "v" (show index)) -{-|-Generates declarations in the spirit of the following:--@-contrazip4 :: Divisible f => f a1 -> f a2 -> f a3 -> f a4 -> f ( a1 , a2 , a3 , a4 )-contrazip4 f1 f2 f3 f4 =- divide $(TupleTH.splitTupleAt 4 1) f1 $- divide $(TupleTH.splitTupleAt 3 1) f2 $- divide $(TupleTH.splitTupleAt 2 1) f3 $- f4-@--}+-- |+-- Generates declarations in the spirit of the following:+--+-- @+-- contrazip4 :: Divisible f => f a1 -> f a2 -> f a3 -> f a4 -> f ( a1 , a2 , a3 , a4 )+-- contrazip4 f1 f2 f3 f4 =+-- divide $(TupleTH.splitTupleAt 4 1) f1 $+-- divide $(TupleTH.splitTupleAt 3 1) f2 $+-- divide $(TupleTH.splitTupleAt 2 1) f3 $+-- f4+-- @ contrazipDecs :: String -> Int -> [Dec]-contrazipDecs baseName arity = [signature, value] where- name = mkName (showString baseName (show arity))- signature = SigD name (contrazipType arity)- value = FunD name clauses where- clauses = [clause] where- clause = Clause [] body [] where- body = NormalB (contrazipExp arity)+contrazipDecs baseName arity = [signature, value]+ where+ name = mkName (showString baseName (show arity))+ signature = SigD name (contrazipType arity)+ value = FunD name clauses+ where+ clauses = [clause]+ where+ clause = Clause [] body []+ where+ body = NormalB (contrazipExp arity) contrazipType :: Int -> Type-contrazipType arity = ForallT vars cxt type_ where- fName = mkName "f"- aNames = map aName (enumFromTo 1 arity) where- aName index = mkName (showString "a" (show index))- vars = map Compat.specifiedPlainTV (fName : aNames)- cxt = [pred] where- pred = Compat.classP ''Divisible [VarT fName]- type_ = foldr appArrowT result params where- appArrowT a b = AppT (AppT ArrowT a) b- result = AppT (VarT fName) tuple where- tuple = foldl AppT (TupleT arity) (map VarT aNames)- params = map param aNames where- param aName = AppT (VarT fName) (VarT aName)--{-|-Contrazip lambda expression of specified arity.--Allows to create contrazip expressions of any arity:+contrazipType arity = ForallT vars cxt type_+ where+ fName = mkName "f"+ aNames = map aName (enumFromTo 1 arity)+ where+ aName index = mkName (showString "a" (show index))+ vars = map Compat.specifiedPlainTV (fName : aNames)+ cxt = [pred]+ where+ pred = Compat.classP ''Divisible [VarT fName]+ type_ = foldr appArrowT result params+ where+ appArrowT a b = AppT (AppT ArrowT a) b+ result = AppT (VarT fName) tuple+ where+ tuple = foldl AppT (TupleT arity) (map VarT aNames)+ params = map param aNames+ where+ param aName = AppT (VarT fName) (VarT aName) ->>>:t $(return (contrazipExp 2))-$(return (contrazipExp 2))- :: Data.Functor.Contravariant.Divisible.Divisible f =>- f a1 -> f a2 -> f (a1, a2)--}+-- |+-- Contrazip lambda expression of specified arity.+--+-- Allows to create contrazip expressions of any arity:+--+-- >>>:t $(return (contrazipExp 2))+-- \$(return (contrazipExp 2))+-- :: Data.Functor.Contravariant.Divisible.Divisible f =>+-- f a1 -> f a2 -> f (a1, a2) contrazipExp :: Int -> Exp-contrazipExp arity = SigE (LamE pats body) (contrazipType arity) where- pats = map pat (enumFromTo 1 arity) where- pat index = VarP name where- name = mkName (showString "f" (show index))- body = exp arity where- exp index = case index of- 1 -> VarE (mkName (showString "f" (show arity)))- _ -> foldl1 AppE [- VarE 'divide- ,- splitTupleAtExp index 1- ,- VarE (mkName (showString "f" (show (arity - index + 1))))- ,- exp (pred index)- ]+contrazipExp arity = SigE (LamE pats body) (contrazipType arity)+ where+ pats = map pat (enumFromTo 1 arity)+ where+ pat index = VarP name+ where+ name = mkName (showString "f" (show index))+ body = exp arity+ where+ exp index = case index of+ 1 -> VarE (mkName (showString "f" (show arity)))+ _ ->+ foldl1+ AppE+ [ VarE 'divide,+ splitTupleAtExp index 1,+ VarE (mkName (showString "f" (show (arity - index + 1)))),+ exp (pred index)+ ] splitTupleAtExp :: Int -> Int -> Exp splitTupleAtExp arity position =- let- nameByIndex index = Name (OccName ('_' : show index)) NameS- names = enumFromTo 0 (pred arity) & map nameByIndex- pats = names & map VarP- pat = TupP pats- exps = names & map VarE- body = splitAt position exps & \ (a, b) -> Compat.tupE [Compat.tupE a, Compat.tupE b]- in LamE [pat] body+ let nameByIndex index = Name (OccName ('_' : show index)) NameS+ names = enumFromTo 0 (pred arity) & map nameByIndex+ pats = names & map VarP+ pat = TupP pats+ exps = names & map VarE+ body = splitAt position exps & \(a, b) -> Compat.tupE [Compat.tupE a, Compat.tupE b]+ in LamE [pat] body