我有一个依赖于谓词P的数据类型:一个->类型,这意味着它的一些数据构造函数引用了一个隐式P作为参数。我希望idris能够自动推断出这个隐含的内容。为此,我用关键字auto注释了隐式,并在类型声明之前编写了一个函数isP:(x : a) -> Dec (P ),其中有%的提示注释。也就是说,类似于:
module P
P : a -> Type
%hint
isP : (x : a) -> Dec (P x)
在一个单独的文件中
module Main
import P
data Foo : Type where
Bar : (x : a) -> .{a
考虑以下大小列表的类型定义:
Inductive listn: nat -> Type -> Type :=
| nil: forall {A: Set}, listn 0 A
| cons: forall {n: nat} {A: Set}, A -> listn n A -> listn (S n) A.
这本质上是Idris中的类型。
我试图为init定义listn函数,它删除了最后一个元素。
我尝试的实现实际上与Idris中init的定义完全相同。这是在伊德里斯:
init : Vect (S len) elem -> Vect len elem
init
在Idris中,字符串是原语,而不是Haskell中的列表。因此,我希望有某种原始的replace : (needle : String) -> (replacement : String) -> (haystack : String) -> String函数-- la 。我一直找不到这个。但我想,也许我能找到一些replace : Eq a => (needle : List a) -> (replacement : List a) -> (haystack : List a) -> List a函数a la ,因为Idris确实提供了unpack
这个问题最简单的例子(但不是我能展示的唯一例子)是:假设我得到一个更高阶的函数f : (a -> b) -> c。我想证明f = (\g => f (\x => g x))。
在我自己的推理中,它应该非常简单:只需应用两次eta等价(一次在内部,然后在外部)。
如果我想证明f = (\x => f x),一个简单的Refl就足够了:这让我想到"Idris知道eta等价“。但话又说回来,同样的解决方案不适用于f = (\g => f (\x => g x))。
在这一点上,我尝试使用rewrite,但找不到在(\g => f (\x =&g
它们是在Idris 0.9.14中实现的,我成功地使用了induction作为一些证明。但是,它们只适用于某些库类型;例如,Vect支持它们,而几乎同构的All不支持它们:
-Main.h2> induction ys1 INTERNAL ERROR: induction needs an eliminator for Data.Vect.Quantifiers.All
This is probably a bug, or a missing error message.
Please consider reporting at https://github.com/idris-lang
我正在尝试设置Azure Pipeline来为各种平台生成Idris1二进制文件: from head,并使用它为各种平台构建Idris2Head:。
我一直在尝试遵循这里的文档:
我想不出如何获得使其在Idris 2上工作所需的确切YAML。
Idris 1管道在这里:
Idris 2管道在这里:
# Test on Linux
- job: Linux
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: |
echo Collection ID is $(System
TL;DR:我想举一两个在Idris中使用来帮助我更好地理解它的例子。
泛型相等类型的概念定义如下:
data (=) : a -> b -> Type where
Refl : x = x
当我第一次遇到这种情况时,我对语法感到非常困惑。(我一直认为=是一种运算符,而不是类型。)但是在REPL里玩它让我明白了。例如,我们可以声明类型来表示假等式:
λ> 2 + 2 = 5
4 = 5 : Type
λ> 2 = "wombat"
2 = "wombat" : Type
但是,=的唯一构造函数是Refl,只有在两个参数相等时才能使用它
在中有以下几行:
data List a = Nil | (::) a (List a)
data Vect : Nat -> Type -> Type where
Nil : Vect Z a
(::) : a -> Vect k a -> Vect (S k) a
我假设第1行是List的类型定义,其余的是Vect的类型声明。我认为应该有声明和定义,所以我查看了并发现:
data List : (elem : Type) -> Type where
Nil : List elem
(::) : (x : elem) -> (xs
我目前正在尝试下载和使用Idris for Atom,并使用它的编辑器。我从那里下载了Hackage,然后在我的计算机上安装了idris,然后在atom上安装了idris包,当我在程序中输入类似idris应该突出显示的内容时,但是当我输入检查时,我得到了两个错误:“无法找到idris可执行文件:无法在”Idris“和”idris编译器被关闭或崩溃:它(可能)被错误代码:-2“崩溃。
因此,我正在阅读这篇关于精心思考()的论文,并决定尝试这种策略(见第5.2节):
mush : Elab ()
mush =
do attack
x <- gensym "x"
intro x
try intros
induction (Var x) `andThen` auto
solve
据推测,这种策略可以证明加法的相联性:
plusAssoc : (j, k, l : Nat) -> plus (plus j k) l = plus j (plus k l)
plusAssoc = %runE
我只能在Idris 0.9.12中以一种相当笨拙的方式进行秩-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
一个可能更大的问题是,我根本无法在高级别类型中执行类约束。
给定:
$idris -v
0.99
我想升级到版本1。但是,我盲目地尝试通过运行cabal install idris来升级,以查看以下输出:
$cabal install idris
Resolving dependencies...
All the requested packages are already installed:
idris-1.0
Use --reinstall if you want to reinstall anyway.
那么,根据idris -v输出,我似乎已经安装了idris版本1,但是我没有使用它?
考虑到我的情况,我如何使用Idris v1?
我对emacs很陌生(来自vim,我无法让idris-vim工作),并通过el- get安装了这些包:
ace-jump-mode installed A quick cursor location minor mode for emacs.
el-get installed Manage the external elisp bits and pieces you depend upon.
evil-leader installed Add <leader> shortcuts to Evil, the ex
当我在Idris解释器中输入这个简单表达式时,它会导致一个错误:
Idris> (\x=>2.0*x) `map` [1..10]
When checking an application of function Prelude.Functor.map:
Can't find implementation for Enum Double
到底是怎么回事?
我认为这是可行的,因为List Int将映射到List Double中,因为映射类型允许不保留原始类型。
刚开始在Idris (如果它重要的话是Idris 2),并偶然发现这个问题。我正在尝试实现一个函数,该函数返回所有Fibonacci数的向量,直到给定的n。
fibs : (n : Nat) -> Vect (n + 1) Int
fibs Z = [0]
fibs (S Z) = [0, 1]
fibs (S k) =
case (fibs k) of
(x :: y :: xs) => (x + y) :: x :: y :: xs
我得到的错误如下:
Can't solve constraint between:
S (S ?len)
在Haskell中,我可以这样实现if:
if' True x y = x
if' False x y = y
spin 0 = ()
spin n = spin (n - 1)
这符合我的预期
haskell> if' True (spin 1000000) () -- takes a moment
haskell> if' False (spin 1000000) () -- immediate
在Racket中,我可以实现这样一个有缺陷的if:
(define (if2 cond x y) (if cond x y))
(define
如何让Idris自动证明两个值不相等?
p : Not (Int = String)
p = \Refl impossible
如何让Idris自动生成此证明?auto似乎无法证明涉及Not的语句。我的最终目标是让Idris自动证明向量中的所有元素都是唯一的,并且两个向量是不相交的。
namespace IsSet
data IsSet : List t -> Type where
Nil : IsSet []
(::) : All (\a => Not (a = x)) xs -> IsSet xs -> IsSet (x ::
我正在用Idris编写一个基本的一元解析器,以适应Haskell的语法和不同之处。我很好地掌握了这方面的基础知识,但我仍然无法尝试为解析器创建VerifiedSemigroup和VerifiedMonoid实例。
这是解析器类型、半群和Monoid实例,以及VerifiedSemigroup实例的开始。
data ParserM a = Parser (String -> List (a, String))
parse : ParserM a -> String -> List (a, String)
parse (Par