我正在尝试编写一个可变参数函数组合函数。这基本上是(.)
除了第二个参数函数是可变的。这应该允许如下表达式:
map even . zipWith (+)
要不就
map even . zipWith
目前,如果我添加IncoherentInstances
并需要第一个参数函数的非多态实例,我已经达到的效果。
{-# LANGUAGE FlexibleInstances, OverlappingInstances, MultiParamTypeClasses,
FunctionalDependencies, UndecidableInstances, KindSignatures #-}
class Comp a b c d | c -> d where
comp :: (a -> b) -> c -> d
instance Comp a b (a :: *) (b :: *) where
comp f g = f g
instance Comp c d b e => Comp c d (a -> b) (a -> e) where
comp f g = comp f . g
有任何想法吗?甚至可能吗?