Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Commit

Permalink
notes on occurrence typing
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Apr 23, 2012
1 parent 3830bd6 commit db97328
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions notes/parameterised.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ nil <: Associative
; - (seq x) is really [(U Seqable nil Iterable ...) -> (U nil ISeq)]
; - Would rather [Seqable -> ISeq]
; - We could introduce a new type
; - (def-type SeqableI (A) (U nil (Seqable A) (Iterable A) ..))
; - (def-type SeqI (A) (U nil (ISeq A)))
; - seq :- [(SeqableI A) -> (SeqI A)]
; - count :- [(SeqableI A) -> (SeqI A)]
; - (def-type-alias SeqableI (A) (U (Seqable A) (Iterable A) (Array A) ...))
; - (def-type-alias SeqableOrNil (A) (U nil (SeqableI A)))
; - (def-type-alias SeqOrNil (A) (U nil (ISeq A)))
; - seq :- [(SeqableOrNil A) -> (SeqOrNil A)]
; - count :- [(SeqableOrNil A) -> (SeqOrNil A)]

(def-typed-interface Seqable (+A)
:methods
Expand Down Expand Up @@ -122,6 +123,7 @@ nil <: Associative
[(hashEq [this])])

(def-typed-interface MapEntry
)

(defprotocol ISeq (+A)
(-first [this] ...))
Expand All @@ -141,3 +143,38 @@ APersistentVector[X] extends AFn[Long -> X] implements IPersistentVector[X], Ite
; See scala's function1..function20..function?
AFn

(defn symbol? [a :- Any]
:filters
[a :- Symbol
a !:- Symbol])

(defn identity (A) [a :- A] A
:filters
[a !:- (U nil false)
a :- (U nil false)]
a)

(defn every? (A)
[f :- [A -> B]
coll :- (Seqable A)]
boolean
:filter
[coll :- (Seqable (then-filter f))
coll :- (Seqable (U (then-filter f)
(else-filter f)))]
)

(let [x (long-or-nil-seq)] ; (Seq (U Long nil))
(when (every? identity x)
; x :- (Seqable (U Long nil))
; with proposition x :- (Seqable !:- (U nil false))
; update (Seqable (U Long nil)
; (Seqable !:- (U nil false))
; => x :- (Seqable Long)
(apply + x)))

(let [x (some-seq)] ; (Seq Any)
(if (symbol? (first x))
; x :- (Seq Any)
; and (first x) :- Symbol
(str (namespace (first x)) (name (first x)))))

0 comments on commit db97328

Please sign in to comment.