Add the haskell book

This commit is contained in:
2025-12-09 16:32:32 +01:00
parent c95abc31d6
commit 3624c712d7
67 changed files with 1576 additions and 0 deletions

8
Haskell-book/03/.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
/bower_components/
/node_modules/
/.pulp-cache/
/output/
/generated-docs/
/.psc*
/.purs*
/.psa*

View File

@@ -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"
}
}

View File

@@ -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"

View File

@@ -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."