new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
9
Task/Binary-strings/Haskell/binary-strings-1.hs
Normal file
9
Task/Binary-strings/Haskell/binary-strings-1.hs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import Text.Regex
|
||||
{- The above import is needed only for the last function.
|
||||
It is used there purely for readability and conciseness -}
|
||||
|
||||
{- Assigning a string to a 'variable'.
|
||||
We're being explicit about it just for show.
|
||||
Haskell would be able to figure out the type
|
||||
of "world" -}
|
||||
string = "world" :: String
|
||||
8
Task/Binary-strings/Haskell/binary-strings-2.hs
Normal file
8
Task/Binary-strings/Haskell/binary-strings-2.hs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{- Comparing two given strings and
|
||||
returning a boolean result using a
|
||||
simple conditional -}
|
||||
strCompare :: String -> String -> Bool
|
||||
strCompare x y =
|
||||
if x == y
|
||||
then True
|
||||
else False
|
||||
8
Task/Binary-strings/Haskell/binary-strings-3.hs
Normal file
8
Task/Binary-strings/Haskell/binary-strings-3.hs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{- As strings are equivalent to lists
|
||||
of characters in Haskell, test and
|
||||
see if the given string is an empty list -}
|
||||
strIsEmpty :: String -> Bool
|
||||
strIsEmpty x =
|
||||
if x == []
|
||||
then True
|
||||
else False
|
||||
8
Task/Binary-strings/Haskell/binary-strings-4.hs
Normal file
8
Task/Binary-strings/Haskell/binary-strings-4.hs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{- This is the most obvious way to
|
||||
append strings, using the built-in
|
||||
(++) concatenation operator
|
||||
Note the same would work to join
|
||||
any two strings (as 'variables' or
|
||||
as typed strings -}
|
||||
strAppend :: String -> String -> String
|
||||
strAppend x y = x ++ y
|
||||
4
Task/Binary-strings/Haskell/binary-strings-5.hs
Normal file
4
Task/Binary-strings/Haskell/binary-strings-5.hs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{- Take the specified number of characters
|
||||
from the given string -}
|
||||
strExtract :: Int -> String -> String
|
||||
strExtract x s = take x s
|
||||
4
Task/Binary-strings/Haskell/binary-strings-6.hs
Normal file
4
Task/Binary-strings/Haskell/binary-strings-6.hs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{- Take a certain substring, specified by
|
||||
two integers, from the given string -}
|
||||
strPull :: Int -> Int -> String -> String
|
||||
strPull x y s = take (y-x+1) (drop x s)
|
||||
5
Task/Binary-strings/Haskell/binary-strings-7.hs
Normal file
5
Task/Binary-strings/Haskell/binary-strings-7.hs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{- Much thanks to brool.com for this nice
|
||||
and elegant solution. Using an imported standard library
|
||||
(Text.Regex), replace a given substring with another -}
|
||||
strReplace :: String -> String -> String -> String
|
||||
strReplace old new orig = subRegex (mkRegex old) orig new
|
||||
Loading…
Add table
Add a link
Reference in a new issue