Interfaces - Idris implements ad-hoc polymorphism (name overloading) using a system of interfaces. - Idris interfaces are based on Haskell typeclasses. - Each Interface defines a collection of signatures (called "methods") involving variables, and represents a constraint on those variables. - An interface may include constraints determined by other interfaces. - Some interface methods may be defined in terms of others. A generating set of interface methods is called a "basis". - An implementation or "instance" of an interface provides a definition for a basis of the methods, and represents a solution to the constraint on the variables involved. - When Idris encounters an interface method in a program, it searches for a solution to the constraint in the current scope. - There are two ways to satisfy a constraint: * treat the constraint as a property by providing an unnamed "default" implementation, * treat the constraint as a structure by providing a named implementation. Partial List of Interfaces from the standard library: -- conversion to a string (in Prelude.Show): Show : Type -> Constraint show : {a : Type} -> Show a => a -> String -- deciding equality (in Prelude.Interfaces): Eq : Type -> Constraint (==) , (\=) : {a : Type} -> Eq a => a -> a -> Bool -- total ordering (in Prelude.Interfaces): Ord : (a : Type) -> Eq a => Constraint compare : {a : Type} -> Ord a => a -> a -> Ordering -- casting (in Prelude.Cast): Cast : Type -> Type -> Constraint cast : {a , b : Type} -> Cast a b => a -> b -- associative operations (in Prelude.Algebra): Semigroup : Type -> Constraint (<+>) : {a : Type} -> Semigroup a => a -> a -> a -- semigroups with a neutral element (in Prelude.Algebra): Monoid : (a : Type) -> Semigroup a => Constraint neutral : {a : Type} -> Monoid a => a -- parameterized type that lift functions (in Prelude.Functor): Functor : (Type -> Type) -> Constraint map : {t : Type -> Type} -> Functor t => (a -> b) -> (t a -> t b) -- functors with a unit that support partial application (in Prelude.Applicative): Applicative : (t : Type -> Type) -> Functor t => Constraint pure : {t : Type -> Type} -> Applicative t => a -> t a (<*>) : {t : Type -> Type} -> Applicative t => t (a -> b) -> (t a -> t b) -- applicative functors with iterative structure (in Prelude.Monad): Monad : (t : Type -> Type) -> Applicative t => Constraint join : {t : Type -> Type} -> Monad t => t (t a) -> t a Defining Interfacs: interface [Interface Variables] where [Interface Methods]