Giter Site home page Giter Site logo

typedefs / typedefs Goto Github PK

View Code? Open in Web Editor NEW
364.0 15.0 18.0 735 KB

Programming language agnostic type construction language based on polynomials.

Home Page: http://typedefs.com/

License: GNU Affero General Public License v3.0

Idris 98.81% Nix 0.99% Makefile 0.20%
type-definitions serialization-library types f-algebras type-theory category-theory serialization marshalling

typedefs's Introduction

Typedefs

Build Status

About

Typedefs is a programming language-agnostic, algebraic data type definition language, written in Idris.

See http://typedefs.com, or play around with examples at Try Typedefs!

Build and run

Nix package descriptions, an Elba manifest and a Makefile are provided.

Nix packages

If you want to build everything, do:

nix-build

If you only want to build a specific package:

nix-build -A typedefs.nix

Makefile

Build everything:

make build-lib
sudo make install-lib
make build-rest

Build a specific package:

make build pkg=typedefs

Build documentation:

make doc-all

Run tests:

make test-all

Install:

sudo make install-all

Clean up:

make clean-all

Elba

There is a complete tutorial on how to compile and install typedefs using the elba package manager here.

In most cases it should be just as easy as:

elba install

typedefs's People

Contributors

andrevidela avatar arianvp avatar cb372 avatar clayrat avatar epost avatar fredriknordvallforsberg avatar joshmh avatar kjekac avatar marcosh avatar tg-x avatar wires 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

typedefs's Issues

Create a parse test helper so we don't have to repeat the string to be parsed

We now have:

    it "\"(var 123)\"" $
      showTDef "(var 123)"
        `shouldBe` "Just (124 ** {123})"

We want something like:

    itShouldParseAs "(var 123)" "Just (124 ** {123})"

Actually, it would be nicer still if we could just construct a term t as the rhs, instead of the current showTDef t.

Maybe, while we're at it, for clarity, we should uppercase things in the tests from maybe, list, nil, cons, etc.

Remove old parsers

  • rm old Text.Parse version in src/Parse.idr.
  • tparseTDef in TParseTDef.idr is the one we actually want; that file whould be renamed.
  • tparse currently parses to the old 'fake' non-dependently typed AST
    (tdefAst is src/TParse.idr?).

JS API should expose top-level methods

Outline

The idea is that ParserJS.idr call the various Backends instead of just the Haskell one.

  • expose Haskell backend
  • expose ReasonML backend
  • expose JSON backend
  • expose type parser
  • remove main function
  • add a String switch to select the desired backend

Older version of this issue (plz update!)

This is a probably somewhat outdated TODO:

  • expose showTDef
  • expose Backend.Haskell: generate, generateType
  • expose TermCodec (serialize and serializeMu?)

Re invocation of the Haskell backend, @clayrat writes

It's generally generate <typedef> or generateType <typedef>
depends on whether you're making type synonyms or actual new data
I'll try to add those tests later today

See #48.

Alex also mentioned idris-lang/Idris-dev#4073, which should allow us to create interfaces for Node (and, after some browserification, hopefully also for the browser).

Web UI groundwork

  • compile the typedefs compiler to Javascript
  • do so in a separate... Nix build file? or perhaps something a bit more workable
  • create an HTML page with a textarea and a compile button, and invoke the JS typedefs compiler on the textarea content
  • discuss further nicifications

JS compilation via Nix fails when including Backend.Haskell in ParserJS.idr

Idris's JS compiler doesn't seem to like

import Typedef
import Parse
import Backend.Haskell

It complains about:

[nix-shell:/app/typedefs]# idris --build typedefs-parser-js.ipkg
Entering directory `./parser.js'
Type checking ./ParserJS.idr
Uncaught error: Elaborating {__infer_0} arg {ival_0}: NoSuchVariable run__IO
FAILURE: "idris-codegen-javascript" ["./ParserJS.ibc","-o","/app/typedefs/typedefs_parser.js"]
Leaving directory `./parser.js'

