Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
-- We define the functions to return an empty string if the argument is too
|
||||
-- short for the particular operation.
|
||||
|
||||
remFirst, remLast, remBoth :: String -> String
|
||||
|
||||
remFirst "" = ""
|
||||
remFirst cs = tail cs
|
||||
|
||||
remLast "" = ""
|
||||
remLast cs = init cs
|
||||
|
||||
remBoth (c:cs) = remLast cs
|
||||
remBoth _ = ""
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let s = "Some string."
|
||||
mapM_ (\f -> putStrLn . f $ s) [remFirst, remLast, remBoth]
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
word = "knights"
|
||||
|
||||
main = do
|
||||
-- You can drop the first item
|
||||
-- using `tail`
|
||||
putStrLn (tail word)
|
||||
|
||||
-- The `init` function will drop
|
||||
-- the last item
|
||||
putStrLn (init word)
|
||||
|
||||
-- We can combine these two to drop
|
||||
-- the last and the first characters
|
||||
putStrLn (middle word)
|
||||
|
||||
-- You can combine functions using `.`,
|
||||
-- which is pronounced "compose" or "of"
|
||||
middle = init . tail
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
main :: IO ()
|
||||
main = mapM_ print $ [tail, init, init . tail] <*> ["knights"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue