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
John Reppy edited this pageSep 2, 2015 ·1 revision
signature STRING

We propose three new functions for theSTRING signature.

This page is part of proposal2015-003.


Synopsis

val rev           : string -> stringval implodeRev    : char list -> stringval concatWithMap : string -> ('a -> string) -> 'a list -> string

Description

  • rev s

returns the reverse of `s`.
  • implodeRev chrs

is equivalent to the expression `implode (List.rev chrs)`.
  • concatWithMap sep f items

returns a string that is constructed by converting the items to strings using the function `f`and then joining them using the separator string `sep`.For example, `concatWithMap "," Int.toString [1, 2, 3]` evaluates to the string`"1,2,3"`.

Discussion

We might also want to add aconcatRev operation that is equivalent to

concat o List.rev

for the same reason thatimplodeRev is useful.

I am not sure what the best order for the arguments toconcatWithMap is. I decided to putthe separator first, because I could imagine wanting to format lists of various differentelement types using the same separator.Furthermore, since it follows the order of the pattern that it replaces;i.e.,

concatWith sep (List.map f items)

On the other hand, the Basis Library convention for higher-order combinators has been to putthe function argument first.

Rationale

Therev function provides an efficient way to reverse a string, which is an occasionallyuseful operation.TheimplodeRev functions is useful for when a list of characters has been constructed,but is in the wrong order.TheconcatWithMap function captures an extremely common pattern where one must firstmap ato-string conversion over a list and the concatenate the result with a separator.Combining the map and concatenation in a single function provides convinence to theprogrammer and is amenable to a more efficient implementation.

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