Idris2/libs/base/Data/Fun.idr
2020-08-18 22:26:56 +01:00

26 lines
597 B
Idris

module Data.Fun
import public Data.Vect
%default total
||| Build an n-ary function type from a Vect of Types and a result type
public export
Fun : Vect n Type -> Type -> Type
Fun [] r = r
Fun (t::ts) r = t -> Fun ts r
public export
chain : {ts : Vect n Type} -> Fun [r] r' -> Fun ts r -> Fun ts r'
chain {ts = []} g r = g r
chain {ts = (_::_)} g f = \ x => chain g (f x)
public export
[Nary] {ts : Vect n Type} -> Functor (Fun ts) where
map = chain
||| Returns the co-domain of a n-ary function.
public export
target : {ts : Vect n Type} -> {r: Type} -> Fun ts r -> Type
target {r} _ = r