<div dir="ltr">I'm having a go at converting a <a href="https://github.com/kylebgorman/swipe/blob/master/swipe.m">pitch detection algorithm</a> from MATLAB to Typed Racket, and which I'll Open Source if I can get it working, and am after a few pointers, since I'm new to TR and am finding it slow going.<div>
<br><div><div><div>Examples of the kind of code I'm writing in my fledlging attempts: </div></div></div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><font face="courier new, monospace">#lang typed/racket</font></div>
</div></div><div><div><div><font face="courier new, monospace"><br></font></div></div></div><div><div><div><font face="courier new, monospace">(define: (log2 [x : Real]) : Real</font></div></div></div><div><div><div><font face="courier new, monospace"> (define result (/ (log x) (log 2)))</font></div>
</div></div><div><div><div><font face="courier new, monospace"> (if (real? result)</font></div></div></div><div><div><div><font face="courier new, monospace"> result</font></div></div></div><div><div><div><font face="courier new, monospace"> 0.0))</font></div>
</div></div><div><div><div><font face="courier new, monospace"><br></font></div></div></div><div><div><div><font face="courier new, monospace">(define: (build-step-vector [min : Real] [step : Real] [max : Real]) :</font></div>
</div></div><div><div><div><font face="courier new, monospace"> (Vectorof Real) </font></div></div></div><div><div><div><font face="courier new, monospace"> (for/vector: : (Vectorof Real)</font></div></div></div><div><div>
<div><font face="courier new, monospace"> #:length (ceiling (inexact->exact (/ (- max min) step)))</font></div></div></div><div><div><div><font face="courier new, monospace"> ([i (in-naturals)])</font></div>
</div>
</div><div><div><div><font face="courier new, monospace"> (+ min (* i step))))</font></div></div></div></blockquote><div><font face="courier new, monospace"><br></font></div><div><div>Suggestions of better idioms and choices most welcome! E.g. the second one could be written as a range -> array, multiplied by the step.</div>
</div><div><br></div><div>Beyond that:</div><div><ul><li>Can anyone point me to examples of any code before/after converted from MATLAB (or Octave) to TR?</li><li>What's a good scalar type to work with for floating point to start with?</li>
<li>Which non-scalar type(s) should I favor: vectors, arrays or matrices?</li><li>Any general tips to develop facility for this kind of stuff? I feel like I need to go "back to basics", but there seems to be a dearth of examples and tutorials. on math/... beyond the reference materials.</li>
</ul></div><div><br></div><div>Many thanks</div><div><br></div><div>Dan</div><div><br></div><div><br></div></div></div>