infernu icon indicating copy to clipboard operation
infernu copied to clipboard

Port Shake html code, as a test

Open ndmitchell opened this issue 9 years ago • 3 comments

Shake has a bunch of somewhat-functional Javascript, written by a functional programmer. It might serve as a good medium-size test case. In particular, https://github.com/ndmitchell/shake/tree/db06af5736cc031308f05aed87c21b0a5e06a295/html contains:

  • shake-util.js - a bunch of very simple utilities
  • shake-logic.js - some much more complex processing
  • shake-test.js - a test suite for those two modules
  • shake-ui.js - hooking the logic up with jQuery and Flot

I'm currently porting that to TypeScript, see https://github.com/ndmitchell/shake/tree/master/html/ts

If infernu could handle it, and had explicit and checked type signatures, I'd consider moving to it. Using a Haskell-based Javascript checker makes things like generation and management much easier.

If you aren't interested in test cases at this time, feel free to close this issue.

ndmitchell avatar Nov 05 '15 21:11 ndmitchell

This is a good test case.

I've made some changes to have it successfully pass the current version of infernu. Here's the changed version: https://gist.github.com/sinelaw/e9b394cade8642e4a9c6 This code highlights several issues in infernu:

  1. Missing support for "in" syntax (e.g. if (!(x in seen)) in the cache examples), also there's no support for hasOwnProperty which would have also worked here.
  2. Inferred row types are indeed fully general, but a major drawback of that is how exceedingly detailed and unreadable they are. For example:
/*       sum : ( { get length: Number
                 , get =[]: Rnt.(Number -> Number) | m} -> Number) */
function sum(xs) // :: Num a => [a] -> a

Infernu doesn't assume xs is an array, but that would have been so much clearer and it's anyway the only valid type you can construct in JS that has numeric indices.

  1. No support for type-casing as used in the regexp/string wrappers, though this is known and problematic to support anyway.
  2. No support for Maybe a as used in the plural function. There's a branch of infernu that has a basic implementation.

Also, other issues.

sinelaw avatar Nov 05 '15 23:11 sinelaw

Does infernu account for key stringification?

vendethiel avatar Nov 06 '15 08:11 vendethiel

When types are not otherwise restricted It can't assume bracket causes stringification, in x[k] if k can be a number and x an array. On Nov 6, 2015 10:55 AM, "ven" [email protected] wrote:

Does infernu account for key stringification?

— Reply to this email directly or view it on GitHub https://github.com/sinelaw/infernu/issues/29#issuecomment-154347881.

sinelaw avatar Nov 06 '15 09:11 sinelaw