idris

How to encode possible state transitions in type?

人走茶凉 提交于 2020-01-22 18:53:53
问题 I am trying to replicate in Haskell this piece of Idris code, which enforces correct sequencing of actions through types: data DoorState = DoorClosed | DoorOpen data DoorCmd : Type -> DoorState -> DoorState -> Type where Open : DoorCmd () DoorClosed DoorOpen Close : DoorCmd () DoorOpen DoorClosed RingBell : DoorCmd () DoorClosed DoorClosed Pure : ty -> DoorCmd ty state state (>>=) : DoorCmd a state1 state2 -> (a -> DoorCmd b state2 state3) -> DoorCmd b state1 state3 Thanks to overloading of (

How to encode possible state transitions in type?

瘦欲@ 提交于 2020-01-22 18:52:05
问题 I am trying to replicate in Haskell this piece of Idris code, which enforces correct sequencing of actions through types: data DoorState = DoorClosed | DoorOpen data DoorCmd : Type -> DoorState -> DoorState -> Type where Open : DoorCmd () DoorClosed DoorOpen Close : DoorCmd () DoorOpen DoorClosed RingBell : DoorCmd () DoorClosed DoorClosed Pure : ty -> DoorCmd ty state state (>>=) : DoorCmd a state1 state2 -> (a -> DoorCmd b state2 state3) -> DoorCmd b state1 state3 Thanks to overloading of (

`case` that refines arguments

孤街浪徒 提交于 2020-01-15 02:00:28
问题 In this answer on a question about the totality checker, a workaround involving using case instead of with was recommended. However, in situations where the result of the match refines the type of other arguments, this transformation is not straightforward to make. For example, given the following definitions: data IsEven : Nat -> Nat -> Type where Times2 : (n : Nat) -> IsEven (n + n) n data IsOdd : Nat -> Nat -> Type where Times2Plus1 : (n : Nat) -> IsOdd (S (n + n)) n total parity : (n :

How to reverse a HVect in Idris?

六月ゝ 毕业季﹏ 提交于 2020-01-14 10:25:10
问题 I'm new to Irdis. Is it possible to reverse a HVect? If I call reverse on a HVect [String, Int] it should return a HVect [Int, String] and if I call reverse on a HVect [String, Int, Day] it should return a HVect [Day, Int, String] . I tried to reuse Data.Vect.reverse (Gist) module reverse_hvect import Data.HVect reverse : HVect ts -> HVect (reverse ts) reverse [] = [] reverse (x::xs) = (reverse xs) ++ [x] but I get Type checking .\reverse_hvect.idr reverse_hvect.idr:7:9:When checking right

Why do Maybe/Optional types use a Just/Some type instead of the actual type?

↘锁芯ラ 提交于 2020-01-10 03:47:25
问题 In Idris, the Maybe type is defined as followed: data Maybe a = Just a | Nothing It's defined similarly in Haskell: data Maybe a = Just a | Nothing deriving (Eq, Ord) Here's the ML version: datatype 'a option = NONE | SOME of 'a What are the benefits of using Just and Some ? Why not define the type without them? example: data Maybe a = a | Nothing 回答1: What would then be the difference between Maybe a and Maybe (Maybe a) ? There's supposed to be a difference between Nothing and Just Nothing .

How to define a pair type in Idris that only holds certain combinations of values

此生再无相见时 提交于 2020-01-04 09:59:30
问题 I'm trying to learn about dependent types in Idris by attempting something way out of my depth. Please bear with me if I make any silly mistakes. Given the simple type data Letter = A | B | C | D I would like to define a type LPair that holds a pair of Letter such that only "neighboring" letters can be paired. For example, B can be paired with A or C , but not D or itself. It wraps around, so A and D are treated as neighbors. In practice, given x : Letter and y : Letter , mklpair x y would be

Idris rewrite does not happen

偶尔善良 提交于 2020-01-03 20:47:25
问题 import Data.Vect import Data.Vect.Quantifiers sameKeys : Vect n (lbl, Type) -> Vect n (lbl, Type) -> Type sameKeys xs ys = All (uncurry (=)) (zip (map fst xs) (map fst ys)) g : {xs,ys : Vect n (lbl, Type)} -> sameKeys xs ys -> map (\b => fst b) xs = map (\b => fst b) ys g {xs = []} {ys = []} [] = Refl g {xs = x::xs} {ys = y::ys} (p::ps) = rewrite g ps in ?q This is the error I see: *main> :load main.idr Type checking ./main.idr main.idr:57:3:When checking right hand side of g with expected

Idris: function works with Nat parameter and fails type checking with Integer parameter

别说谁变了你拦得住时间么 提交于 2019-12-31 04:10:28
问题 I am new to Idris. I am experimenting with types and my task is to make an "onion": a function that takes two arguments: a number and whatever and puts whatever into List nested such number of times. For example, the result for mkOnion 3 "Hello World" should be [[["Hello World"]]] . I've made such a function, this is my code: onionListType : Nat -> Type -> Type onionListType Z b = b onionListType (S a) b = onionListType a (List b) mkOnionList : (x : Nat) -> y -> onionListType x y mkOnionList

Control.ST pure type

本秂侑毒 提交于 2019-12-25 03:26:36
问题 pure : (result : ty) -> STrans m ty (out_fn result) out_fn from http://docs.idris-lang.org/en/latest/st/state.html#strans-primitive-operations I'm not sure what (out_fn result) out_fn means. Is it about constraining out_fn to be a function of result ? Does it actually say anything about the input resource list? The given explanation seems to be "...provided that the current list of resources is correct when producing that value" but I'm not sure how to interpret it. 回答1: STrans : (m : Type ->

Idris in atom editor, “Couldn't find Idris executable” error

Deadly 提交于 2019-12-24 21:04:15
问题 I am currently trying to download and use Idris for Atom and use it's editor. I downloaded Hackage and then installed idris on my computer from there and then installed the idris package on atom, and when ever I type in the program it highlights like Idris should, but when I type check it I am getting two errors, "Couldn't find idris executable: Couldn't find idris executable at "Idris"" and "The idris compiler was closed or crashed: It (probably) crashed with error code : -2". picture of the