Code Monkey home page Code Monkey logo

henk's Introduction

Henk: Pure Type System

Henk languages described first by Erik Meijer and Simon Peyton Jones in 1997. Later on in 2015 a new implementation of the ideas in Haskell appeared, called Morte. It used the Bâhm-Berarducci encoding of recursive data types into non-recursive terms. Morte has constants, variables, and kinds, is based only on П, λ and apply constructions, one axiom and four deduction rules. The Henk language resembles Henk design and Morte implementation. This language is indended to be small, concise, easily provable, clean and be able to produce verifiable programs that can be distributed over the networks and compiled at target with safe linkage.

$ mix deps.get
$ iex -S mix

The Henk Syntax is the following:

   <> ::= #option

    I ::= #identifier

    U ::= * < #number >

    O ::= U | I | ( O ) | O O
            | Ξ» ( I : O ) β†’ O
            | βˆ€ ( I : O ) β†’ O

Henk is an implementation of PTS with an Infinite Number of Universes, the pure lambda calculus with dependent types. It can be compiled (code extraction) to bytecode of Erlang virtual machines BEAM and LING.

Trusted PTS with an Infinite Universes

In repository henk you may find the following parts of core:

Henk ships with different "modes" (spaces of types with own encodings), or "preludes", which you may find in lib directory. They are selectable with om:mode("normal").

henk.groupoid.space/lib/normal/
  β”œβ”€β”€ Bool
  β”œβ”€β”€ Cmd
  β”œβ”€β”€ Eq
  β”œβ”€β”€ Equ
  β”œβ”€β”€ Frege
  β”œβ”€β”€ IO
  β”œβ”€β”€ IOI
  β”œβ”€β”€ Lazy
  β”œβ”€β”€ Leibnitz
  β”œβ”€β”€ List
  β”œβ”€β”€ Maybe
  β”œβ”€β”€ Mon
  β”œβ”€β”€ Monad
  β”œβ”€β”€ Monoid
  β”œβ”€β”€ Morte
  β”œβ”€β”€ Nat
  β”œβ”€β”€ Path
  β”œβ”€β”€ Prod
  β”œβ”€β”€ Prop
  β”œβ”€β”€ Sigma
  β”œβ”€β”€ Simple
  β”œβ”€β”€ String
  β”œβ”€β”€ Unit
  └── Vector

This is a minimal practical prelude similar to Morte's base library of Gabriella Gonzalez. It contains common inductive constructions encoded using plain Church (or BΓΆhm-Berarducci if you wish) encoding, and two basic (co)monadic effect systems: IO (free monad, for finite I/O) and IOI (free comonad, for infinitary I/O, long-term processes). The generated code is being sewed with Erlang effects that are passed as parameters to pure functions.

Note: all these folders (modules) are encoded in plain CoC in Henk repository to demonstrate you the basic principles how things work. Later all these should be written in Per languages and translated to Henk automatically (if possible). You may think of Henk as the low-level typed assembler of type theory.

PTS

Credits

henk's People

Contributors

5ht avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

henk's Issues

Examples of normalization corner cases

A term that looks much worse after normalization. E.g. the one that uses sharing extensively.

It is not a counterexample to normalization per se, but to normalization seen as optimization or god forbid superoptimization.

Some questions

Hi, this is a very nice project. Since pure is based on the Calculus of Constructions, there are two worries one could have:

  • Although you can state the induction principle for an inductive type, you can not prove it. So even though you have dependent types, without induction these are not particularly useful (I think).
  • There is no way to write an efficient pattern matching function for an inductive type in CoC. For example when defining a natural number datatype, you cannot write a predecessor function that runs in O(1).

Have you thought about these things, or are the irrelevant?

Make stream parsers modular for Exe development

Copy-Paste for now is ok, but we need deeper understanding of AST enrichment through ordered blocks of stream parsers chained in one function-pipeline. This would be an Erlang prototype of the future Exe modular stream parser.

Parser Error

