Checking and Commutativity / Associativity of +

Since the _+_ -Operation for Nat is usually defined recursively in the first argument, its obviously non-trivial for the type-checker to know that i + 0 == i . However, I frequently run into this issue when I write functions on fixed-size Vectors. One example: How can I define an Agda-function swap : {A : Set}{m n : Nat} -> Vec A (n + m) -> Vec A (m + n) which puts the first n values a

+的检查和交换性/关联性

由于Nat的_+_ -Operation通常是在第一个参数中递归定义的,因此它对于知道i + 0 == i的类型检查器来说显然是不重要的。 但是,当我在固定大小的矢量上编写函数时,我经常遇到这个问题。 一个例子:我如何定义一个Agda函数 swap : {A : Set}{m n : Nat} -> Vec A (n + m) -> Vec A (m + n) 这将前n值放在向量的末尾? 因为Haskell中的一个简单解决方案就是 swap 0 xs = xs swap n (x:xs) = swap (n-1) (xs ++ [x

What is the combinatory logic equivalent of intuitionistic type theory?

I recently completed a university course which featured Haskell and Agda (a dependent typed functional programming language), and was wondering if it was possible to replace lambda calculus in these with combinatory logic. With Haskell this seems possible using the S and K combinators, thus making it point-free. I was wondering what the equivalent was for Agda. Ie, can one make a dependently t

直觉型理论的组合逻辑等价物是什么?

我最近完成了一门以Haskell和Agda(一种依赖类型的函数式编程语言)为特色的大学课程,并想知道是否可以用组合逻辑来替代这些中的lambda演算。 对于Haskell来说,使用S和K组合器似乎是可能的,从而使它没有任何问题。 我想知道Agda的等价物是什么。 也就是说,是否可以使用与Agda等效的独立类型函数式编程语言而不使用任何变量? 另外,是否有可能用组合器取代量化? 我不知道这是否是巧合,但是例如通用量化使得类型签名

"Strictly positive" in Agda

I'm trying to encode some denotational semantics into Agda based on a program I wrote in Haskell. data Value = FunVal (Value -> Value) | PriVal Int | ConVal Id [Value] | Error String In Agda, the direct translation would be; data Value : Set where FunVal : (Value -> Value) -> Value PriVal : ℕ -> Value ConVal : String -> List Valu

Agda的“严格正面”

我试图根据我在Haskell中编写的程序将一些指称语义编码到Agda中。 data Value = FunVal (Value -> Value) | PriVal Int | ConVal Id [Value] | Error String 在Agda,直接翻译会是; data Value : Set where FunVal : (Value -> Value) -> Value PriVal : ℕ -> Value ConVal : String -> List Value -> Value Error : String -> Value 但我得到一个

fmap and "flat map" in Haskell

All this time, when any Haskell lecture spoke of "flat map", usually in relation to Monads, I thought it was called "flat" for a reason, ie it flattens out the container. So [[1,2],[3,4]] would be processed just as if it were [1,2,3,4] But now I discover that fmap and map are basically the same thing, the only difference being the application of one for functors and the o

fmap和Haskell的“平面地图”

所有这一次,当Haskell演讲中谈到“平面地图”时,通常就Monad而言,我认为它被称为“平坦”是有原因的,即它将容器弄平。 所以 [[1,2],[3,4]] 将被处理,就像它一样 [1,2,3,4] 但是现在我发现fmap和map基本上是一样的,唯一的区别是一个用于函子,另一个用于列表。 最后,这只是为了避免在使用地图时混淆错误消息。 真的吗? 如果是的话为什么fmap中的f来表示“平坦”,为什么不是“函数图”? 如果是这样,为什么fmap f来表

Haskell: class system extension proposal

I'm solving some ploblem on generating ancestor instances in Haskell. Recently I found this on Haskell wiki: Class system extension proposal. So, I would like to know, are there any solutions for this proposal already? Here are the examples from the Proposal: The current class system in Haskell is based on the idea that you can often provide default implementations for class methods at

Haskell:类系统扩展建议

我正在解决一些关于在Haskell中生成祖先实例的方法。 最近我在Haskell wiki上发现了这个:Class系统扩展建议。 所以,我想知道,这个提案有没有解决方案? 以下是建议中的例子: Haskell中的当前类系统基于这样的想法:通过使用类或其祖先的其他方法,您可以在定义类的同时为类方法提供默认实现。 但是请考虑以下层次结构,这些层次结构是根据Functor层次结构提案和The Other Prelude调整的 class Functor m where fm

Why doesn't Haskell have a stronger alternative to Eq?

The reason why Set is not a functor is given here. It seems to boil down to the fact that a == b && fa /= fb is possible. So, why doesn't Haskell have as standard an alternative to Eq, something like class Eq a => StrongEq a where (===) :: a -> a -> Bool (/==) :: a -> a -> Bool x /== y = not (x === y) x === y = not (x /== y) for which instances are s

为什么Haskell没有比Eq更强大的替代方案?

这里给出了Set不是函子的原因。 这似乎归结为a == b && fa /= fb是可能的事实。 那么,为什么Haskell没有像Eq那样的标准替代方案? class Eq a => StrongEq a where (===) :: a -> a -> Bool (/==) :: a -> a -> Bool x /== y = not (x === y) x === y = not (x /== y) 对于这些情况应该遵守法律 ∀a,b,f. not (a === b) || (f a === f b) ∀a. a === a ∀a,b. (a === b) == (b === a)

What laws are the standard Haskell type classes expected to uphold?

It's well-known that Monad instances ought to follow the Monad laws. It's perhaps less well-known that Functor instances ought to follow the Functor laws. Nevertheless, I would feel fairly confident writing a GHC rewrite rule that optimizes fmap id == id . What other standard classes have implicit laws? Does (==) have to be a true equivalence relation? Does Ord have to form a partia

标准的Haskell类型预期将遵循哪些法则?

众所周知, Monad实例应该遵循Monad定律。 Functor实例应该遵循Functor定律,这也许并不为人所知。 尽管如此,我还是fmap id == id信心写一个优化fmap id == id的GHC重写规则。 其他标准课程有哪些隐含法律? (==)必须是一个真正的等价关系吗? Ord是否必须形成部分订单? 全部订单? 我们至少可以假设它是传递性的吗? 反对称? 这些最后几个似乎没有在Haskell 2010报告中指定,我也不会有信心使用它们来编写重写规

Relationship between Functor, Applicative Functor, and Monad

When reading up on type classes I have seen that the relationship between Functors, Applicative Functors, and Monads is that of strictly increasing power. Functors are types that can be mapped over. Applicative Functors can do the same things with certain effects. Monads the same with possibly unrestrictive effects. Moreover: Every Monad is an Applicative Functor Every Applicative Functor is

Functor,Applicative Functor和Monad之间的关系

在阅读类型班时,我发现Functors,Applicative Functors和Monads之间的关系是严格增加权力的关系。 函子是可以映射的类型。 Applicative Functors可以在某些特定效果下做同样的事情。 Monads与可能无限制的效果相同。 此外: Every Monad is an Applicative Functor Every Applicative Functor is a Functor Applicative Functor的定义清楚地表明: class Functor f => Applicative f where pure :: a -> f a (

Haskell or Standard ML for beginners?

I'm going to be teaching a lower-division course in discrete structures. I have selected the text book Discrete Structures, Logic, and Computability in part because it contains examples and concepts that are conducive to implementation with a functional programming language. (I also think it's a good textbook.) I want an easy-to-understand FP language to illustrate DS concepts and tha

Haskell或Standard ML适合初学者?

我将要教授一个分立结构的低级课程。 我选择了离散结构,逻辑和可计算性的教科书,部分原因是它包含有助于使用函数式编程语言实现的示例和概念。 (我也认为这是一本很好的教科书。) 我想要一个易于理解的FP语言来说明DS概念,并且学生可以使用。 充其量,大多数学生在Java中只有一两个学期的程序设计。 看过Scheme,Erlang,Haskell,Ocaml和SML之后,我已经选择了Haskell或Standard ML。 我倾向于Haskell,原因如下,

Haskell: Composition of morphisms in monoidal categories

I have the following definitions for a monoidal category class (Similar to the standard library, but providing inverses of the necessary natural isomorphisms): class (Category r, Category s, Category t) => Bifunctor p r s t | p r -> s t, p s -> r t, p t -> r s where bimap :: r a b -> s c d -> t (p a c) (p b d) -- class (Bifunctor b k k k) => Associative k b where associa

Haskell:monoidal类别中的态射构成

对于monoidal类别类,我有以下定义(类似于标准库,但提供必要的自然同构反转): class (Category r, Category s, Category t) => Bifunctor p r s t | p r -> s t, p s -> r t, p t -> r s where bimap :: r a b -> s c d -> t (p a c) (p b d) -- class (Bifunctor b k k k) => Associative k b where associate :: k (b (b x y) z) (b x (b y z)) associateInv :: k (b x (b y z)) (b (b x y)