-
11-12-2019 - |
質問
多数関数構成関数を書いています。これは基本的には、2番目の引数関数がvariadicであることを除いて、(.)
です。これは、次のような式を許可する必要があります。
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
.
任意のアイデア?可能なのか?
解決
多型関数の作業に組み込むことが可能です:
{-# 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
.
しかし、私はあなたがIncoherentInstances
を避けることができます
所属していません StackOverflow