Skip to content

Latest commit

 

History

History
48 lines (31 loc) · 850 Bytes

HandleyMilner.md

File metadata and controls

48 lines (31 loc) · 850 Bytes

Handle Milner

Anotation for type definition with functions

//  capitalize :: String -> String
var capitalize = function(s) {
  return toUpperCase(head(s)) + toLowerCase(tail(s));
}

capitalize("smurf");
//=> "Smurf"

With curry

  //  join :: String -> [String] -> String
  const join = curry((what, xs) =>  xs.join(what));
  
});

Another examples

  //  head :: [a] -> a
  const head = xs => xs[0];

  //  filter :: (a -> Bool) -> [a] -> [a]
  var filter = curry((f, xs) => xs.filter(f));

  //  reduce :: (b -> a -> b) -> b -> [a] -> b
  var reduce = curry((f, x, xs) => xs.reduce(f, x));

Constraints

// sort :: Ord a => [a] -> [a]

Above, where are saying that the function sort receives a parameter a that implements Ord