dependent-type - 在Idris中进行秩N量化

标签 dependent-type higher-rank-types idris

我只能以一种相当笨拙的方式在Idris 0.9.12中进行rank-n类型的操作:

tupleId : ((a : Type) -> a -> a) -> (a, b) -> (a, b)
tupleId f (a, b) = (f _ a, f _ b)

在有类型应用程序的任何地方都需要加下划线,因为当我尝试使(嵌套的)类型参数隐式时,Idris会引发解析错误:
tupleId : ({a : Type} -> a -> a) -> (a, b) -> (a, b) -- doesn't compile

一个可能更大的问题是,我根本无法对高等级类型进行类约束。我无法将以下Haskell函数转换为Idris:
appShow :: Show a => (forall a. Show a => a -> String) -> a -> String
appShow show x = show x

这也使我无法将Idris函数用作类型的同义词,例如Lens,在Haskell中是Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t

有什么办法可以补救或规避上述问题?

最佳答案

我刚刚在master中实现了这一点,允许在任意范围内使用隐式函数,它将在下一个hackage版本中发布。它还没有经过很好的测试!我至少尝试了以下简单示例,以及其他一些示例:

appShow : Show a => ({b : _} -> Show b => b -> String) -> a -> String
appShow s x = s x

AppendType : Type
AppendType = {a, n, m : _} -> Vect n a -> Vect m a -> Vect (n + m) a

append : AppendType
append [] ys = ys
append (x :: xs) ys = x :: append xs ys

tupleId : ({a : _} -> a -> a) -> (a, b) -> (a, b)
tupleId f (a, b) = (f a, f b)

Proxy  : Type -> Type -> Type -> Type -> (Type -> Type) -> Type -> Type

Producer' : Type -> (Type -> Type) -> Type -> Type
Producer' a m t = {x', x : _} -> Proxy x' x () a m t

yield : Monad m => a -> Producer' a m ()

目前的主要限制是您不能直接为隐式参数提供值,除非在顶层。我最终会为此做些...

关于dependent-type - 在Idris中进行秩N量化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22880309/

相关文章:

haskell - 如何在 CPS 中构建更高等级的 Coyoneda 类型的值?

parsing - idris 统一意外失败

proof - 我怎样才能让 Idris 自动证明两个值不相等?

functional-programming - 什么是累积宇宙和 `* : *` ?

haskell - 存在类型包装器的必要性

haskell - 处理 GHC 中较高级别类型的特殊情况?

dependent-type - Idris 确定结果向量长度

javascript - 如何保证传递的对象键可以使用 Typescript 进行调用?

algorithm - 可证明正确的排列小于 O(n^2)

wrapper - 我可以为表示包装其他类型的类型的 Wrapper 接口(interface)编写通用函数包装函数吗?