And*_*ács 31 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)
Run Code Online (Sandbox Code Playgroud)
我需要在有类型应用程序的地方使用下划线,因为当我尝试隐藏(嵌套)类型参数时,Idris会抛出解析错误:
tupleId : ({a : Type} -> a -> a) -> (a, b) -> (a, b) -- doesn't compile
Run Code Online (Sandbox Code Playgroud)
一个可能更大的问题是我根本不能在更高级别的类型中进行类约束.我无法将以下Haskell函数转换为Idris:
appShow :: Show a => (forall a. Show a => a -> String) -> a -> String
appShow show x = show x
Run Code Online (Sandbox Code Playgroud)
这也防止我使用伊德里斯用作类型同义词类型,例如Lens
,这是Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
在Haskell.
有什么方法可以补救或规避上述问题?
Edw*_*ady 20
我刚刚在master中实现了这个,允许在任意作用域中使用implicits,它将在下一个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 ()
Run Code Online (Sandbox Code Playgroud)
一分钟的主要约束是你不能直接给出隐式参数的值,除了在顶层.我最终会做些什么......