4 ms·
Out of interest, why are you using a record for the PID, and not a map?
by weavejester 12y ago
Out of interest, why are you using a record for the PID, and not a map?
- pi-rat 12y agoI had this grand plan of playing with core.typed, type annotate everything (ann-record Pid [set-point :- Number .....]). But the types made the examples too confusing for a blog post, so I dropped the idea. The record stayed though - but there's no reason why it couldn't simply be a map.
- weavejester 12y agoI believe you could also use the heterogeneous map (HMap) type if you wanted static typing: (defalias Pid (HMap :complete? true :mandatory {:set-point Num :k-p Num :k-i Num :k-d Num :error-sum Num :error-last Num :output-max Num :output Num})) And then use it as you might expect: (ann calculate-pid [Pid Num -> Pid]) There's no real downside to using a record, but they're really only necessary for polymorphism.
- pi-rat 12y agoThanks! I'm just getting started with core.typed, and record felt more natural as it's annotated just as you would annotate a function. I expected there to be a way to create a type a map just like that, but just haven't had the time to read up on it. So thank you for the example, will definitely play more with core.typed.