This repository has been archived by the owner on Jan 2, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d1edc56
Showing
5 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pom.xml | ||
*jar | ||
/lib/ | ||
/classes/ | ||
.lein-failures | ||
.lein-deps-sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# typed-clojure | ||
|
||
FIXME: write description | ||
|
||
## Usage | ||
|
||
FIXME: write | ||
|
||
## License | ||
|
||
Copyright (C) 2011 FIXME | ||
|
||
Distributed under the Eclipse Public License, the same as Clojure. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(defproject typed-clojure "1.0.0-SNAPSHOT" | ||
:description "FIXME: write description" | ||
:dependencies [[org.clojure/clojure "1.2.1"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
(ns typed-clojure.core) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Global type environment | ||
|
||
(defprotocol ITypeEnv | ||
(extend-env! [this name type]) | ||
(get-env [this])) | ||
|
||
(deftype TypeEnv [env] | ||
ITypeEnv | ||
(get-env [this] env) | ||
(extend-env! [this name type] | ||
(swap! env assoc name type))) | ||
|
||
(def the-env (TypeEnv. (atom {}))) | ||
|
||
(defn extend-env [name type] | ||
(extend-env! the-env name type)) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Type utilities | ||
|
||
(defn make-union [& types] | ||
(vec types)) | ||
|
||
(defmacro defnt [name & body] | ||
(extend-env name (-> (meta name) :-)) | ||
`(defn ~name ~@body)) | ||
|
||
(defn type-declaration [name type] | ||
(extend-env name type)) | ||
|
||
(defmacro make-type [name] | ||
`(do | ||
(deftype ~name []) | ||
(new ~name))) | ||
|
||
(defmacro make-type-alias [name type] | ||
`(make-type ~name)) | ||
|
||
(deftype Function [sig]) | ||
(defn make-Function [& types] | ||
(Function. types)) | ||
|
||
(deftype List [type]) | ||
(defn make-Listof [sig] | ||
(List. sig)) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Primitive types | ||
|
||
;; TODO Work out proposition representation | ||
|
||
(make-type Any) | ||
(make-type None) | ||
|
||
(type-declaration + (make-Function Number Number Number)) | ||
(type-declaration - (make-Function Number Number Number)) | ||
|
||
;(make-pred-ty symbol? Symbol) | ||
|
||
(defnt ^{:- (make-Function Number Number)} | ||
f | ||
[x] | ||
(if (number? x) | ||
(+ x) | ||
(- x))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(ns typed-clojure.test.core | ||
(:use [typed-clojure.core]) | ||
(:use [clojure.test])) | ||
|
||
(deftest replace-me ;; FIXME: write | ||
(is false "No tests have been written.")) |