Erlang


System Fω


LOL WUT

Types


                    fun(A,B,...) -> A -> B -> ...
                    product(A,...) -> {A,...}
                    sum(A,B,...) -> A | B | ...
                    cat(A,B,...) -> 
                                 Domains(A,B,...), 
                                 Morphisms(A,B,...), ... end.


Type Constructors



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


      fun/Arity | cat/Arity | list/1 | any 


Sample


string() = list(char) = string/0.

integer().

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).

main = fun/2.


product/3 = product(any(),any(),any()).


mylist = product(list(product/3),sum/2,any).

lst = list/1.


functorArg = type/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)            (* -> *) -> *

Free Monads


 
            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

Typed Erlang

  • 4,873