Removing the import Backend.Haskell makes the error go away and compilation succeed.

Update: this was using Nix 2.1.3 on macOS (pre-Mojave)

Elba build

The Nix build is great to have, but it's also problematic in areas. Maybe we'd want to timebox creating an Elba build?

Application?

We probably want some internal notion of application if we want to be able to generate something like the following:

data List a = Nil | Cons a (List a)
data Nat = Z | S Nat
type ListNat = List Nat

One way would be to look at http://assert-false.net/arnaud/papers/A%20dissection%20of%20L.pdf, and have some degenerate form of it, e.g., where we only keep the contexts and never do actual substitution. This could also help with #61

Use prettyprint

Look at using Text.PrettyPrint.WL to generate output. Possibly relevant to defining an interface, too.

whitespace parsing issues

> typedefs-parser '(var 0)'
Just (Var 0)
> typedefs-parser '(var 0) '
Nothing
> typedefs-parser '(mu list (cons (* (var 1) (var 0))) )'
Just (Mu "list" [(Prod (Var 1) (Var 0))])
> typedefs-parser '(mu list (cons (* (var 1) (var 0)) ))'
Nothing

Specify and implement a non-sexp typedefs grammar

It would be nice to have some semi-formal definition for how everything is defined. Most of it seems pretty evident, but there could be subtleties around var and mu:

  • It has been mentioned that mu is supposed to "chop off" the first variable - does that mean the one with a minimal index?
  • Do variable indexes always start from 0? This arises when trying to parse things from strings: e.g., do the following strings encode legit ASTs?
  1. (var 3)
  2. (* (var 1) (var 0))

Document, clarify, clean up and format the main ADT and examples.

We want to capture some of the documentation and learnings in source code comments, and generally present things as clearly as possible.

  • add doc comments to main types
  • add doc comments to examples
  • make sure the order of examples makes sense
  • update makefile with an additional doc target
  • move Jelle's todo list from the bottom of Typedefs.idr into issues or something

Parse into TDef data type

Up until now, the parser has been producing trees of an intermediate AST type. Instead, it should produce the Typedefs AST type TDefs, which can de done using a sigma type of the form (n : Nat ** TDef n).

nix-build fails due to incomplete definition of unpack

macOS 10.13.4
nix 2.1.3

Output:

โžœ  typedefs git:(master) nix-build default.nix -A typedefs
these derivations will be built:
  /nix/store/chwyrvnnh59ib11crq31d0nfr6qiqmkn-idris-typedefs-dev.drv
