-
-
Save luxbock/bd54c9e519527cdf855a to your computer and use it in GitHub Desktop.
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
(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