Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 单子中的变分函数_Haskell_Type Families - Fatal编程技术网

Haskell 单子中的变分函数

Haskell 单子中的变分函数,haskell,type-families,Haskell,Type Families,我有一类可变函数族: type family (~~>) (argTypes :: [Type]) (result :: Type) :: Type where '[] ~~> r = r (t ': ts) ~~> r = t -> (ts ~~> r) infixr 0 ~~> 我想要一个变量函数,它将一些单变量动作(比如print)应用于它的所有参数: class Foo (ts :: [Type]) where foo :: ts ~~

我有一类可变函数族:

type family (~~>) (argTypes :: [Type]) (result :: Type) :: Type where
'[]       ~~> r = r
(t ': ts) ~~> r = t -> (ts ~~> r)

infixr 0 ~~>
我想要一个变量函数,它将一些单变量动作(比如print)应用于它的所有参数:

class Foo (ts :: [Type]) where
foo :: ts ~~> IO ()

instance Foo '[] where
    foo = pure ()

instance (Show t, Foo ts) => Foo (t ': ts) where
    foo t = print t >> foo @ts
通常的一元结构在这里不起作用。
(>>)
具有类型
IO()->IO()->IO()
。我需要使用
IO()->(ts~~~>IO())->ts~~~>IO()
类型的东西来编写
print t t
foo@ts


可以编写这样的函数吗?

连续传递样式可以直接访问计算结果

另一种方法是构建一个类型类来迭代组合,但这很麻烦

 {-# LANGUAGE FlexibleInstances #-}

class Foo t where
  foo_ :: (IO () -> IO ()) -> t

instance (Show a, Foo t) => Foo (a -> t) where
  foo_ k a = foo_ (\continue -> k (print a >> continue))

instance Foo (IO ()) where
  foo_ k = k (return ())

foo :: Foo t => t
foo = foo_ id

main :: IO ()
main = foo () (Just "bar") [()]

我找到了一种编写函数
IO()->(ts~~~>IO())->ts~~~>IO()

因此,有关实例变成:

instance (Show t, Foo ts, BindV IO () () ts) => Foo (t ': ts) where
    foo t = thenV @IO @() @() @ts (print t) (foo @ts)
我希望我能以操作员的身份编写
thenV
bindV
,但是
TypeApplications
不能与操作员一起工作

instance (Show t, Foo ts, BindV IO () () ts) => Foo (t ': ts) where
    foo t = thenV @IO @() @() @ts (print t) (foo @ts)