building '/nix/store/chwyrvnnh59ib11crq31d0nfr6qiqmkn-idris-typedefs-dev.drv'...
unpacking sources
unpacking source archive /nix/store/pqwi1h8976g6l8nab0hjnklywinl24w3-typedefs
source root is typedefs
patching sources
configuring
no configure script, doing nothing
building
Entering directory `./src'
Leaving directory `./src'
running tests
Entering directory `./src'
Type checking /private/tmp/nix-build-idris-typedefs-dev.drv-0/idris27013-0.idr
.idris-wrapped_: Erasure/getArity: definition not found for with block in Prelude.Strings.unpack
CallStack (from HasCallStack):
  error, called at src/Idris/Erasure.hs:602:20 in idris-1.3.0-HQONzYd57BmLbdAngG1p5r:Idris.Erasure
builder for '/nix/store/chwyrvnnh59ib11crq31d0nfr6qiqmkn-idris-typedefs-dev.drv' failed with exit code 1
error: build of '/nix/store/chwyrvnnh59ib11crq31d0nfr6qiqmkn-idris-typedefs-dev.drv' failed

Codec for type definitions (Ty <-> Bits)

Moved into this issue from an older source code comment by @wires:

  • define binary schema
  • serialise : Ty -> Bits
  • deserialise : Bits -> Ty
  • prf Ty codec :
      forall t:Ty. (serialise . deserialise) t == t
    

Related snippet:

showTy x =
  case x of
    Ty0 => "0"
    Ty1 => "1"
    (a .+. b) => showOp "+" a b
    (a .*. b) => showOp "*" a b
  where
    parens : String -> String
    parens s = "(" ++ s ++ ")"
    showOp : String -> Ty -> Ty -> String
    showOp op x y = parens $ (showTy x) ++ " " ++ op ++ " " ++ (showTy y)

Use literate Idris

We want to turn turn the main .idr files into a literate Idris and turn it into a human readable article

Jelle sketched out some typedefs stuff here, please have a look and feel add comments

Compilation problem

Hey folks, nix-shell -A typedefs-parser-js gives me the following, any ideas where this comes from?

Type checking ./Parse.idr
Parse.idr:62:13:
   |
62 |     TMu nam $ weakenNTDefs xs (S m) (LTESucc prf)
   |             ^
When checking right hand side of weakenTDef with expected type
        TDef m

When checking an application of constructor Typedefs.TMu:
        Type mismatch between
                Vect k (Name, TDef m1) (Type of weakenNTDefs _ m _)
        and
                List (Name, TDef (S m)) (Expected type)

        Specifically:
                Type mismatch between
                        Vect k (String, TDef m1)
                and
                        List (String, TDef (S m))

Parse.idr:104:16-28:
    |
104 |        , map (\(nm, (n**td)) => (n ** TName nm td)) $
    |                ~~~~~~~~~~~~~
When checking right hand side of Parse.case block in tdef at Parse.idr:104:16-28 with expected type
        (n1 : Nat ** TDef n1)

When checking argument pf to constructor Builtins.MkDPair:
        No such variable TName

Let-bindings

We should probably introduce some aliasing/let binding syntax, so that we can define them in parts and referred back to, like in the ListNat test.

Syntax suggestions? Shall we introduce list literals (which i don't particularly like, but wth):

(let [ (name Maybe (+ 1 (var 0))
     , (mu ...)
     , ...
     ]
     (....tdef...)
)

Does this make any sense? :P I'm half-tempted to break sexp syntax where and go for a list of definitions like

foo = (+ 1 1)
bar = (...)

Actually, how should this interact with naming through TName and TMu?

Set up unit tests

  • create typedefs.ipkg
  • move sources into src dir
  • make Typedefs a proper module instead of a 'main' file
  • move tests into separate dir/file
  • Prefix test modules with Test. (should match dir and filenames)
  • move examples into an Examples.idr src (should be main module in the ipkg)
  • update Makefile test target
  • update Makefile with an additional examples or run target
  • update Nix build

Nix 2.x build problems

Problem

The project will not build under Nix 2.x and Idris 1.2.0 using the build file default.nix. (NB: this is a branch.) Like Alex points out, this problem is described under NixOS/nixpkgs#33994.

The error:

Entering directory `./src'
 Can't find import Builtins
 Can't find import Prelude
 Can't find import Data/Fin

Reproduce

  1. Run nix-shell in the project dir containing default.nix.

  2. From inside the shell, run:

    idris --build typedefs.ipkg
    

Idris 1.3.0 build using Nix 2.0

  • Fix compilation errors caused by the upgrade from 1.2.0 to 1.3.0
  • Idris 1.3.0 builder for Nix 2.x
    • Is this available from somewhere?
    • If not, discuss feasibility, effort and value of doing this ourselves
  • We probably want to do this in a dedicated build file independent of default.nix
  • tparsec dependency?

Nix build failure

When I do nix-build on a clean clone of typedefs, the build fails as follows. Any ideas?

Entering directory `./src'
Type checking ./Types.idr
 Can't find import Token
builder for '/nix/store/wh1zhx12x8cz6bdsk3v5bwdbw2zvgcvn-idris-typedefs-dev.drv' failed with exit code 1
error: build of '/nix/store/jfmdyys1cwcq7vk0nhvzxzpa85a1adxc-idris-typedefs-examples-dev.drv', '/nix/store/wh1zhx12x8cz6bdsk3v5bwdbw2zvgcvn-idris-typedefs-dev.drv' failed

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.