Currying support #227

Open
opened 2020-02-20 23:14:00 +09:00 by zxq9 · 1 comment
zxq9 commented 2020-02-20 23:14:00 +09:00 (Migrated from gitlab.com)

Created by: radrow

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)
*Created by: radrow* Sometimes curried functions are more useful than >1 arity ones, because they play very naturally with partial application. Example of syntax/usage: ```ocaml 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) ```
zxq9 commented 2020-02-21 16:39:18 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

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)
*Created by: UlfNorell* For reference, this is what you can write at the moment: ```sophia 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 ```sophia 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)
Sign in to join this conversation.
No Milestone
No project
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/sophia#227
No description provided.