首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Haskell排名n类型&类型类语法

Haskell排名n类型&类型类语法
EN

Stack Overflow用户
提问于 2016-09-27 15:52:12
回答 1查看 147关注 0票数 0

在学习Haskell的同时,我试图理解Haskell中clojure的传感器的类型。

代码语言:javascript
复制
{-# 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

我在理解如何键入以下函数时遇到问题:

代码语言:javascript
复制
-- 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

这给我带来了麻烦,它不能编译。我是不是遗漏了一些语法方面的东西?或者这是不可能的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-28 01:54:56

在我看来,你可能指的是

代码语言:javascript
复制
transduce :: Foldable t => Transducer a b -> Reducer r a -> r -> t b -> r

作为user2407038 suggested,只有当您想强制调用者提供Transducer时,才需要这种奇特的类型。否则,您可以将其简化为

代码语言:javascript
复制
transduce :: Foldable t => (x -> Reducer r b) -> x -> r -> t b -> r
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39719073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档