Fork me on GitHub
#malli
<
2020-11-22
>
ikitommi15:11:42

hi all. comments on the function schema syntax? some alternatives:

;;
;; many ways to present function schemas
;; - 2 ints to int
;; - int to int
;; - no args to int
;; - no args to irrelevant
;;

;; 1: current
[:=> [:tuple int? int?] int?]
[:=> [:tuple int?] int?]
[:=> [:tuple] int?]
[:=> [:tuple]]

;; 2: shortcut
[:=> [int? int?] int?]
[:=> [int?] int?]
[:=> [] int?]
[:=> []]

;; 3: separator
[:fn int? int? :=> int?]
[:fn int? :=> int?]
[:fn :=> int?]
[:fn :=>]

rutledgepaulv03:11:29

I personally do not mind the more verbose version. I am wary of adding too many syntactic shortcuts since sometimes they begin to collide in unfortunate ways that make it more difficult to write correct tooling. But maybe you already have easy ways to quickly convert them into a normal form?

👍 6
ikitommi06:11:36

no tools to convert, totally agree that there should not be extra syntaxes in malli core.

Martín Varela07:11:09

I like the 3rd version best, seems easier to read than the other ones.

👍 3
ikitommi07:11:54

@U95NTJT4H that is basically Ghostwheel (spec) / Aave (malli) do:

(>defn bad-return-val
  [x y]
  [int? int? => string?]
  (+ x y))

ikitommi07:11:47

one more:

;; 4: via properties
[:=> {:input [:tuple int? int?]
      :outut int?}]
[:=> {:input [:tuple int?]
      :output int?}]
[:=> {:output int?}]
:=>

Martín Varela07:11:42

I haven't used those, but it does seem more readable than the alternatives (I guess this is a very subjective thing, anyway). I guess I'm also with @U5RCSJ6BB in not minding a bit more verbosity

Martín Varela07:11:58

terse is really cool, until it isn't... 🙂

☝️ 3
ikitommi07:11:38

data-specs for spec-tools for a great idea for really simple things. But as soon as one needed something non-trivial, it became a burden. Same with spec2, s/select syntax is awesome, until you need something inlined specs in it.

Martín Varela07:11:56

BTW, is the idea to provide the full power of malli for these? If I think of my use cases, the most likely ones would probably be rather complicated crap data (nested, with constraints, etc..), so it'd be cool to be able to use a registry or similar

Martín Varela07:11:53

they may become rather unreadable very fast, if inlined as such

ikitommi07:11:05

:=> is just a normal Schema, so generators, validators etc. work normally

Martín Varela07:11:22

Not entirely unrelated to this, the other day, while trying to figure out that reitit issue, I thought the problem was that reitit wasn't picking up the registry, so I ended up writing a bit of meander term rewriting code that allows you to define schemas based on other schemas (where you'd normally use a registry), and compile those to malli "primitives". So you get both the concision and explicitness, in a way.

rutledgepaulv11:11:13

Suppose another question is should a "irrelevant" return be a special case or should you just use a 'any? schema

ikitommi16:11:42

I think as Aave already provides the short variant, so the official (malli-like) syntax doesn’t have to be that terse, just formal. But the 1 is still.. ugly.