Logo

Programming-Idioms

History of Idiom 46 > diff from v11 to v12

Edit summary for version 12 by :

Version 11

2015-09-02, 13:56:27

Version 12

2015-09-02, 13:57:33

Idiom #46 Extract beginning of string (prefix)

Create string t consisting of the 5 first characters of string s.

Idiom #46 Extract beginning of string (prefix)

Create string t consisting of the 5 first characters of string s.

Code
t = take 5 s
Code
t :: String
t = take 5 s
Comments bubble
The function "take" has two arguments- the number of characters to take as a prefix, and the string to take the prefix from. The function "take" is in the Haskell prelude and doesn't need to be imported.
Comments bubble
The function "take" has two arguments- the number of characters to take as a prefix, and the string to take the prefix from. The function "take" is in the Haskell prelude and doesn't need to be imported.

The type signature is optional, and could be omitted leaving only "t = take 5 s".