TypedJS icon indicating copy to clipboard operation
TypedJS copied to clipboard

Misleading Use of Currying in Type Signatures

Open Ejhfast opened this issue 12 years ago • 7 comments

Jameshfisher of reddit made a good point:

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

Ejhfast avatar Feb 11 '12 07:02 Ejhfast

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 :)

jameshfisher avatar Feb 11 '12 10:02 jameshfisher

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.

Ejhfast avatar Feb 11 '12 16:02 Ejhfast

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.

panesofglass avatar Feb 11 '12 18:02 panesofglass

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

goatslacker avatar Feb 26 '12 10:02 goatslacker

Nice!

panesofglass avatar Mar 01 '12 23:03 panesofglass

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]

DazWilkin avatar Mar 07 '12 18:03 DazWilkin

No, currying doesn't work :(

goatslacker avatar Mar 07 '12 18:03 goatslacker