Ejhfast / TypedJS

Lightweight program specifications for testing JavaScript
http://typedjs.com
223 stars 12 forks source link

Misleading Use of Currying in Type Signatures #12

Open Ejhfast opened 12 years ago

Ejhfast commented 12 years ago

Jameshfisher of reddit made a good point:

http://www.reddit.com/r/javascript/comments/pholi/typedjs_sanity_check_your_code/c3pscxo

jameshfisher commented 12 years ago

Bear in mind that the right-associative arrow does make sense where currying is actually going on. So Char -> Char -> Char would be the appropriate signature for

//+ char_first :: Char -> Char -> Char
function char_first(c1){
  return function(c2) {
    return c1;
  }
}

(I'm Jameshfisher :)

Ejhfast commented 12 years ago

Right. But knowing whether a function can be curried (like your example) requires a bit of analysis that I'm not currently doing ;-) Maybe an extra feature later on.

panesofglass commented 12 years ago

I can't remember the Haskell equivalent exactly, but I think it would be //+ char_first :: Char Char -> Char. Another option, if the delimiter is necessary, might be //+ char_first :: Char * Char -> Char, a la ML.

goatslacker commented 12 years ago

//+ add :: Number, Number -> Number currently works.

panesofglass commented 12 years ago

Nice!

DazWilkin commented 12 years ago

Love the principle of TypedJS but having some problems using it so, with apologies if I'm being a "DA"....

Does currying work? I tried a simple function:

fnCurry = function (a) { return function (b) { return true; } };

and then used

test = TypedJS.addTest("fnCurry :: Number -> Number -> Boolean", fnCurry);
TypedJS.go([test]);

but it fails 300 times with

Expected "boolean" but returned undefined on input: [62,33]

goatslacker commented 12 years ago

No, currying doesn't work :(