$ cat intro
  βˆ€ (Intro:
    (
      βˆ€ (a : A)
    β†’ βˆ€ (aok  : AOk a)
    β†’ BOk (isoAB a)
    )
  β†’ ( βˆ€ (a1: A)
    β†’ βˆ€ (a1ok : AOk a1)
    β†’ βˆ€ (a2 : A)
    β†’ βˆ€ (a2ok: AOk a2)
    β†’ AEqu a1 a2
    β†’ BEqu (isoAB a1) (isoAB a2)
    )
  β†’ AND)
β†’ AND

There is a workaround involving additional pair of brackets for Intro type.

reference substitution before parsing is exponencially inefficient // do use cache table

parsing become very slow for resonable terms
(or parser is not linear in time???)

user@note:~/github/groupoid/om$ time (./om a "#sec2all" , mode "new-posets" > /dev/null)
eheap_alloc: Cannot allocate 529782288 bytes of memory (of type "heap").

real    0m44.392s
user    0m40.764s
sys 0m18.952s
user@note:~/github/groupoid/om$ time (./om print type a "#sec2all" , mode "new-posets" > /dev/null)

real    0m45.879s
user    0m44.152s
sys 0m16.196s

test data: https://github.com/groupoid/om/blob/c970619f039433454a06e31b6e9948873cff110c/priv/new-posets/sec2all

Typechecker Error Messages

 -error({input,X})        -> om:print("Invalid input type: ~p~n",[X]);
 -error({output,X})       -> om:print("Invalid output type: ~p~n",[X]);
 -error({untyped,X})      -> om:print("No type for: ~p~n",[X]);
 -error({mismatch,{X,Y}}) -> om:print("Invalid Application~nExpected type: ~p~nArgument type: ~p~n",[X,Y]);
 -error({unbound,U})      -> om:print("Unbound variable ~p.~n",[U]);
 -error({app,A})          -> om:print("Only functions may be applied to values ~p.~n",[A]);

Uninline Morte Samples

Files #Morte/recursive and #Morte/corecursive are inlined.
We need to uninline them to use #IO/Make and #Maybe/maybe FQN external files.

Typos in README.md

diff --git a/README.md b/README.md
index 1e0732a..e8f0d1d 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Maxim Sokhatsky [email protected]

 ![Om](http://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Georg_Simon_Ohm3.jpg/200px-Georg_Simon_Ohm3.jpg)

-Georg Simon Ohm -- a German physicist and mathematician who was born in german town Erlangen. 
+Georg Simon Ohm -- a German physicist and mathematician who was born in German town Erlangen. 

 Abstract
 --------
@@ -47,7 +47,7 @@ from Ξ» value-level functions.

 Note than list/1 is special type constructor only for built-in Erlang list types.
 All type constructors with zero arity denoted as concrete types. It has 
-compatiblity with Erlang dializer syntax, e.g.:
+compatibility with Erlang dializer syntax, e.g.:

     string() = list(char) = string/0.
     integer().
@@ -69,7 +69,7 @@ Here is type constructors which are partially constructed with not concrete type
     lst = list/1.
     functorArg = type/1.

-Here is mix of dependance of concrete types and partially constructed:
+Here is mix of dependence of concrete types and partially constructed:

     mixed(T,A) = product(A,any,sum(T,list(T)),product/3,fun/2,functor(list/1)).

@@ -77,7 +77,7 @@ Kinds Notion
 ------------

 Type constructors 'cat', 'fun', 'sum' and 'product' belongs to type 'type' which
-is also typeable by number of arguments and signature of type construdctor:
+is also typeable by number of arguments and signature of type constructor:

     Typed Erlang      System Fω
     ------------      ---------
@@ -126,7 +126,7 @@ if capital -- variable.
     a = tree(integer()).
     B = {1}.

-Exeption is functions which are treated as fun types with binded body values:
+Exception is functions which are treated as fun types with binded body values:

     b = tree(integer()) -> {1}.
     join = fun(A,B) -> lists:join(A,B) end.
@@ -134,7 +134,7 @@ Exeption is functions which are treated as fun types with binded body values:
 Modules
 -------

-Modules are paramerized by type constructors, which form local programs.
+Modules are parametrized by type constructors, which form local programs.

     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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.