idris

bind to abstract types for c struct with idris

柔情痞子 提交于 2021-02-11 12:20:24
问题 I can not find how to treat this typedef struct TF_Status TF_Status; as abstract types and bind to that the c function is TF_Status* TF_NewStatus(); data TF_Status tfNewStatus : IO TF_Status tfNewStatus = foreign FFI_C "TF_NewStatus" (IO TF_Status) http://docs.idris-lang.org/en/latest/reference/ffi.html it complains that When checking argument fty to function foreign: Can't find a value of type FTy FFI_C [] (IO TF_Status) 回答1: TF_Status* TF_NewStatus(); returns a pointer to a TF_Status when

How can I create a function that only accepts a subset of constructors of a type?

筅森魡賤 提交于 2021-02-07 06:50:20
问题 Let's say I have a type like this: data Foo = Bar String | Baz | Qux String I want to have a function like this: get : Foo -> String get (Bar s) = s get (Qux s) = s As written, this compiles, but it's not total, as there are missing cases; in other words, get Baz is treated like a hole rather than as an expression that doesn't typecheck. I want to replace that Foo in the type signature of get with something that specifies that the value must be either a Bar or a Qux . How can I express this

Idris: proof about concatenation of vectors

对着背影说爱祢 提交于 2021-01-28 05:05:47
问题 Assume I have the following idris source code: module Source import Data.Vect --in order to avoid compiler confusion between Prelude.List.(++), Prelude.String.(++) and Data.Vect.(++) infixl 0 +++ (+++) : Vect n a -> Vect m a -> Vect (n+m) a v +++ w = v ++ w --NB: further down in the question I'll assume this definition isn't needed because the compiler -- will have enough context to disambiguate between these and figure out that Data.Vect.(++) -- is the "correct" one to use. lemma : reverse

Idris: proof about concatenation of vectors

感情迁移 提交于 2021-01-28 04:37:19
问题 Assume I have the following idris source code: module Source import Data.Vect --in order to avoid compiler confusion between Prelude.List.(++), Prelude.String.(++) and Data.Vect.(++) infixl 0 +++ (+++) : Vect n a -> Vect m a -> Vect (n+m) a v +++ w = v ++ w --NB: further down in the question I'll assume this definition isn't needed because the compiler -- will have enough context to disambiguate between these and figure out that Data.Vect.(++) -- is the "correct" one to use. lemma : reverse

Finding an implementation (of show) for an inductively defined type

荒凉一梦 提交于 2021-01-27 23:06:17
问题 The following snippet was from (https://stackoverflow.com/a/37461290/2129302): tensor : Vect n Nat -> Type -> Type tensor [] a = a tensor (m :: ms) a = Vect m (tensor ms a) I'd like to define the following: mkStr : (Show a) => tensor shape a -> String mkStr x = show x But instead this gives the following error: Can't find implementation for Show (tensor shape a) However, on the REPL I can run "show [some tensor value...]". Why is this and what can I do to fix it? 回答1: You're not showing a ,

How does the order of implicit arguments affect idris?

*爱你&永不变心* 提交于 2021-01-27 22:22:01
问题 This fails: > the ({A : Type} -> A -> {B : Type} -> B -> (A, B)) MkPair (input):1:5:When checking argument value to function Prelude.Basics.the: Type mismatch between A -> B1 -> (A, B1) (Type of MkPair) and A1 -> B -> (A1, B) (Expected type) Specifically: Type mismatch between Pair A and \uv => uv -> uv This works: > ({A : Type} -> {B : Type} -> A -> B -> (A, B)) MkPair \A1, B1 => MkPair : A -> B -> (A, B) Oddly: q : {A : Type} -> A -> {B : Type} -> B -> (A, B) q a b = MkPair a b > :t q q : A

Finding an implementation (of show) for an inductively defined type

前提是你 提交于 2021-01-27 21:50:49
问题 The following snippet was from (https://stackoverflow.com/a/37461290/2129302): tensor : Vect n Nat -> Type -> Type tensor [] a = a tensor (m :: ms) a = Vect m (tensor ms a) I'd like to define the following: mkStr : (Show a) => tensor shape a -> String mkStr x = show x But instead this gives the following error: Can't find implementation for Show (tensor shape a) However, on the REPL I can run "show [some tensor value...]". Why is this and what can I do to fix it? 回答1: You're not showing a ,

How does the order of implicit arguments affect idris?

坚强是说给别人听的谎言 提交于 2021-01-27 20:50:03
问题 This fails: > the ({A : Type} -> A -> {B : Type} -> B -> (A, B)) MkPair (input):1:5:When checking argument value to function Prelude.Basics.the: Type mismatch between A -> B1 -> (A, B1) (Type of MkPair) and A1 -> B -> (A1, B) (Expected type) Specifically: Type mismatch between Pair A and \uv => uv -> uv This works: > ({A : Type} -> {B : Type} -> A -> B -> (A, B)) MkPair \A1, B1 => MkPair : A -> B -> (A, B) Oddly: q : {A : Type} -> A -> {B : Type} -> B -> (A, B) q a b = MkPair a b > :t q q : A

Idris - map an operation on a n-dimensional vector

好久不见. 提交于 2021-01-27 07:35:30
问题 I defined n-dimensional vectors in Idris as follows: import Data.Vect NDVect : (Num t) => (rank : Nat) -> (shape : Vect rank Nat) -> (t : Type) -> Type NDVect Z [] t = t NDVect (S n) (x::xs) t = Vect x (NDVect n xs t) Then I defined the following function which maps a function f to every entry in the tensor. iterateT : (f : t -> t') -> (v : NDVect r s t) -> NDVect r s t' iterateT {r = Z} {s = []} f v = f v iterateT {r = S n} {s = x::xs} f v = map (iterateT f) v But when I try to call

Idris - map an operation on a n-dimensional vector

那年仲夏 提交于 2021-01-27 07:35:22
问题 I defined n-dimensional vectors in Idris as follows: import Data.Vect NDVect : (Num t) => (rank : Nat) -> (shape : Vect rank Nat) -> (t : Type) -> Type NDVect Z [] t = t NDVect (S n) (x::xs) t = Vect x (NDVect n xs t) Then I defined the following function which maps a function f to every entry in the tensor. iterateT : (f : t -> t') -> (v : NDVect r s t) -> NDVect r s t' iterateT {r = Z} {s = []} f v = f v iterateT {r = S n} {s = x::xs} f v = map (iterateT f) v But when I try to call