Skip to content

Instantly share code, notes, and snippets.

@luxbock
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luxbock/bd54c9e519527cdf855a to your computer and use it in GitHub Desktop.
Save luxbock/bd54c9e519527cdf855a to your computer and use it in GitHub Desktop.
(ns rdp-214.bar
(:require [clojure.core.typed :as t
:refer [defalias cf ann U ASeq Set Num Str HVec Map]]))
(defalias Point (HVec [Long Long]))
(defalias Area (Set Point))
(t/ann-record Paper [color :- Long,
x :- Long,
y :- Long,
width :- Long,
height :- Long])
(defrecord Paper
[^long color
^long x
^long y
^long width
^long height])
;;; This works:
(ann paper->area [Paper -> Area])
(defn paper->area
[{:keys [x y width height]}]
(into #{}
(t/for [x' :- Num (range x (+ x width))
y' :- Num (range y (+ y height))]
:- (HVec [Long Long])
[(long x') (long y')])))
;;; Fails with: CompilerException java.lang.OutOfMemoryError: PermGen space
(ann paper->area [Paper -> Area])
(defn paper->area
[{:keys [x y width height]}]
(into #{}
(t/for [x' :- Num (range x (+ x width))
y' :- Num (range y (+ y height))]
:- (ASeq (HVec [Long Long])) ;; <-- Wrong type for return
[(long x') (long y')])))
;;; Also fails: CompilerException java.lang.OutOfMemoryError: PermGen space
(ann paper->area [Paper -> Area])
(defn paper->area
[{:keys [x y width height]}]
(into #{}
(t/for [x' :- Long (range x (+ x width)) ; <-- Not actually a Long
y' :- Long (range y (+ y height))]
:- (HVec [Long Long])
[x y])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment