Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

2015 005 Addition of Fn module

John Reppy edited this pageSep 21, 2015 ·9 revisions

Proposal 2015-005

Addition ofFn module

Author: Andreas Rossberg
Last revised: September 21, 2015
Status: proposed
Discussion:issue #6


Synopsis

signature FNstructure Fn :> FN

TheFn structure provides various combinators to aid computing with function values.

Interface

val id       : 'a -> 'aval const    : 'a -> 'b -> 'aval apply    : ('a -> 'b) * 'a -> 'bval o        : ('b -> 'c) * ('a -> 'b) -> ('a -> 'c)val curry    : ('a * 'b -> 'c) -> ('a -> 'b -> 'c)val uncurry  : ('a -> 'b -> 'c) -> ('a * 'b -> 'c)val flip     : ('a * 'b -> 'c) -> ('b * 'a -> 'c)val repeat   : int -> ('a -> 'a) -> ('a -> 'a)val equal    : ''a -> ''a -> boolval notEqual : ''a -> ''a -> bool

Description

  • id x
    returns the valuex (id is the polymorphic identity function).

  • const x y
    returns the value x.

  • apply (f, x)
    applies the functionf tox. Thus, it is equivalent tof a.

  • f o g
    is the function composition off andg. Thus,(f o g) x is equivalent tof (g x).This function is the same as the globalo operator and is also part of theGeneral structure.

  • curry f x y
    is equivalent tof (x, y);i.e.,curry f transforms the binary functionf into curried form.

  • uncurry f (x, y)
    is equivalent tof x y;i.e.,uncurry f transforms the curried functionf into a binary function.This function is the inverse ofcurry.

  • flip f (x, y)
    is equivalent tof (y, x);i.e.,flip f flips the argument order of the binary functionf.

  • repeat n f
    returns the n-fold composition off.Ifn is zero, thenrepeat n f returns the identity function.Ifn is negative, then it raises the exceptionDomain.

  • equal a b
    a curried version of the polymorphic equality function (=).

  • notEqual a b
    a curried version of the polymorphic inequality function (<>).

Discussion

Other combinators could be added. These are the ones that I have needed most in practice.

Impact

Adopting this proposal should not affect existing programs.

Rationale

The need for basic higher-order functions likeid andconst arises all the time in combination with other functionals.So far, the SML Basis has lacked any of these functions, although they are standard in the libraries of most other functional programming languages.

This module also provides a more natural home for the existingo operator, but it would alsoremain in theGeneral structure for backward compatibility.


History

  • [2015-09-21] Addedequal andnotEqual functions as proposed byMichael Norrishin thediscussion.[JHR].

  • [2015-08-21] Reworked function descriptions to follow standard style[JHR].

  • [2015-08-16] Proposed


Creative Commons License
This document is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp