core-typed

Typed Clojure, an optional type system for Clojure
2020-02-21T01:45:53.165Z

@zilti haha good question. depends on your perspective. xD required a good amount of insight but I'm using spec2's extensibility as intended

2020-02-21T01:48:08.166700Z

I managed to verify clojure.core/map was (All [x y] [[x -> y] (Coll x) -> (Coll y)]) by effectively calling (conform (All [x y] [[x -> y] (Coll x) -> (Coll y)]) map) but with gnarlier syntax for the spec

2020-02-21T01:49:04.167600Z

instead of generating values, we need to generate types (specs) to instantiate x and y

2020-02-21T01:50:17.168400Z

that would be a super compelling story for typed clojure if I can pull off the runtime side of things

2020-02-21T01:58:34.168800Z

2.0 branch lives here now https://github.com/typedclojure/typedclojure

2020-02-21T01:59:01.169400Z

trying to figure out how to deploy it to clojars.. having trouble

2020-02-21T02:00:13.170400Z

going back to the typed groupId and namespace. probably typed/clj with root namespace typed.clj and typed/clj.check with ns typed.clj.check

2020-02-21T02:01:30.171800Z

then library annotations will live in typed.lib/clojure typed.lib/core.async etc, with wrappers and stuff living under typed.lib.clojure.core/doseq typed.lib.clojure.core.async/go etc

2020-02-21T02:02:03.172300Z

I think that's sustainable.

zilti 2020-02-21T10:32:11.173200Z

Yea, having core.typed generate specs, mainly for the parts that can't be verified at compile time, would be one helluva feature

2020-02-21T10:45:20.174900Z

Crazy idea.. not sure, is it possible to have a cljc core.typed library? It would be usable from CLJS in the browser, nodejs and Graalvm. We could have type inference in small setting? Not sure if this is stupid to suggest, but I really would like to have it

2020-02-21T23:22:26.175700Z

@jeroenvandijk actually that's behind my obsessive partitioning of typed clojure into "jvm" "js" etc

2020-02-21T23:22:34.176Z

it's on the roadmap

2020-02-21T23:22:45.176300Z

Awesome!

2020-02-21T23:23:07.176700Z

@zilti yea it all clicks together for me

2020-02-21T23:23:21.177100Z

you could throw away the type checker and still have incredible value

2020-02-21T23:23:48.177600Z

@jeroenvandijk I really want a web demo, I've wanted one since 2013-ish haha

2020-02-21T23:23:59.177900Z

so I've slowly been going towards cljc

2020-02-21T23:24:37.178300Z

If I can help somehow with testing please let me know. It think it will be huge

zilti 2020-02-21T23:25:16.178700Z

Will core.typed 2 be syntax-compatible to 1.0 btw?

2020-02-21T23:26:18.179300Z

I have no idea. this whole spec2 thing just popped up a few days ago after about 5 years of thinking

2020-02-21T23:26:28.179600Z

this is totally brand new and I barely understand it

2020-02-21T23:26:40.179900Z

but I do know spec2 syntax is extremely verbose

2020-02-21T23:27:15.180600Z

since my goal is a one-one spec2<==>typedclojure type correspondance, I assume we can easily write a type->spec2 function

2020-02-21T23:27:25.180900Z

and I quite like typedclojure syntax

zilti 2020-02-21T23:27:49.181500Z

Yea, the conversion should be rather straightforward. I mean, I did/do it by hand for a few types in core.typed 1 currently

zilti 2020-02-21T23:28:24.182500Z

But I miss the varname :- type syntax being equivalent to t/ann

2020-02-21T23:28:41.182800Z

the research I need to do now is how to do these properly in spec2: All, TFn, type variables, t/inst

2020-02-21T23:29:32.183600Z

yea that should be easy to do. it's kinda gross to me tbh

2020-02-21T23:29:49.184Z

doesn't play well with type hints either aesthetically

zilti 2020-02-21T23:31:10.185300Z

Hmm. I mean, in the end, you can leave it to the user which variant they use. But I found it a bit confusing (maybe because I was using core.typed before) that the :- notation and the ann notation differ

2020-02-21T23:31:21.185600Z

but it definitely makes a lot of sense for scoping type variables. you don't want the names of your local type variables to be determined in another file ...

2020-02-21T23:31:52.186100Z

oh yea, that was a consequence of a series of design decisions

2020-02-21T23:32:54.187200Z

definitely a bug that they differ

2020-02-21T23:33:23.188100Z

we can have a defn wrapper that emits (do (ann ..) (c.c/defn ...)) now

zilti 2020-02-21T23:33:26.188200Z

I ended up simply placing an ann right above each defn

zilti 2020-02-21T23:33:32.188400Z

Yea

2020-02-21T23:34:08.189Z

yea I recommend that. but inline types are super popular so that's fine.

2020-02-21T23:34:56.190300Z

I think I originally wrote the :- macros back in the day and schema based its syntax on that. then everyone make spec wrappers that work that way.

zilti 2020-02-21T23:35:00.190400Z

I also noticed there are still annotations for some clojure.core functions missing in 1.0.0

2020-02-21T23:35:36.191Z

which ones did you need?

zilti 2020-02-21T23:35:59.191500Z

(t/ann clojure.core/update [Coll Any [Coll -&gt; Any] -&gt; Any])
(t/ann clojure.core/re-pattern [Str -&gt; java.util.regex.Pattern])
(t/ann clojure.core/slurp [Str -&gt; Str])
are the ones I made

2020-02-21T23:36:00.191600Z

some macros like reify aren't supported

zilti 2020-02-21T23:36:53.192800Z

Though the ann for update I made is ugly

2020-02-21T23:36:55.192900Z

ah yea. if you want to contribute the last two feel free

2020-02-21T23:37:03.193100Z

update is a whole nother thing

2020-02-21T23:37:37.193700Z

most of my phd is based on problems like how to type update

2020-02-21T23:37:46.194Z

so that's a typedclojure 2.0 thing

zilti 2020-02-21T23:39:50.195800Z

Just copy over the Haskell type def 😜

2020-02-21T23:39:51.195900Z

something like (All [m k v o z ...] [m k [(Get m k) z ... z -&gt; o] z ... z -&gt; (Assoc m k o)]) would satisfy me LOL

2020-02-21T23:40:11.196400Z

nah man, more like the typescript type

2020-02-21T23:40:13.196600Z

haha

2020-02-21T23:40:20.196900Z

pulling out all the stops

zilti 2020-02-21T23:40:38.197300Z

I have no clue about typescript ^^ (neither about Haskell, even though I've read about it a bit though)

2020-02-21T23:41:03.197800Z

typescript has all the these typelevel operators that are pretty crazy

2020-02-21T23:41:21.198200Z

like (Domain [Int -&gt; Str]) => Int

2020-02-21T23:41:36.198400Z

metaprogramming your types

2020-02-21T23:41:56.199400Z

and so many functions in clojure are designed with assoc/get/update as building blocks

2020-02-21T23:42:04.199900Z

so we really need type-level equivalents

zilti 2020-02-21T23:42:07.200Z

I don't know that much about type systems in general, just some silly facts like how Scala's is turing complete apparently

2020-02-21T23:42:36.200800Z

What if you had a tiny subset of Clojure e.g. just (str (+ 2 (inc 4)) . Would that be easy to type check?

2020-02-21T23:42:41.201100Z

I'm hyperfocussed on bidirectional checking myself

2020-02-21T23:42:56.201600Z

so (+ (str "somethin") 2) woudl fail

2020-02-21T23:43:05.201800Z

@jeroenvandijk as soon as you have if and fn you're in trouble

2020-02-21T23:43:26.202400Z

Same with for ?

2020-02-21T23:43:41.203Z

for's a beast for a different reason

2020-02-21T23:43:46.203300Z

(if you leave out :when etc

2020-02-21T23:44:01.204Z

if is interesting because updating types of locals to check branches

zilti 2020-02-21T23:44:03.204300Z

for is basically an entire logic DSL with all the clauses you can include

2020-02-21T23:44:16.204600Z

Ok but you are saying if it's just function calls that's possible?

2020-02-21T23:44:35.204900Z

fn is interesting because of higher-order functions eg., how to know the type of x in (map (fn [x] ..) ..)

2020-02-21T23:44:51.205600Z

if you just have function calls with annotations, it's easy

2020-02-21T23:45:00.206100Z

ie the functions are annotated

2020-02-21T23:45:09.206500Z

but that's why type checking clojure is so fun

zilti 2020-02-21T23:45:12.206600Z

A lot is possible. I mean, you can formally verify that a turing complete subset of the Ada language is bug-free

2020-02-21T23:46:19.207100Z

I think a web demo with the easy cases is already of tremendous value

2020-02-21T23:46:38.207400Z

I think I could use that

2020-02-21T23:47:18.208Z

hopefully within the year! 🙂

2020-02-21T23:47:26.208300Z

🎉

2020-02-21T23:48:23.209700Z

one thing I'm not sure about is what the differences need to be between typed.clj and typed.cljs

2020-02-21T23:48:35.210200Z

and typed.clj.check and typed.cljs.check

2020-02-21T23:48:37.210300Z

My desire is to create a web framework that allow novices to edit stuff via a web editor. They would only be allowed to do the simple stuff. So super useful if it had type checking

2020-02-21T23:48:52.210600Z

ah nice

zilti 2020-02-21T23:49:00.210800Z

Why does it all always have to be in a browser though

2020-02-21T23:49:21.211400Z

what alternative are you thinking about?

zilti 2020-02-21T23:49:28.211900Z

JavaFX e.g.

2020-02-21T23:49:39.212400Z

yeah for sure that would be an option too

2020-02-21T23:49:52.213100Z

but the web gives the benefit of lower requirements on the client machine

2020-02-21T23:50:00.213300Z

you just need a browser

2020-02-21T23:50:14.213700Z

cljfx ftw

zilti 2020-02-21T23:50:15.213800Z

Actually I am currently looking into creating an editor with syntax highlighting, since there is a mature rich text component with a code edit mode

zilti 2020-02-21T23:50:42.214500Z

Well, download and execute is all that's needed these days. At least on MacOS and Linux... Windows, as always, is making lifes difficult

zilti 2020-02-21T23:51:01.214900Z

AppImages are such a great thing

2020-02-21T23:51:07.215100Z

What if you want to edit on your mobile? 🙂

2020-02-21T23:51:34.215900Z

But i definitely see benefits with javafx

zilti 2020-02-21T23:51:41.216100Z

Just compile the same app for mobile... Granted, the Graal-based plugin to do that is still under heavy development, but they're on their way

zilti 2020-02-21T23:52:13.216800Z

Though I have no idea if Clojure's eval is possible in a Graal native compiled binary

2020-02-21T23:52:26.217200Z

Sci?

zilti 2020-02-21T23:52:35.217500Z

What's Sci?

2020-02-21T23:52:38.217700Z

ah 🙂

2020-02-21T23:52:48.218Z

https://github.com/borkdude/babashka

2020-02-21T23:53:09.218600Z

it has another library called sci underneath. Eval in browser, graal, node etc

2020-02-21T23:53:18.218900Z

you don't feel the difference with normal clojure

2020-02-21T23:53:25.219100Z

#babashka

2020-02-21T23:53:45.219600Z

It's a pretty cool addition to the Clojure community

2020-02-21T23:53:57.219900Z

It's the reason i'm thinking of building a web framework

2020-02-21T23:54:13.220200Z

holy crap that's cool

2020-02-21T23:55:11.221200Z

It's interpreter might also be interesting from a type checking perspective

2020-02-21T23:55:55.222Z

you can type check per form. I don't know much about type checking but as a noob I feel this makes it easier. Type checking the code while interpreting it

2020-02-21T23:56:24.222400Z

So you don't have to say everything ahead of time

zilti 2020-02-21T23:56:40.222600Z

I mean you can do that in the REPL, too

2020-02-21T23:56:51.222900Z

LOL core.async is included

zilti 2020-02-21T23:56:53.223100Z

And check form by form using cf

2020-02-21T23:57:24.223300Z

like i said i'm a noob 🙂

2020-02-21T23:57:46.223800Z

i'll leave it to the experts

2020-02-21T23:58:49.224800Z

The cool thing is that you control what functions can be executed. So you could say i don't know what the type it is, let's just try it

2020-02-21T23:59:03.225200Z

If you don't have side effects that would not be a weird strategy

2020-02-21T23:59:28.225900Z

since you can control the fn's that are evaluated you know if there are gonna be side effects

2020-02-21T23:59:31.226100Z

even looping is controlled

2020-02-21T23:59:54.226500Z

I suppose that's different than checking a form in the repl