diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-12-09 16:32:32 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-12-09 16:32:32 +0100 |
| commit | 3624c712d72d246f21d4e710cec7c11e052e0326 (patch) | |
| tree | f385cb51c72a0c5eeb2057609b75f5f8c6c4f272 /Haskell-book/03 | |
| parent | c95abc31d62e296db4f1b537e3de440dd40defd1 (diff) | |
| download | book-exercises-3624c712d72d246f21d4e710cec7c11e052e0326.tar.gz | |
Add the haskell book
Diffstat (limited to 'Haskell-book/03')
| -rw-r--r-- | Haskell-book/03/.gitignore | 8 | ||||
| -rw-r--r-- | Haskell-book/03/bower.json | 18 | ||||
| -rw-r--r-- | Haskell-book/03/src/Main.purs | 45 | ||||
| -rw-r--r-- | Haskell-book/03/test/Main.purs | 9 |
4 files changed, 80 insertions, 0 deletions
diff --git a/Haskell-book/03/.gitignore b/Haskell-book/03/.gitignore new file mode 100644 index 0000000..9623fa5 --- /dev/null +++ b/Haskell-book/03/.gitignore @@ -0,0 +1,8 @@ +/bower_components/ +/node_modules/ +/.pulp-cache/ +/output/ +/generated-docs/ +/.psc* +/.purs* +/.psa* diff --git a/Haskell-book/03/bower.json b/Haskell-book/03/bower.json new file mode 100644 index 0000000..9944a06 --- /dev/null +++ b/Haskell-book/03/bower.json @@ -0,0 +1,18 @@ +{ + "name": "03", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-prelude": "^3.1.0", + "purescript-console": "^3.0.0", + "purescript-arrays": "^4.2.1", + "purescript-strings": "^3.3.1" + }, + "devDependencies": { + "purescript-psci-support": "^3.0.0" + } +} diff --git a/Haskell-book/03/src/Main.purs b/Haskell-book/03/src/Main.purs new file mode 100644 index 0000000..d73dc74 --- /dev/null +++ b/Haskell-book/03/src/Main.purs @@ -0,0 +1,45 @@ +module Main where + +import Prelude +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (CONSOLE, log) +import Data.String (singleton, drop, take) +import Data.String.Unsafe (charAt) + +-- Given +-- "Curry is awesome" +-- Return +-- "Curry is awesome!" +a :: String -> String +a x = x <> "!" + +-- Given +-- "Curry is awesome!" +-- Return +-- "y" +b :: String -> String +b x = singleton $ charAt 4 x + +-- Given +-- "Curry is awesome!" +-- Return +-- "awesome!" +c :: String -> String +c = drop 9 + +-- If you apply your function to this value: +-- "Curry is awesome" +-- Your function should return +-- 'r' +thirdLetter :: String -> Char +thirdLetter = charAt 2 + +letterIndex :: Int -> Char +letterIndex x = charAt x "Curry is awesome!" + +rvrs :: String -> String +rvrs inp = (drop 9 inp) <> (drop 5 $ take 9 inp) <> (take 5 inp) + +main :: forall e. Eff (console :: CONSOLE | e) Unit +main = do + log $ rvrs "Curry is awesome" diff --git a/Haskell-book/03/test/Main.purs b/Haskell-book/03/test/Main.purs new file mode 100644 index 0000000..845d0f4 --- /dev/null +++ b/Haskell-book/03/test/Main.purs @@ -0,0 +1,9 @@ +module Test.Main where + +import Prelude +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (CONSOLE, log) + +main :: forall e. Eff (console :: CONSOLE | e) Unit +main = do + log "You should add some tests." |
