This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-02
Channels
- # announcements (6)
- # babashka (21)
- # beginners (38)
- # biff (2)
- # calva (14)
- # cider (5)
- # clerk (4)
- # cljdoc (2)
- # clojure (11)
- # clojure-europe (2)
- # clojure-norway (5)
- # clojure-spec (4)
- # core-typed (8)
- # data-science (5)
- # deps-new (15)
- # events (1)
- # fulcro (2)
- # graalvm (33)
- # holy-lambda (3)
- # hyperfiddle (19)
- # kaocha (1)
- # portal (5)
- # test-check (1)
- # xtdb (9)
- # yamlscript (2)
Hi, I am quite new to typedclojure, and am having difficulty with the built-in update
. When I create a simple function using update
such as follows,
(ns typedupclj.core
(:require
[malli.core :as m]
[typed.clojure :as t]))
(def Address
[:map
[:street string?]
[:city string?]
[:zip int?]])
(defn step-up-zip [address]
(update address :zip inc))
(m/=> step-up-zip
[:=> [:cat Address] Address])
(t/cns 'typedupclj.core)
I am getting this error
Caused by clojure.lang.ExceptionInfo
Type Checker: Found 1 error
{:type-error :top-level-error, :errors (#error {
:cause "Unannotated var clojure.core/update"
:data {:type-error :clojure.core.typed.errors/type-error, :env {:line 13, :column 4, :file "file:/Users/darren/Work/jam/typed-up-clj/src/typedupclj/core.clj"}, :form update}
:via
[{:type clojure.lang.ExceptionInfo
:message "Unannotated var clojure.core/update"
Should I annotate on update
or should I simply use something else?Hi, update
doesn't work yet, but I think (assoc address :zip (inc (:zip address)))
should work.
I'll take another look at update
support since the recently improved local inference might make it a little easier.
FWIW you could also write a macro to help the checker:
(defmacro update [m k f & args]
`(let [m# ~m k# ~k] (assoc m# k# (~f (get m# k#) ~@args))))
On update
support: I think an annotation like this is my goal:
update : (t/All [m k v] [m k [(t/Get m k) :-> v] :-> (t/Assoc m k v)])
I think I can use similar inference gymnastics to symbolic closures to make it work. Basically I want to fix m
and k
as early as possible, then check the 3rd arg with the t/Get
type eliminated (by substituting m
and k
). Then iterate until we learn nothing else about the type variables.