Variadic撰写功能?

is7*_*s7s 13 haskell variadic pointfree function-composition

我正在尝试编写一个可变函数组合函数.基本上(.)除了第二个参数函数是可变参数之外.这应该允许表达式:

map even . zipWith (+)
Run Code Online (Sandbox Code Playgroud)

要不就

map even . zipWith
Run Code Online (Sandbox Code Playgroud)

目前,如果我添加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
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?它甚至可能吗?

Ed'*_*'ka 9

可以输入它来处理多态函数:

{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses,
  IncoherentInstances, UndecidableInstances,
  FunctionalDependencies, TypeFamilies,
  NoMonomorphismRestriction #-}


class Comp a b c | a b -> c where
    (...) :: a -> b -> c

instance (a ~ c, r ~ b) => Comp (a -> b) c r where
    f ... g = f g

instance (Comp (a -> b) d r1, r ~ (c -> r1)) => Comp (a -> b) (c -> d) r where
    f ... g = \c -> f ... g c

t1 = map even ... zipWith (+)
t2 = map even ... zipWith
t3 = (+1) ... foldr
Run Code Online (Sandbox Code Playgroud)

但我怀疑你可以避免 IncoherentInstances