Git Product home page Git Product logo

typed-clojure's Introduction

This repository has moved: core.typed

Leiningen dependency (Clojars):

[typed "0.1.6"]

Typed Clojure

Gradual typing in Clojure, as a library.

[Talk] Clojure Conj 2012

Video

Documentation

See wiki.

License

Typed Clojure is released under the same license as Clojure: Eclipse Public License v 1.0.

See LICENSE.

Changelog

0.1.6

  • Ensure Result is not introduced when performing type inference on drest fn apps

  • tc-ignore is more do-like.

    Workaround for a quirk in the Clojure compiler where protocols only get generated in a top-level do.

  (identity (do (def-protocol foo (bar [this]))
              bar)) ;; <-- bar cannot be resolved
  vs.
  (do (def-protocol foo (bar [this]))
    bar)  ;; <-- bar is resolvable

(patch by Stephen Compall, issue #3)

  • Fix typo in into-array logic (patch by Stephen Compall, issue #4)
  • into-array> generalises Java types, does not need redundant type annotations. See User Documentation in wiki.
  • Improve type of clojure.core/class. (class ) is always a Class (class nil) is always a nil
  • Move documentation to wiki.

0.1.5

  • Better errors for Java methods and polymorphic function applications, borrow error messages from Typed Racket
  • Change ann-datatype, ann-protocol, ann-pprotocol syntax to be flatter (ann-protocol pname method-name method-type ...) (ann-dataype dname [field-name :- field-type ...])
  • Add defprotocol>

0.1.4

  • Support Clojure 1.4.0+
  • Better errors, print macro-expanded form from AST

0.1.3

  • Refactor typed.core into individual files
  • Add method-type
    • (method-type 'java.io.File/getName) prints the current Typed Clojure type for the getName method of File
  • Add types for some clojure.core coersion functions
  • Preliminary support for ClojureScript

0.1.2

  • Fix objects and filters being lost during polymorphic and dotted function applications
    • Add tests for (if (seq a) (first a) 0) filter example.
  • Can annotate datatypes outside current namespace
  • Improve type of seq, next, conj
  • tc-pr-env -> print-env
  • tc-pr-filters -> print-filterset
  • Alter APersistentMap
  • Check that local binding occurrences match with expected types
  • Heterogeneous maps are APersistentMap's instead of IPersistentMap's
  • Heterogeneous vectors are APersistentVector's instead of IPersistentVector's

0.1.1

  • Ensure ann-form finally checks its expression is of the expected type
  • Improve simplifying of intersections involving Java classes

Quickstart

(typed.core/ann v t) gives var v the static type t.

(typed.core/ann-form f t) ensures form f is of the static type t.

(typed.core/check-ns) type checks the current namespace.

(typed.core/cf t) type checks the form t.

Examples

(These don't completely type check yet)

Future work

  • Equality filters for occurrence typing
  • Type check multimethods
  • Rest type checking in fn definition
  • Type check defprotocol definitions
  • Unify AST with ClojureScript
  • Namespace dependency management

Contributors

Stephen Compall (S11001001)

typed-clojure's People

Contributors

frenchy64 avatar s11001001 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

typed-clojure's Issues

License?

There's no License file in the repo I can find and no mention in the README. What license is this under?

Typed array syntax cannot specify all Java array types

Currently into-array> doesn't allow you to specify a "Java type" for the array that contains other arrays, and does not recognise shorthand primitive types (eg. must use Integer/TYPE instead of int).

(Continues discussion from #3)

Assert failed: (FilterSet? %) in Eclipse/Counterclockwise

=> (require 'typed.core)
CompilerException java.lang.AssertionError: Assert failed: (FilterSet? %), compiling:(core.clj:1992:19) 
=> (pst (root-cause *e))
CompilerException java.lang.AssertionError: Assert failed: (FilterSet? %), compiling:(core.clj:1992:19)
    clojure.lang.Compiler$InvokeExpr.eval (Compiler.java:3455)
    clojure.lang.Compiler$DefExpr.eval (Compiler.java:404)
    clojure.lang.Compiler.eval (Compiler.java:6608)
    clojure.lang.Compiler.load (Compiler.java:7047)
    clojure.lang.RT.loadResourceScript (RT.java:361)
    clojure.lang.RT.loadResourceScript (RT.java:352)
    clojure.lang.RT.load (RT.java:431)
    clojure.lang.RT.load (RT.java:402)
    clojure.core/load/fn--5015 (core.clj:5504)
    clojure.core/load (core.clj:5503)
    clojure.core/load-one (core.clj:5310)
    clojure.core/load-lib/fn--4964 (core.clj:5349)
Caused by:
AssertionError Assert failed: (FilterSet? %)
    typed.core/-FS (core.clj:1970)
    clojure.lang.Compiler$InvokeExpr.eval (Compiler.java:3450)
    clojure.lang.Compiler$DefExpr.eval (Compiler.java:404)
    clojure.lang.Compiler.eval (Compiler.java:6608)
    clojure.lang.Compiler.load (Compiler.java:7047)
nil

The issue occurs in Counterclockwise in a REPL started via (Project) -> Run As -> Clojure Application. It does not occur in a repl started via lein repl, nor in a Counterclockwise REPL connected to an Nrepl server started by lein repl.

Eclipse for RCP and RAP Developers
Version: Juno Release
Build id: 20120614-1722
Counterclockwise version 0.10.3.201211151217
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

project.clj:

(defproject tctest "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.0-beta1"]
                 [typed "0.1.2"]])

Assert failed: ((hash-c? Value? (some-fn Type? Result?)) types)

(typed.core/cf {"foo" :bar})
[(HMap {"foo" (Value :bar)}) {:then tt, :else ff}]

works just fine, but

(defn foo [] "foo")
(ann foo [-> String])
(typed.core/cf {(foo) :bar})

throws:
Assert failed: ((hash-c? Value? (some-fn Type? Result?)) types)
[Thrown class java.lang.AssertionError]

Restarts:
0: [QUIT] Quit to the SLIME top level

Backtrace:
0: type_rep.clj:583 typed.core/->HeterogeneousMap
1: type_rep.clj:52 typed.core/-hmap
2: check.clj:140 typed.core/eval13845[fn]

Clojure 1.5.0-RC2
typed 0.1.6

Rationale

Not really an issue but I expected to see a Rationale for this kind of work. Mind putting one up so as to give people a perspective on the kind of problem you are trying to solve. This is also in line with the spirit of Clojure itself.

Regards
John

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.