Questions tagged [idris]

Idris is a general purpose pure functional programming language with dependent types.

Idris is a general-purpose purely functional programming language with dependent types, strict or optional lazy evaluation and features such as a totality checker.


Useful links:

785 questions
11
votes
1 answer

Any tricks to get rid of boilerplate when constructing proofs of absurd predicate on enums?

Let's say I have data Fruit = Apple | Banana | Grape | Orange | Lemon | {- many others -} and a predicate on that type, data WineStock : Fruit -> Type where CanonicalWine : WineStock Grape CiderIsWineToo : WineStock Apple which doesn't…
ulidtko
  • 14,740
  • 10
  • 56
  • 88
11
votes
1 answer

Tell dependent function in conditional statement branch that condition is true

I have a function with a type signature (x, y : SomeType) -> (cond x y) = True -> SomeType. When I check the condition in if-then-else/case/with statement, how do I pass to the function in a corresponding branch the fact, that condition is true?
Anonymous
  • 449
  • 2
  • 9
11
votes
2 answers

Use named instances for other instances

I'm trying to make a Semigroup and VerifiedSemigroup instance on my custom Bool datatype both on operator && and operator ||: %case data Lógico = Cierto | Falso (&&) : Lógico -> Lógico -> Lógico (&&) Cierto Cierto = Cierto (&&) _ _ = Falso (||) :…
chamini2
  • 2,820
  • 2
  • 24
  • 37
10
votes
2 answers

How to map Type to Value in Idris/Agda/Coq?

I'm trying to define a function named byteWidth, which captures the usage about "get byte width of specific atomic type". My 1st trial: byteWidth : Type -> Int byteWidth Int = 8 byteWidth Char = 1 And the Idris compiler complains: "When checking…
luochen1990
  • 3,689
  • 1
  • 22
  • 37
10
votes
1 answer

How can I get Idris to unmap a vector in order to infer a type?

I have the following working function: unMaybe : (t : Type) -> {auto p : t = Maybe x} -> Type unMaybe {x} _ = x This function works fine: > unMaybe (Maybe Int) Int I also have another similar function: unMaybesA : (ts : Vect n Type) -> {xs : Vect…
michaelmesser
  • 3,601
  • 2
  • 19
  • 42
10
votes
3 answers

Why is filter based on dependent pair?

In the Idris Tutorial a function for filtering vectors is based on dependent pairs. filter : (a -> Bool) -> Vect n a -> (p ** Vect p a) filter f [] = (_ ** []) filter f (x :: xs) with (filter f xs ) | (_ ** xs') = if (f x) then (_ ** x :: xs')…
trevor cook
  • 1,531
  • 8
  • 22
10
votes
2 answers

Why doesn't this Idris snippet typecheck without an explicit type?

I'm just getting started learning Idris, and I'm working through the book Type Driven Development with Idris. One of the example exercises from the second chapter is to write a function which, given a string, determines the average length of a word…
10
votes
6 answers

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

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…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
10
votes
1 answer

Relevance of model checking in strongly typed functional programming languages?

I am currently learning about model checking (modal logic, LTL, CTL, SAL model checker, etc.) and in my spare time I am learning about Idris which is a strongly typed functional programming language that supports dependent types. Since I am looking…
Michelrandahl
  • 3,365
  • 2
  • 26
  • 41
10
votes
1 answer

How do you formalize the numeric tower on functional languages?

Everyone knows the elegant way to express natural numbers on dependently typed functional languages: data Nat = Zero | Succ Nat Integer, Fraction, Real, Complex and Quaternion are, too, very important for practical programming application. One…
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
10
votes
1 answer

What are cumulative universes and `* : *`?

In Agda, there is Set n. As I understand, Set n extends the Haskell-style value-type-kind hierarchy to infinite levels. That is, Set 0 is the universe of normal types, Set 1 is the universe of normal kinds, Set 2 is the universe of normal sorts,…
盛安安
  • 1,110
  • 1
  • 8
  • 21
10
votes
1 answer

Prove map id = id in idris?

I'm just starting playing with idris and theorem proving in general. I can follow most of the examples of proofs of basic facts on the internet, so I wanted to try something arbitrary by my own. So, I want to write a proof term for the following…
comco
  • 573
  • 4
  • 13
10
votes
1 answer

Haskell-style type families

In Haskell, I might write a typeclass with a type declaration to create a type family, like so: class ListLike k where type Elem :: * -> * fromList :: [Elem k] -> k And then write instances like this: instance ListLike [a] where type…
AJF
  • 11,767
  • 2
  • 37
  • 64
10
votes
2 answers

Is there a nice way to use `->` directly as a function in Idris?

One can return a type in a function in Idris, for example t : Type -> Type -> Type t a b = a -> b But the situation came up (when experimenting with writing some parsers) that I wanted to use -> to fold a list of types, ie typeFold : List Type ->…
Vic Smith
  • 3,477
  • 1
  • 18
  • 29
10
votes
2 answers

The best way to convert a String to an Integer or Natural in Idris

What is the best way to convert a String to an Integer or Natural in Idris? I know the standard library is still a work in progress and so if the answer is I should add it to the standard library then that's fine I will try and do that, but before I…
jedesah
  • 2,983
  • 2
  • 17
  • 29