aeternity / aesophia

Stand alone compiler for the Sophia smart contract language
https://docs.aeternity.com/aesophia
ISC License
52 stars 19 forks source link

Currying support #227

Open radrow opened 4 years ago

radrow commented 4 years ago

Sometimes curried functions are more useful than >1 arity ones, because they play very naturally with partial application. Example of syntax/usage:

function map(f : ('a) => 'b)(l : list('a)) : list('b) = switch(l)
  []   => []
  h::t => f(h)::map(f)(t)

function map_deep(f : ('a) => 'b)(l : list(list('a))) : list(list('b)) =
  map(map(f))(l)
UlfNorell commented 4 years ago

For reference, this is what you can write at the moment:

  function map(f : ('a) => 'b) : list('a) => list('b) = (l) => switch(l)
    []   => []
    h::t => f(h)::map(f)(t)

  function map_deep(f : ('a) => 'b) : list(list('a)) => list(list('b)) = (l) =>
    map(map(f))(l)

or


  function
    map : ('a => 'b) => list('a) => list('b)
    map(f) = (l) => switch(l)
      []   => []
      h::t => f(h)::map(f)(t)

  function
    map_deep : ('a => 'b) => list(list('a)) => list(list('b))
    map_deep(f) = (l) => map(map(f))(l)