# Type Constructors

type/Arity = product/Arity | sum/Arity |

# Sample

### atom().

tree(A) = sum(product(A),product(tree(A),tree(A)))

= {A} | {tree(A),tree(A)}.

array(T) = list(list(T)).

cube(T) = list(array(T)).

typeCons(A,B,C) = product(A,B,list(C)).

# Non-proper

typeCons = product(any(),any(),list/1).

# Functions

listmap = fun((Fun::fun(A::X,B::Y),In::list(X))-> list(Y)) ->
io:format("In: ~p",[In]),
Out = [ Fun(E) || E <- In],
io:format("Out: ~p",[Out]),
Out end.

fmap = fun(fun(any(),any()),type/1).
listmap = fun(fun(A,B),list(A),list(B)).
unimap(A,B,T::type/1) = fun(fun(A,B),T(A),T(B)).

# Simple Functors

tree(A) = sum(product(A),product(tree(A),tree(A)))
= {A} | {tree(A),tree(A)}.

Functor = cat(Type::type/1) ->
fmap = fun(fun(A,B),Type(A),Type(B)). end.

Listfunctor = Functor(list/1) ->
fmap(F,X) -> listmap(F,X). end.

Square = fun(X) -> X * X end.
Listfunctor:fmap(Square,[1,2,3,4]).

# Kinds

Typed Erlang      System Fω

type(A)               * -> *
type(A,B)                   * -> * -> *
type(A::type/1)            (* -> *) -> *

functor = cat(Type::type/1) ->
fmap = fun(fun(A,B),Type(A),Type(B)). end.

other = fun((F::type(A))->lift(F,A)).

pure = fun((A)->lift(type(A))).

lift(F::type(A)) = sum(pure(A),other(F(A))).

free(F::functor(A)) = sum(pure(A), free(F(free(F(A))))).

# Discussion

## https://github.com/5HT/et

#### Typed Erlang

By Maxim Sokhatsky

• 1,830