<< Back to previous view

[CTYP-310] Remove support for mixing "typed eval" and check-ns Created: 04/Feb/16  Updated: 04/Feb/16

Status: Open
Project: core.typed
Component/s: None
Affects Version/s: None
Fix Version/s: 0.3.23

Type: Task Priority: Minor
Reporter: Ambrose Bonnaire-Sergeant Assignee: Ambrose Bonnaire-Sergeant
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Pull request: 99
Commit:
Release:






[CTYP-309] Export typed vars with contracts to untyped namespaces Created: 31/Jan/16  Updated: 04/Feb/16

Status: Open
Project: core.typed
Component/s: None
Affects Version/s: None
Fix Version/s: 0.3.23

Type: Enhancement Priority: Major
Reporter: Ambrose Bonnaire-Sergeant Assignee: Ambrose Bonnaire-Sergeant
Resolution: Unresolved Votes: 0
Labels: gradual-typing


 Description   

Problem

While statically typed vars are statically checked, we can just call them from an untyped context and pass any data we please. Gradual typing says this is bad, as errors are delayed and are worse.

Solution

We take a similar approach to Typed Racket. Each typed def will actually define two vars.

The first var is has a munged name, but otherwise represents the original def exactly.

The second var has the original name, but the static type is used as a contract. It also uses the fully expanded AST from the original var.

How to compile typed {{def}}s

Here's how we compile a def in typed file.

Take the following typed function my-plus.

(ns my-typed
  {:lang :core.typed}
  (:require [clojure.core.typed :as t]))

(ann my-plus [Num Num -> Num])
(defn ^:my-meta my-plus [a b] (+ a b))

Then we emit a def that is the same as the original but with a new name.

Finally we create a new def for my-plus___typed that casts to appropriate

(ns my-typed
  {:lang :core.typed}
  (:require [clojure.core.typed :as t]))


(ann my-plus [Num Num -> Num])
(do
  (declare my-plus___typed my-plus)
  (def 
    ^{:core.typed {:contracted-var #'my-plus}} 
    my-plus___typed
    (fn [a b]
      (+ a b)))

  (def 
    ^:my-meta
    my-plus
    (t/cast [Num Num -> Num] my-plus___typed)))

  (alter-meta! 
    #'my-plus 
    (fn [m]
      (assoc-in m [:core.typed :uncontracted-var] #'my-plus___typed)))

  #'my-plus)

Potholes

  • Recursive functions
    • Which var to rewrite to in the body?
  • Keeping vars up to date
    • What happens on alter-var-root! or def
    • Is it just now part of the semantics? "Deal with it"?

Pull request: 98






Generated at Thu Feb 11 00:40:46 CST 2016 using JIRA 4.4#649-r158309.