This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-11
Channels
- # announcements (2)
- # asami (10)
- # aws (2)
- # babashka (28)
- # beginners (103)
- # calva (2)
- # clj-kondo (10)
- # clojure (69)
- # clojure-austin (11)
- # clojure-europe (48)
- # clojure-nl (10)
- # clojure-switzerland (1)
- # clojure-uk (2)
- # clojurescript (6)
- # conjure (2)
- # consulting (1)
- # core-async (2)
- # core-typed (2)
- # cursive (5)
- # datomic (15)
- # jobs (1)
- # malli (4)
- # meander (7)
- # membrane (26)
- # missionary (6)
- # nbb (39)
- # reagent (3)
- # releases (1)
- # ring (3)
- # shadow-cljs (28)
- # spacemacs (2)
- # sql (6)
- # vim (5)
Hi, I was trying below type annotation but kept on getting error on (t/check-ns-clj)
I am using Typed Clojure (ver. 1.0.31) and was implementing delayed evaluation for function arguments.
Code:
(require '[typed.clojure :as t])
(t/defalias Lazy
(t/TFn [[x :variance :covariant]]
(t/IFn [:-> x])))
;; => nil
(t/ann lazy-int [t/Int :-> (Lazy t/Int)])
;; => nil
(defn lazy-int
[elem]
(fn [] elem))
;; => #'some-ns/lazy-int
(t/defalias LazyList
(t/TFn [[y :variance :covariant]]
(t/U nil
(Lazy (t/HMap :mandatory
{:head (Lazy y)
:tail (LazyList y)})))))
;; => nil
(t/ann to-lazy-list [(t/SequentialColl t/Int) :-> (LazyList t/Int)])
;; => nil
(defn to-lazy-list
[xs]
#(when (seq xs)
{:head (lazy-int (first xs))
:tail (to-lazy-list (rest xs))}))
;; => #'some-ns/to-lazy-list
Error details:
Type mismatch:
Expected: (t/HMap :mandatory {:head (some-ns/Lazy t/Int), :tail (some-ns/LazyList t/Int)})
Actual: nil
in:
nil
Execution error (ExceptionInfo) at clojure.core.typed.errors/print-errors! (errors.cljc:290).
Type Checker: Found 1 error
1. t/U
with nil
in the definition of LazyList
, however debug info says otherwiset/U
)
(t/defalias LazyList
(t/TFn [[y :variance :covariant]]
(Lazy
(t/U nil
(t/HMap :mandatory
{:head (Lazy y)
:tail (LazyList y)})))))
1. Is there a better way to define LazyList
(i.e. the :tail
part contained in t/HMap
). Can t/Rec
be used in this case (I couldn't figure it out)?
Nudge in the right direction would be greatly appreciated 🙂