在学习Haskell的同时,我试图理解Haskell中clojure的传感器的类型。
{-# LANGUAGE RankNTypes #-}
module Transducers where
-- r = reduced
type Reducer r a = r -> a -> r
type Transducer a b = forall r . Reducer r a -> Reducer r b我在理解如何键入以下函数时遇到问题:
-- type inference
transduce :: Foldable t => (t1 -> b -> a -> b) -> t1 -> b -> t a -> b
-- what I actually want
transduce :: forall t1 . Foldable t => Transducer a b -> t1 -> b -> t a -> b
transduce xform f init coll = foldl (xform f) init coll这给我带来了麻烦,它不能编译。我是不是遗漏了一些语法方面的东西?或者这是不可能的?
发布于 2016-09-28 01:54:56
在我看来,你可能指的是
transduce :: Foldable t => Transducer a b -> Reducer r a -> r -> t b -> r作为user2407038 suggested,只有当您想强制调用者提供Transducer时,才需要这种奇特的类型。否则,您可以将其简化为
transduce :: Foldable t => (x -> Reducer r b) -> x -> r -> t b -> rhttps://stackoverflow.com/questions/39719073
复制相似问题