我是Idris的初学者。在Idris2版本0.3.0中,我观察到一个奇怪的行为。
为什么不检查代码类型?
f : Type -> Type -> Type
f a b = (c : Bool) -> if c then a else b
While processing right hand side of f. Main.case block in f is not accessible in this context.
虽然此代码类型检查没有问题:
f1 : Type -> Type -> Bool -> Type
f1 a b c = if c the
idris中有一个函数计数,定义为:
count : Eq a => a -> Vect n a -> Nat
count x [] = Z
count x (y::ys) = with (x == y)
| True = S (count x ys)
| False = count x ys
并且可以返回最大值计数的证明:
countLTELen : Eq a => (x : a) -> (l : Vect n a) -> LTE (count x l) n
countLTELen x [] = lteRefl
countLteLen x (y::
我是(为了好玩?)试着研究如何在伊德里斯证明这一点。我需要的属性之一是整数的全序。Idris已经拥有提供基于电感的整数的模块。我需要添加一个类似于Nat的的类型。我似乎无法让自己相信我的实现是正确的(或者LTE对此是正确的)。如何“检查”我正在处理的LTEZZ数据类型?如何检查(LTE 4 3)是否无效?
示例代码如下:
%default total
||| Proof the a is <= b
||| a is the smaller number
||| b is the larger number
data LTEZZ : (a : ZZ) -> (b : ZZ) ->
我试图定义依赖类型的n进制函数(构建为二进制函数和一元函数的树;我怀疑这与(Vect n a) -> a的类型是同构的),作为学习Idris的一个练习。
在试图定义一个将参数应用于n进制函数(产生(n-1)-ary函数)的函数时,我得到了一个非常可疑的错误:
Type mismatch between
ArityFn m a (Type of ng)
and
ArityFn (minus m 0) a (Expected type)
Specifically:
Type mismatch b
我试图用Idris编写一个关于以下基于减法的mod操作符的证明:
mod : (x, y : Nat) -> Not (y = Z) -> Nat
mod x Z p = void (p Refl)
mod x (S k) _ = if lt x (S k) then x else helper x (minus x (S k)) (S k)
where total
helper : Nat -> Nat -> Nat -> Nat
helper Z x y = x
helper (S k) x y = if l
我正在自学python,我正在尝试创建一个密码生成器。我想要程序做的是,生成一个随机密码并将其保存到文本文件中。我在获取密码以保存到文本文件方面有什么问题。我能够获得一个生成的密码,但是我在text_file file.write( output ) NameError中得到了一个错误代码:虽然我已经定义了输出,但没有定义名称'output‘。如果有人能告诉我我做错了什么,我会很感激的。如果需要更多的信息,请告诉我。谢谢
import random
import string
# Generates a password from random.choice
length = int
Idris具有非常简单的cong函数。
cong : {f : t -> u} -> a = b -> f a = f b
cong Refl = Refl
如果我为超过零的加法创建一个特殊形式的cong,它不能进行类型检查。
cong0 : {f : Nat -> Nat} -> a + Z = a -> f (a + Z) = f a
cong0 Refl = Refl
在Idris 1中,我得到了
When checking left hand side of cong0:
When checking an application of Main.co
Agda使用以下操作符显示集合之间的逆:
_↔_ : ∀ {f t} → Set f → Set t → Set _
在Idris中也有类似的吗?我试图在列表中定义包的相等性
data Elem : a -> List a -> Type where
Here : {xs : List a} -> Elem x (x :: xs)
There : {xs : List a} -> Elem x xs -> Elem x (y :: xs)
(~~) : List a -> List a -> Type
xs ~~ ys {a} = Elem
我正在用Idris编写一个基本的一元解析器,以适应Haskell的语法和不同之处。我很好地掌握了这方面的基础知识,但我仍然无法尝试为解析器创建VerifiedSemigroup和VerifiedMonoid实例。
这是解析器类型、半群和Monoid实例,以及VerifiedSemigroup实例的开始。
data ParserM a = Parser (String -> List (a, String))
parse : ParserM a -> String -> List (a, String)
parse (Par
我对伊德里斯有点陌生。我以前用过一点agda,我在GHC Haskell有很强的背景。我试着去理解为什么在GHC Haskell中工作的东西在Idris不起作用。以下代码未编译(idris版本0.12.3,nobuiltins,noprelude):
data Nat = S Nat | Z
plus : Nat -> Nat -> Nat
plus Z right = right
plus (S left) right = S (plus left right)
rightIdentityAlt : (n : Nat) -> n = (plus n Z)
向量cons的下列声明
cons : a -> Vect n a -> Vect (n + 1) a
cons x xs = x :: xs
与错误一起失败
Type mismatch between
S n
and
plus n 1
当下面的向量append编译并工作时
append : Vect n a -> Vect m a -> Vect (n + m) a
append xs ys = xs ++ ys
为什么类型级别的plus在第二种情况下被接受,而对于第一种情况则不被接受。有什
我正在尝试从数据库中提取一些记录(关于杂志),以创建带有统计数据的表。提取是根据时间和杂志的名称。下面是我目前的代码,但我认为它不够枯燥,原因有二:
def get_statistic(date__gte=None, date__lte=None, name=None):
magazines_qs = Magazines.objects.all()
#1 move filters to "for"
#2 get rid of "if" statement (may be by setting default values which
如何让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,Agda,Coq和类似的地方推导出教会编码的Nat类型。注意,这与在CoC (众所周知是不可能的)上做这件事不同,因为我们对这些元素有更多的表现力(例如,我们能够提取Sigma的第二个元素)。
下面是关于Idris的一个糟糕的证明草图(有很多语法问题):
CN : Type
CN = (t : Type) -> t -> (t -> t) -> t
CS : CN -> CN
CS n t z s = s (n t z s)
CZ : CN
CZ t z s = z
ind :
(p : CN -> Type)
给定两个接口:
interface Poset a (po : a -> a -> Type) where
reflexive : (x : a) -> x `po` x
interface JoinSemilattice a where
join : a -> a -> a
joinAssociative : (x, y, z : a) -> x `join` (y `join` z) = (x `join` y) `join` z
我希望使用以下类型同义词在给定第二个接口的情况下实现第一个接口:
LTE : JoinSemilattice
我试图证明在将一个向量分成三个部分后,每个部分的长度都小于原始向量。下面是我的实现:
||| Split into three parts: two lists and a single element
data Sp : Type -> Type where
MkSp : List a -> a -> List a -> Sp a
||| cons an element into the left list
spConsL : a -> Sp a -> Sp a
spConsL x (MkSp xs y ys) = MkSp (x :: xs) y y
我发现Nat的Nat函数是用实现的。
total plus : (n, m : Nat) -> Nat
plus Z right = right
plus (S left) right = S (plus left right)
我想知道是否有特别的理由不对第二个论点进行模式匹配,就像下面这样:
total plus : (n, m : Nat) -> Nat
plus Z right = right
plus left Z = left
plus (S left) right = S (plus left right)
正如我目前所看到
在以下代码中
Idris> :t \x => x + x
\x => x + x : Integer -> Integer
Idris为x变量派生了一个Integer类型,我认为它应该得到一个接口限制,如Haskell中的那样:
Haskell> :t (\x y -> x + y)
(\x y -> x + y) :: Num a => a -> a -> a
然后,它甚至不像一个整数,接受双重类型:
Idris> (\x => x + x) 2.0
4.0 : Double
有人能给我解释一下吗?
由于类型在Idris中是第一类的,所以我应该能够编写一个返回参数类型的typeOf函数:
typeOf : a => a -> Type
typeOf x = a
然而,当我试图调用这个函数时,我会得到一个看起来像是错误的信息:
*example> typeOf 42
Can't find implementation for Integer
我如何才能正确地实现这个typeOf 函数呢?,还是关于“获取所缺少的值类型”的想法是否有更微妙的东西,从而阻止了这样一个函数的存在?
我一直在冥想共通,并有一个直觉,一个非空的列表(“完整的列表”)是一个共通。我在Idris中构造了一个看似可行的实现,并致力于证明,但未能证明其中一个规则的递归分支。我如何证明这一点( ?i_do_not_know_how_to_prove_this_if_its_provable漏洞)--或者我是否错了我的实现是一个有效的comonad (我看过实现,它似乎与我的实现相同)?
module FullList
%default total
data FullList : Type -> Type where
Single : a -> FullList a
Cons :
给定向量的这种类型,如何创建特定类型的项目的零长度向量?
data Vect : Nat -> Type -> Type where
VectNil : Vect 0 ty
(::) : ty -> Vect size ty -> Vect (S size) ty
VectNil字符串和我在REPL中尝试过的所有变体都失败了。期望VectNil像C#中泛型列表的默认构造函数那样工作难道不正确吗?
new List<string> (); // creates a zero length List of string
我有一个减去两个Nat的函数,如何证明传递给它的第一个参数实际上比第二个参数小 dummy : (k : Nat) -> (n : Nat) -> {auto smaller : LTE k n} -> Nat
dummy k n = n - k 我试过几种解决方案,但都不起作用 smallerThan : (k : Nat) -> (n : Nat) -> Maybe (LTE k n)
smallerThan Z k = Just (LTEZero {right=k})
smallerThan (S k) Z = Nothing
smallerThan (S
受和的启发,我想我应该尝试Idris中的一些类别理论,使用它的接口(类型类)。
我定义了Category如下,它工作得很好:
interface Category (obj : Type) (hom : obj -> obj -> Type) where
id : {a : obj} -> hom a a
comp : {a, b, c : obj} -> hom b c -> hom a b -> hom a c
然后,本着模块的精神,我想我应该定义一个经过验证的类别:
interface Category obj hom =>
我正在尝试设置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
我是伊德里斯的新手。我需要创建一个描述有界数字的数据。因此,我使用这样的构造函数创建了这样的数据:
data BoundedDouble : (a, b : Double) -> Type where
MkBoundedDouble : (x : Double) ->
{auto p : a <= x && x <= b = True} ->
BoundedDouble a b
它似乎在a和b之间创建了一个b。下面是一个简单的使用示例:
test : Bound